Made tree view paging based on count query (#19758)

This commit is contained in:
Erik Jan de Wit 2023-04-26 14:21:43 +02:00 committed by GitHub
parent 04ac3a64ee
commit b22801c8dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,6 +126,7 @@ export const GroupTree = ({
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [max, setMax] = useState(20); const [max, setMax] = useState(20);
const [first, setFirst] = useState(0); const [first, setFirst] = useState(0);
const [count, setCount] = useState(0);
const [exact, setExact] = useState(false); const [exact, setExact] = useState(false);
const [activeItem, setActiveItem] = useState<TreeViewDataItem>(); const [activeItem, setActiveItem] = useState<TreeViewDataItem>();
@ -160,8 +161,8 @@ export const GroupTree = ({
}; };
useFetch( useFetch(
() => async () => {
fetchAdminUI<GroupRepresentation[]>( const groups = await fetchAdminUI<GroupRepresentation[]>(
adminClient, adminClient,
"ui-ext/groups", "ui-ext/groups",
Object.assign( Object.assign(
@ -172,10 +173,15 @@ export const GroupTree = ({
}, },
search === "" ? null : { search } search === "" ? null : { search }
) )
), );
(groups) => { const count = (await adminClient.groups.count({ search, top: true }))
.count;
return { groups, count };
},
({ groups, count }) => {
setGroups(groups); setGroups(groups);
setData(groups.map((g) => mapGroup(g, [], refresh))); setData(groups.map((g) => mapGroup(g, [], refresh)));
setCount(count);
}, },
[key, first, max, search, exact] [key, first, max, search, exact]
); );
@ -200,7 +206,7 @@ export const GroupTree = ({
return data ? ( return data ? (
<PaginatingTableToolbar <PaginatingTableToolbar
count={data.length || 0} count={count - first}
first={first} first={first}
max={max} max={max}
onNextClick={setFirst} onNextClick={setFirst}
@ -229,7 +235,7 @@ export const GroupTree = ({
> >
{data.length > 0 && ( {data.length > 0 && (
<TreeView <TreeView
data={data} data={data.slice(0, max)}
allExpanded={search.length > 0} allExpanded={search.length > 0}
activeItems={activeItem ? [activeItem] : undefined} activeItems={activeItem ? [activeItem] : undefined}
hasGuides hasGuides