From 078ab8e836d70d569d0327e3e40a9a69d97e5aa6 Mon Sep 17 00:00:00 2001 From: Viktor Rozaev Date: Mon, 25 Nov 2024 16:17:51 +0100 Subject: [PATCH] fix(Groups): expand group tree on non-empty group filter [#853] --- packages/ui/src/ui/store/selectors/groups.ts | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/ui/store/selectors/groups.ts b/packages/ui/src/ui/store/selectors/groups.ts index 24f4f1c45..7d74f7635 100644 --- a/packages/ui/src/ui/store/selectors/groups.ts +++ b/packages/ui/src/ui/store/selectors/groups.ts @@ -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 = { + ...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; }, );