• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stacklok / codegate-ui / 13903674755

17 Mar 2025 03:42PM CUT coverage: 61.874% (-4.6%) from 66.452%
13903674755

Pull #345

github

web-flow
Merge ce2550358 into 5d463ef04
Pull Request #345: feat: react-hook-form field array for provider muxes

443 of 798 branches covered (55.51%)

Branch coverage included in aggregate %.

63 of 93 new or added lines in 21 files covered. (67.74%)

50 existing lines in 4 files now uncovered.

904 of 1379 relevant lines covered (65.55%)

36.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.09
/src/features/workspace/components/form-mux-fields-array.tsx
1
import { DragEndEvent } from '@dnd-kit/core'
2
import { useCallback } from 'react'
3
import { FormMuxRuleRow } from './form-mux-rule-row'
4
import { DndSortProvider } from './form-mux-dnd-provider'
5
import { useFormMuxRulesContext } from './form-mux-context-provider'
6
import { FormMuxFieldsLabels } from './form-mux-fields-labels'
7

8
function getIndicesOnDragEnd(event: DragEndEvent): {
9
  from: number
10
  to: number
11
} | null {
NEW
12
  const { active, over } = event
×
NEW
13
  if (over == null || active.id == null || over.id == null) return null
×
14
  // If trying to drag over the last item, no-op
NEW
15
  if (
×
16
    over.data.current?.sortable.index >=
17
    over.data.current?.sortable.items.length - 1
18
  )
NEW
19
    return null
×
20

NEW
21
  return {
×
22
    from: active.data.current?.sortable.index,
23
    to: over.data.current?.sortable.index,
24
  }
25
}
26

27
export function FormMuxFieldsArray({ isDisabled }: { isDisabled: boolean }) {
28
  const { fields, move } = useFormMuxRulesContext()
34✔
29

30
  const onDragEnd = useCallback(
34✔
31
    (event: DragEndEvent) => {
NEW
32
      const { from, to } = getIndicesOnDragEnd(event) || {}
×
NEW
33
      if (typeof from === 'number' && typeof to === 'number') move(from, to)
×
34
    },
35
    [move]
36
  )
37

38
  return (
39
    <>
40
      <FormMuxFieldsLabels />
41
      <DndSortProvider
42
        isDisabled={isDisabled}
43
        items={fields}
44
        onDragEnd={onDragEnd}
45
      >
46
        <ul>
47
          {fields.map((item, index) => (
48
            <FormMuxRuleRow
49
              index={index}
50
              key={item.id}
51
              row={item}
52
              isDisabled={isDisabled}
53
            />
54
          ))}
55
        </ul>
56
      </DndSortProvider>
57
    </>
58
  )
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc