8000 feat: add pagination to the organizaton members table by brettkolodny · Pull Request #16870 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: add pagination to the organizaton members table #16870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: create un-paginated version of query
  • Loading branch information
brettkolodny committed Mar 12, 2025
commit cfd11f6f945c9bdba8d8ac0e3a14d726538f6faf
38 changes: 28 additions & 10 deletions site/src/api/queries/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,32 @@ export const organizationMembersKey = (id: string) => [
"members",
];

export function paginatedOrganizationMembers(
organizationName: string,
/**
* Creates a query configuration to fetch all members of an organization.
*
* Unlike the paginated version, this function sets the `limit` parameter to 0,
* which instructs the API to return all organization members in a single request
* without pagination.
*
* @param id - The unique identifier of the organization
* @returns A query configuration object for use with React Query
*
* @see paginatedOrganizationMembers - For fetching members with pagination support
*/
export const organizationMembers = (id: string) => {
return {
queryFn: () => API.getOrganizationPaginatedMembers(id, { limit: 0 }),
queryKey: organizationMembersKey(id),
};
};

export const paginatedOrganizationMembers = (
id: string,
searchParams: URLSearchParams,
): UsePaginatedQueryOptions<PaginatedMembersResponse, PaginatedMembersRequest> {
): UsePaginatedQueryOptions<
PaginatedMembersResponse,
PaginatedMembersRequest
> => {
return {
searchParams,
queryPayload: ({ limit, offset }) => {
Expand All @@ -74,14 +96,10 @@ export function paginatedOrganizationMembers(
offset: offset,
};
},
queryKey: ({ payload }) => [
...organizationMembersKey(organizationName),
payload,
],
queryFn: ({ payload }) =>
API.getOrganizationPaginatedMembers(organizationName, payload),
queryKey: ({ payload }) => [...organizationMembersKey(id), payload],
queryFn: ({ payload }) => API.getOrganizationPaginatedMembers(id, payload),
};
}
};

export const addOrganizationMember = (queryClient: QueryClient, id: string) => {
return {
Expand Down
14 changes: 7 additions & 7 deletions site/src/components/UserAutocomplete/UserAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import Autocomplete from "@mui/material/Autocomplete";
import CircularProgress from "@mui/material/CircularProgress";
import TextField from "@mui/material/TextField";
import { getErrorMessage } from "api/errors";
import { paginatedOrganizationMembers } from "api/queries/organizations";
import {
organizationMembers,
paginatedOrganizationMembers,
} from "api/queries/organizations";
import { users } from "api/queries/users";
import type { OrganizationMemberWithUserData, User } from "api/typesGenerated";
import { Avatar } from "components/Avatar/Avatar";
Expand Down Expand Up @@ -70,13 +73,10 @@ export const MemberAutocomplete: FC<MemberAutocompleteProps> = ({
}) => {
const [filter, setFilter] = useState<string>();

const searchParams = new URLSearchParams();
searchParams.append("limit", "0");

// Currently this queries all members, as there is no pagination.
Copy link
7FD0 Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 😄 so easy to miss comments like this

const membersQuery = usePaginatedQuery({
...paginatedOrganizationMembers(organizationId, searchParams),
const membersQuery = useQuery({
...organizationMembers(organizationId),
enabled: filter !== undefined,
keepPreviousData: true,
});
return (
<InnerAutocomplete<OrganizationMemberWithUserData>
Expand Down
Loading
0