From 6d39c5336a9ba96cec4605c3502d526d0ac09d4d Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 13 Mar 2023 07:45:26 +0100 Subject: [PATCH] changed to use on select (#17564) that separates selection and expansion fixes: keycloak/keycloak-ui#4560 --- js/apps/admin-ui/src/groups/GroupsSection.tsx | 2 + .../src/groups/components/GroupTree.tsx | 54 ++++++++++++++----- .../src/groups/components/group-tree.css | 2 +- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/js/apps/admin-ui/src/groups/GroupsSection.tsx b/js/apps/admin-ui/src/groups/GroupsSection.tsx index d41f2bd233..e36dbd31b9 100644 --- a/js/apps/admin-ui/src/groups/GroupsSection.tsx +++ b/js/apps/admin-ui/src/groups/GroupsSection.tsx @@ -164,6 +164,8 @@ export default function GroupsSection() { activeKey={activeTab} onSelect={(_, key) => setActiveTab(key as number)} isBox + mountOnEnter + unmountOnExit > (); + const [groups, setGroups] = useState([]); const { subGroups, setSubGroups } = useSubGroups(); const [search, setSearch] = useState(""); const [max, setMax] = useState(20); const [first, setFirst] = useState(0); const [exact, setExact] = useState(false); + const [activeItem, setActiveItem] = useState(); const [key, setKey] = useState(0); const refresh = () => { @@ -133,19 +137,10 @@ export const GroupTree = ({ ): TreeViewDataItem => { const groups = [...parents, group]; return { - id: group.id, + id: joinPath(...groups.map((g) => g.id!)), name: ( - {canViewDetails ? ( - g.id!))}`} - onClick={() => setSubGroups(groups)} - > - {group.name} - - ) : ( - {group.name} - )} + {group.name} ), children: @@ -173,10 +168,31 @@ export const GroupTree = ({ search === "" ? null : { search } ) ), - (groups) => setData(groups.map((g) => mapGroup(g, [], refresh))), + (groups) => { + setGroups(groups); + setData(groups.map((g) => mapGroup(g, [], refresh))); + }, [key, first, max, search, exact] ); + const findGroup = ( + groups: GroupRepresentation[], + id: string, + path: GroupRepresentation[], + found: GroupRepresentation[] + ) => { + return groups.map((group) => { + if (found.length > 0) return; + + if (group.subGroups && group.subGroups.length > 0) + findGroup(group.subGroups, id, [...path, group], found); + + if (group.id === id) { + found.push(...path, group); + } + }); + }; + return data ? ( 0} + activeItems={activeItem ? [activeItem] : undefined} hasGuides + hasSelectableNodes className="keycloak_groups_treeview" + onSelect={(_, item) => { + setActiveItem(item); + if (canViewDetails) { + const id = item.id?.substring(item.id.lastIndexOf("/") + 1); + const subGroups: GroupRepresentation[] = []; + findGroup(groups, id!, [], subGroups); + setSubGroups(subGroups); + navigate(toGroups({ realm, id: item.id })); + } + }} /> )} diff --git a/js/apps/admin-ui/src/groups/components/group-tree.css b/js/apps/admin-ui/src/groups/components/group-tree.css index ed22a53e02..579da88a4d 100644 --- a/js/apps/admin-ui/src/groups/components/group-tree.css +++ b/js/apps/admin-ui/src/groups/components/group-tree.css @@ -1,4 +1,4 @@ -.keycloak_groups_treeview .pf-c-tree-view__node { +.keycloak_groups_treeview .pf-c-tree-view__node-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis;