feat: implement standard pagination for org member list (#19802)

* feat: implement standard pagination for org member list

* fix type error

* i18n for pagination

* add paginationMode

* apply the change to PlatformManagedUsersTable

* replace useInfiniteQuery with useQuery

* fix type error

* fix type error

* fix type error

* fix type error

* update comment

* remove optimistic update

* minor changes

* update usage on nuqs

---------

Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
Eunjae LeeandBenny Joo authored and GitHub committed 2025-03-11 09:55:41 +01:00
1 parent 861e3aa24f
commit 7eee2728a2
24 files changed
+403 -388

No files matched your search

@@ -286,7 +286,7 @@ function MemberListContent(props: Props) {
isOrg: checkIsOrg(props.team),
});
const totalDBRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
const totalRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
const memorisedColumns = useMemo(() => {
const cols: ColumnDef<User>[] = [
@@ -618,7 +618,7 @@ function MemberListContent(props: Props) {
];
return cols;
}, [props.isOrgAdminOrOwner, dispatch, totalDBRowCount, session?.user.id]);
}, [props.isOrgAdminOrOwner, dispatch, totalRowCount, session?.user.id]);
//we must flatten the array of arrays from the useInfiniteQuery hook
const flatData = useMemo(() => data?.pages?.flatMap((page) => page.members) ?? [], [data]) as User[];
@@ -126,7 +126,7 @@ function UsersTableBare() {
//we must flatten the array of arrays from the useInfiniteQuery hook
const flatData = useMemo(() => data?.pages?.flatMap((page) => page.rows) ?? [], [data]);
const totalDBRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
const totalRowCount = data?.pages?.[0]?.meta?.totalRowCount ?? 0;
const totalFetched = flatData.length;
//called on scroll and possibly on mount to fetch more data as the user scrolls and reaches bottom of table
@@ -135,12 +135,12 @@ function UsersTableBare() {
if (containerRefElement) {
const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
//once the user has scrolled within 300px of the bottom of the table, fetch more data if there is any
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && totalFetched < totalDBRowCount) {
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching && totalFetched < totalRowCount) {
fetchNextPage();
}
}
},
[fetchNextPage, isFetching, totalFetched, totalDBRowCount]
[fetchNextPage, isFetching, totalFetched, totalRowCount]
);
useEffect(() => {