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 27, 2024
1 parent 63d60fa commit 54914c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/ui/store/actions/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function toggleGroupExpand(groupName: string) {
const expanded = {...getGroupsExpanded(getState())};
const current = expanded[groupName];
if (current) {
delete expanded[groupName];
expanded[groupName] = false;
} else {
expanded[groupName] = true;
}
Expand Down
33 changes: 28 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,38 @@ const getGroupsTreeFiltered = createSelector(
);

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

const res = cloneDeep_(groupsTreeFiltered);

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

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

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

hammer.treeList.treeForEach(res.children, (node: GroupsTreeNode) => {
const userInteractedWithNode = typeof expandedByUser[node.name] !== 'undefined'

const expanded = userInteractedWithNode ? expandedByUser : expandedBySearch;

if (!expanded[node.name]) {
node.expanded = false;
node.children = [];
} else {
node.expanded = true;
}
});

return res;
},
);
Expand Down

0 comments on commit 54914c0

Please sign in to comment.