-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support infinite query when listing org users and invites (#6128)
* infinite query org users * infinite query org invites * tweak * fetch next page in org users table * fetch next page for users and invites infinite query * tweak scroll container height * lint * more table height fix * use width precent * fix transient bug * remove table min h, table wrapper totalsize h
- Loading branch information
1 parent
988df4f
commit 6bc56be
Showing
4 changed files
with
394 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
web-admin/src/features/organizations/users/create-infinite-query-org-invites.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
adminServiceListOrganizationInvites, | ||
getAdminServiceListOrganizationInvitesQueryKey, | ||
type AdminServiceListOrganizationInvitesParams, | ||
type RpcStatus, | ||
} from "@rilldata/web-admin/client"; | ||
import { | ||
createInfiniteQuery, | ||
type CreateInfiniteQueryOptions, | ||
type CreateInfiniteQueryResult, | ||
type QueryFunction, | ||
type QueryKey, | ||
} from "@tanstack/svelte-query"; | ||
|
||
export const createAdminServiceListOrganizationInvitesInfiniteQuery = < | ||
TData = Awaited<ReturnType<typeof adminServiceListOrganizationInvites>>, | ||
TError = RpcStatus, | ||
>( | ||
organization: string, | ||
params?: AdminServiceListOrganizationInvitesParams, | ||
options?: { | ||
query?: CreateInfiniteQueryOptions< | ||
Awaited<ReturnType<typeof adminServiceListOrganizationInvites>>, | ||
TError, | ||
TData | ||
>; | ||
}, | ||
): CreateInfiniteQueryResult<TData, TError> & { queryKey: QueryKey } => { | ||
const { query: queryOptions } = options ?? {}; | ||
|
||
const queryKey = | ||
queryOptions?.queryKey ?? | ||
getAdminServiceListOrganizationInvitesQueryKey(organization, params); | ||
|
||
const queryFn: QueryFunction< | ||
Awaited<ReturnType<typeof adminServiceListOrganizationInvites>> | ||
> = ({ pageParam, signal }) => | ||
adminServiceListOrganizationInvites( | ||
organization, | ||
{ ...params, pageToken: pageParam }, | ||
signal, | ||
); | ||
|
||
const query = createInfiniteQuery< | ||
Awaited<ReturnType<typeof adminServiceListOrganizationInvites>>, | ||
TError, | ||
TData | ||
>({ | ||
queryKey, | ||
queryFn, | ||
getNextPageParam: (lastPage) => { | ||
if (!lastPage.nextPageToken || lastPage.nextPageToken === "") { | ||
return undefined; | ||
} | ||
return lastPage.nextPageToken; | ||
}, | ||
enabled: !!organization, | ||
...queryOptions, | ||
}) as CreateInfiniteQueryResult<TData, TError> & { queryKey: QueryKey }; | ||
|
||
query.queryKey = queryKey; | ||
|
||
return query; | ||
}; |
64 changes: 64 additions & 0 deletions
64
web-admin/src/features/organizations/users/create-infinite-query-org-users.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
adminServiceListOrganizationMemberUsers, | ||
getAdminServiceListOrganizationMemberUsersQueryKey, | ||
type AdminServiceListOrganizationMemberUsersParams, | ||
type RpcStatus, | ||
} from "@rilldata/web-admin/client"; | ||
import { | ||
createInfiniteQuery, | ||
type CreateInfiniteQueryOptions, | ||
type CreateInfiniteQueryResult, | ||
type QueryFunction, | ||
type QueryKey, | ||
} from "@tanstack/svelte-query"; | ||
|
||
export const createAdminServiceListOrganizationMemberUsersInfiniteQuery = < | ||
TData = Awaited<ReturnType<typeof adminServiceListOrganizationMemberUsers>>, | ||
TError = RpcStatus, | ||
>( | ||
organization: string, | ||
params?: AdminServiceListOrganizationMemberUsersParams, | ||
options?: { | ||
query?: CreateInfiniteQueryOptions< | ||
Awaited<ReturnType<typeof adminServiceListOrganizationMemberUsers>>, | ||
TError, | ||
TData | ||
>; | ||
}, | ||
): CreateInfiniteQueryResult<TData, TError> & { queryKey: QueryKey } => { | ||
const { query: queryOptions } = options ?? {}; | ||
|
||
const queryKey = | ||
queryOptions?.queryKey ?? | ||
getAdminServiceListOrganizationMemberUsersQueryKey(organization, params); | ||
|
||
const queryFn: QueryFunction< | ||
Awaited<ReturnType<typeof adminServiceListOrganizationMemberUsers>> | ||
> = ({ pageParam, signal }) => | ||
adminServiceListOrganizationMemberUsers( | ||
organization, | ||
{ ...params, pageToken: pageParam }, | ||
signal, | ||
); | ||
|
||
const query = createInfiniteQuery< | ||
Awaited<ReturnType<typeof adminServiceListOrganizationMemberUsers>>, | ||
TError, | ||
TData | ||
>({ | ||
queryKey, | ||
queryFn, | ||
getNextPageParam: (lastPage) => { | ||
if (!lastPage.nextPageToken || lastPage.nextPageToken === "") { | ||
return undefined; | ||
} | ||
return lastPage.nextPageToken; | ||
}, | ||
enabled: !!organization, | ||
...queryOptions, | ||
}) as CreateInfiniteQueryResult<TData, TError> & { queryKey: QueryKey }; | ||
|
||
query.queryKey = queryKey; | ||
|
||
return query; | ||
}; |
Oops, something went wrong.
6bc56be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://ui.rilldata.in as production
🚀 Deployed on https://673fc19e8f733cb532e4c932--rill-ui-dev.netlify.app