Skip to content
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

Open
wants to merge 58 commits into
base: develop
Choose a base branch
from

Conversation

rohanm-crest
Copy link
Contributor

@rohanm-crest rohanm-crest commented Nov 29, 2024

Issue number: ADDON-76198

PR Type

What kind of change does this PR introduce?

  • Feature
  • Bug Fix
  • Refactoring (no functional or API changes)
  • Documentation Update
  • Maintenance (dependency updates, CI, etc.)

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.

Screenshot 2024-12-13 at 3 39 25 PM

Checklist

If an item doesn't apply to your changes, leave it unchecked.

@rohanm-crest rohanm-crest changed the title feat: introduce the new CheckboxTree component feat: introduce the new checkboxtree component Nov 29, 2024
@rohanm-crest rohanm-crest force-pushed the feat/checkbox-tree-component branch from 7bacfa3 to f23a4c0 Compare December 4, 2024 06:20
@rohanm-crest rohanm-crest self-assigned this Dec 6, 2024
@rohanm-crest rohanm-crest marked this pull request as ready for review December 9, 2024 06:21
@rohanm-crest rohanm-crest requested review from a team as code owners December 9, 2024 06:21
Copy link
Contributor

@soleksy-splunk soleksy-splunk left a 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();
Copy link
Contributor

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?

Comment on lines +7 to +31
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;
}
Copy link
Contributor

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

Suggested change
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

Suggested change
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants