From b22801c8dd8d1521143b1011d98e840dd1e10298 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 26 Apr 2023 14:21:43 +0200 Subject: [PATCH] Made tree view paging based on count query (#19758) --- .../src/groups/components/GroupTree.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/js/apps/admin-ui/src/groups/components/GroupTree.tsx b/js/apps/admin-ui/src/groups/components/GroupTree.tsx index 8a11b240cd..7b1ce342bb 100644 --- a/js/apps/admin-ui/src/groups/components/GroupTree.tsx +++ b/js/apps/admin-ui/src/groups/components/GroupTree.tsx @@ -126,6 +126,7 @@ export const GroupTree = ({ const [search, setSearch] = useState(""); const [max, setMax] = useState(20); const [first, setFirst] = useState(0); + const [count, setCount] = useState(0); const [exact, setExact] = useState(false); const [activeItem, setActiveItem] = useState(); @@ -160,8 +161,8 @@ export const GroupTree = ({ }; useFetch( - () => - fetchAdminUI( + async () => { + const groups = await fetchAdminUI( adminClient, "ui-ext/groups", Object.assign( @@ -172,10 +173,15 @@ export const GroupTree = ({ }, search === "" ? null : { search } ) - ), - (groups) => { + ); + const count = (await adminClient.groups.count({ search, top: true })) + .count; + return { groups, count }; + }, + ({ groups, count }) => { setGroups(groups); setData(groups.map((g) => mapGroup(g, [], refresh))); + setCount(count); }, [key, first, max, search, exact] ); @@ -200,7 +206,7 @@ export const GroupTree = ({ return data ? ( {data.length > 0 && ( 0} activeItems={activeItem ? [activeItem] : undefined} hasGuides