Skip to content

Commit

Permalink
fix(Groups): expand group tree on non-empty group filter [#853]
Browse files Browse the repository at this point in the history
  • Loading branch information
vrozaev committed Nov 26, 2024
1 parent 63d60fa commit 078ab8e
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions packages/ui/src/ui/store/selectors/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,33 @@ const getGroupsTreeFiltered = createSelector(
);

const getGroupsTreeFilteredAndExpanded = createSelector(
[getGroupsTreeFiltered, getGroupsExpanded],
(root, expanded) => {
const res = cloneDeep_(root);
[getGroupsTree, getGroupsTreeFiltered, getGroupsExpanded, getGroupsNameFilter],
(groupTree, groupsTreeFiltered, expandedByUser, groupNameFilter) => {
const expanded: Record<string, boolean> = {
...expandedByUser,
};

const res = cloneDeep_(groupsTreeFiltered);

hammer.treeList.treeForEach(res.children, (node: GroupsTreeNode) => {
const isNodeMatchedFilter = groupNameFilter && node.name.includes(groupNameFilter);

if (isNodeMatchedFilter) {
let parentName = node.parent!;

while (groupTree[parentName]) {
expanded[parentName] = true;
parentName = groupTree[parentName].parent;
}
}
});

hammer.treeList.treeForEach(res.children, (node: GroupsTreeNode) => {
const {name} = node;
if (!expanded[name]) {
if (!expanded[node.name]) {
node.children = [];
}
});

return res;
},
);
Expand Down

0 comments on commit 078ab8e

Please sign in to comment.