Skip to content

Commit

Permalink
fix: Wrong refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Aug 24, 2023
1 parent a92b3ca commit 9fe8347
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ui/src/checklist.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ describe('Checklist.tsx', () => {
const { getByText, rerender } = render(<XChecklist model={{ ...checklistProps, values: ['Choice1'] }} />)
expect(wave.args[name]).toMatchObject(['Choice1'])

rerender(<XChecklist model={{ ...checklistProps, choices: [...choices] }} />)
rerender(<XChecklist model={{ ...checklistProps }} />)
expect(wave.args[name]).toMatchObject([])

fireEvent.click(getByText('Choice2').parentElement!)
expect(wave.args[name]).toMatchObject(['Choice2'])

rerender(<XChecklist model={{ ...checklistProps, choices: [...choices] }} />)
rerender(<XChecklist model={{ ...checklistProps }} />)
expect(wave.args[name]).toMatchObject([])
})

Expand Down
6 changes: 5 additions & 1 deletion ui/src/checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ export const
const _choices = choices.map(({ c, selected }) => ({ c, selected: c.disabled ? selected : value }))
setChoices(_choices)
capture(_choices)
m.values = value ? _choices.map(({ c }) => c.name) : []
},
selectAll = () => select(true),
deselectAll = () => select(false),
onChange = (idx: U) => (_e?: React.FormEvent<HTMLElement>, checked = false) => {
const _choices = [...choices]
_choices[idx].selected = checked
const choice = _choices[idx]
choice.selected = checked
setChoices(_choices)
checked ? defaultSelection.add(choice.c.name) : defaultSelection.delete(choice.c.name)
m.values = [...defaultSelection]
capture(_choices)
},
items = choices.map(({ c, selected }, i) => (
Expand Down

0 comments on commit 9fe8347

Please sign in to comment.