-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add CheckboxTree component #1495
base: develop
Are you sure you want to change the base?
Conversation
7bacfa3
to
f23a4c0
Compare
ui/src/components/CheckboxTree/stories/CheckboxTree.stories.tsx
Outdated
Show resolved
Hide resolved
…unk/addonfactory-ucc-generator into feat/checkbox-tree-component
…unk/addonfactory-ucc-generator into feat/checkbox-tree-component
Signed-off-by: Viktor Tsvetkov <[email protected]>
Signed-off-by: Viktor Tsvetkov <[email protected]>
Signed-off-by: Viktor Tsvetkov <[email protected]>
Signed-off-by: Viktor Tsvetkov <[email protected]>
Signed-off-by: Viktor Tsvetkov <[email protected]>
Signed-off-by: Viktor Tsvetkov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still reviewing but will post just after adding, feel free to close if something seems like a bad/worse idea
// Verify rows | ||
expect(screen.getByLabelText('Row without group')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Row under Group 1')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('first row under group 3')).toBeInTheDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you create similar test when group is collapsed by default?
export function getFlattenRowsWithGroups({ groups, rows }: CheckboxTreeProps['controlOptions']) { | ||
const flattenRowsMixedWithGroups: Array<GroupWithRows | Row> = []; | ||
|
||
rows.forEach((row) => { | ||
const groupForThisRow = groups?.find((group) => group.fields.includes(row.field)); | ||
if (groupForThisRow) { | ||
const addedGroup = flattenRowsMixedWithGroups.find( | ||
(item): item is GroupWithRows => | ||
isGroupWithRows(item) && item.label === groupForThisRow.label | ||
); | ||
const groupToAdd = addedGroup || { | ||
...groupForThisRow, | ||
rows: [], | ||
}; | ||
groupToAdd.rows.push(row); | ||
if (!addedGroup) { | ||
flattenRowsMixedWithGroups.push(groupToAdd); | ||
} | ||
return; | ||
} | ||
flattenRowsMixedWithGroups.push(row); | ||
}); | ||
|
||
return flattenRowsMixedWithGroups; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fort this one i needed some more time while reading it wdyt about refactoring it into sth like this
export function getFlattenRowsWithGroups({ groups, rows }: CheckboxTreeProps['controlOptions']) { | |
const flattenRowsMixedWithGroups: Array<GroupWithRows | Row> = []; | |
rows.forEach((row) => { | |
const groupForThisRow = groups?.find((group) => group.fields.includes(row.field)); | |
if (groupForThisRow) { | |
const addedGroup = flattenRowsMixedWithGroups.find( | |
(item): item is GroupWithRows => | |
isGroupWithRows(item) && item.label === groupForThisRow.label | |
); | |
const groupToAdd = addedGroup || { | |
...groupForThisRow, | |
rows: [], | |
}; | |
groupToAdd.rows.push(row); | |
if (!addedGroup) { | |
flattenRowsMixedWithGroups.push(groupToAdd); | |
} | |
return; | |
} | |
flattenRowsMixedWithGroups.push(row); | |
}); | |
return flattenRowsMixedWithGroups; | |
} | |
export function getFlattenRowsWithGroups({ groups, rows }: CheckboxTreeProps['controlOptions']) { | |
const flattenRowsMixedWithGroups: Array<GroupWithRows | Row> = []; | |
rows.forEach((row) => { | |
const groupForThisRow = groups?.find((group) => group.fields.includes(row.field)); | |
if (!groupForThisRow) { | |
// no group needed for this row | |
flattenRowsMixedWithGroups.push(row); | |
return; | |
} | |
const existingGroup = flattenRowsMixedWithGroups.find( | |
(item): item is GroupWithRows => | |
isGroupWithRows(item) && item.label === groupForThisRow.label | |
); | |
if (!existingGroup) { | |
// add new group | |
flattenRowsMixedWithGroups.push({ | |
...groupForThisRow, | |
rows: [row], | |
}); | |
return; | |
} | |
// add to existing group | |
existingGroup.rows.push(row); | |
}); | |
return flattenRowsMixedWithGroups; | |
} |
or even something like this
export function getFlattenRowsWithGroups({ groups, rows }: CheckboxTreeProps['controlOptions']) { | |
const flattenRowsMixedWithGroups: Array<GroupWithRows | Row> = []; | |
rows.forEach((row) => { | |
const groupForThisRow = groups?.find((group) => group.fields.includes(row.field)); | |
if (groupForThisRow) { | |
const addedGroup = flattenRowsMixedWithGroups.find( | |
(item): item is GroupWithRows => | |
isGroupWithRows(item) && item.label === groupForThisRow.label | |
); | |
const groupToAdd = addedGroup || { | |
...groupForThisRow, | |
rows: [], | |
}; | |
groupToAdd.rows.push(row); | |
if (!addedGroup) { | |
flattenRowsMixedWithGroups.push(groupToAdd); | |
} | |
return; | |
} | |
flattenRowsMixedWithGroups.push(row); | |
}); | |
return flattenRowsMixedWithGroups; | |
} | |
export function getFlattenRowsWithGroups({ groups, rows }: CheckboxTreeProps['controlOptions']) { | |
return rows.reduce<Array<GroupWithRows | Row>>((flattenRowsMixedWithGroups, row) => { | |
const groupForThisRow = groups?.find((group) => group.fields.includes(row.field)); | |
if (!groupForThisRow) { | |
// no group needed for this row | |
return [...flattenRowsMixedWithGroups, row]; | |
} | |
const existingGroup = flattenRowsMixedWithGroups.find( | |
(item): item is GroupWithRows => | |
isGroupWithRows(item) && item.label === groupForThisRow.label | |
); | |
if (!existingGroup) { | |
// add new group | |
return [ | |
...flattenRowsMixedWithGroups, | |
{ | |
...groupForThisRow, | |
rows: [row], | |
}, | |
]; | |
} | |
// add to existing group | |
existingGroup.rows.push(row); | |
return flattenRowsMixedWithGroups; | |
}, []); | |
} | |
Signed-off-by: Viktor Tsvetkov <[email protected]>
Issue number: ADDON-76198
PR Type
What kind of change does this PR introduce?
Summary
Changes
A new component
CheckboxTree
has been introduced to define hierarchical checkbox structures with support of search functionality.User experience
User can use the new component for handling the list of checkboxes with better UI including the expanding/collapsing, grouping and searching within the checkbox list.
Checklist
If an item doesn't apply to your changes, leave it unchecked.