From 32e8e756221823980dac983c6dc232ff6124425d Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 2 Mar 2023 14:21:23 +0100 Subject: [PATCH] Made groups "browsable" after a search (#4533) --- .../components/group/GroupPickerDialog.tsx | 35 +++++++++++-------- .../src/groups/components/GroupTree.tsx | 6 ++-- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/apps/admin-ui/src/components/group/GroupPickerDialog.tsx b/apps/admin-ui/src/components/group/GroupPickerDialog.tsx index fde2239f19..7b48129514 100644 --- a/apps/admin-ui/src/components/group/GroupPickerDialog.tsx +++ b/apps/admin-ui/src/components/group/GroupPickerDialog.tsx @@ -56,6 +56,7 @@ export const GroupPickerDialog = ({ const [filter, setFilter] = useState(""); const [joinedGroups, setJoinedGroups] = useState([]); const [groupId, setGroupId] = useState(); + const [isSearching, setIsSearching] = useState(false); const [max, setMax] = useState(10); const [first, setFirst] = useState(0); @@ -71,7 +72,7 @@ export const GroupPickerDialog = ({ groups = await adminClient.groups.find({ first, max: max + 1, - search: filter, + search: isSearching ? filter : "", }); } else { group = await adminClient.groups.findOne({ id: groupId }); @@ -113,7 +114,7 @@ export const GroupPickerDialog = ({ const hasSubgroups = (group: GroupRepresentation) => group.subGroups?.length !== 0; - const findSubGroup = ( + const expandGroup = ( group: GroupRepresentation, name: string ): GroupRepresentation => { @@ -122,7 +123,7 @@ export const GroupPickerDialog = ({ } if (group.subGroups) { for (const g of group.subGroups) { - const found = findSubGroup(g, name); + const found = expandGroup(g, name); return found; } } @@ -131,7 +132,7 @@ export const GroupPickerDialog = ({ return ( { setFilter(search); + setIsSearching(search !== ""); setFirst(0); setMax(10); setNavigation([]); + setGroupId(undefined); }} inputGroupPlaceholder={t("users:searchForGroups")} > @@ -219,16 +222,18 @@ export const GroupPickerDialog = ({ key={group.id} id={group.id} onClick={(e) => { - const g = filter !== "" ? findSubGroup(group, filter) : group; + const g = isSearching ? expandGroup(group, filter) : group; if (isRowDisabled(g)) return; if (type === "selectOne") { setGroupId(g.id); } else if ( hasSubgroups(group) && - filter === "" && (e.target as HTMLInputElement).type !== "checkbox" ) { - setGroupId(group.id); + setGroupId( + isSearching ? expandGroup(group, filter).id : group.id + ); + setIsSearching(false); } }} > @@ -255,7 +260,7 @@ export const GroupPickerDialog = ({ } else { newSelectedRows = [ ...selectedRows, - filter === "" ? group : findSubGroup(group, filter), + isSearching ? expandGroup(group, filter) : group, ]; } @@ -271,13 +276,13 @@ export const GroupPickerDialog = ({ key={`name-${group.id}`} className="keycloak-groups-group-path" > - {filter === "" ? ( - {group.name} - ) : ( + {isSearching ? ( + ) : ( + {group.name} )} , ]} @@ -288,7 +293,7 @@ export const GroupPickerDialog = ({ aria-label={t("groupName")} isPlainButtonAction > - {((hasSubgroups(group) && filter === "" && canBrowse) || + {((hasSubgroups(group) && canBrowse) || type === "selectOne") && (