-
Notifications
You must be signed in to change notification settings - Fork 894
chore(site): remove users and pagination services #9932
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
Changes from 12 commits
cda4b4f
9b3adea
9db6ec6
7fb3858
1a6fcfb
04fb5d3
44d8de6
269f67f
b4b7a77
76e94fb
50c861d
93e4e80
579cb11
5eb2321
735fde8
57bb614
23517e3
d2830ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import { QueryClient } from "@tanstack/react-query"; | ||
import * as API from "api/api"; | ||
import { UpdateUserPasswordRequest } from "api/typesGenerated"; | ||
import { UpdateUserPasswordRequest, UsersRequest } from "api/typesGenerated"; | ||
|
||
export const users = (req: UsersRequest) => { | ||
return { | ||
queryKey: ["users", req], | ||
queryFn: () => API.getUsers(req), | ||
}; | ||
}; | ||
|
||
export const updatePassword = () => { | ||
return { | ||
|
@@ -11,9 +19,12 @@ export const updatePassword = () => { | |
}; | ||
}; | ||
|
||
export const createUser = () => { | ||
export const createUser = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.createUser, | ||
onSuccess: async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On line 24, we don't have a closure like we do on line 8. Do you know why? Referencing this convo in Slack the other day. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is because one is a query and another one a mutation so when it is a mutation, you can pass the args on the call like |
||
await queryClient.invalidateQueries(["users"]); | ||
}, | ||
}; | ||
}; | ||
|
||
|
@@ -22,3 +33,49 @@ export const createFirstUser = () => { | |
mutationFn: API.createFirstUser, | ||
}; | ||
}; | ||
|
||
export const suspendUser = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.suspendUser, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries(["users"]); | ||
}, | ||
}; | ||
}; | ||
|
||
export const activateUser = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.activateUser, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries(["users"]); | ||
}, | ||
}; | ||
}; | ||
|
||
export const deleteUser = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: API.deleteUser, | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries(["users"]); | ||
}, | ||
}; | ||
}; | ||
|
||
export const updateRoles = (queryClient: QueryClient) => { | ||
return { | ||
mutationFn: ({ userId, roles }: { userId: string; roles: string[] }) => | ||
API.updateUserRoles(roles, userId), | ||
onSuccess: async () => { | ||
await queryClient.invalidateQueries(["users"]); | ||
}, | ||
}; | ||
}; | ||
|
||
export const authMethods = () => { | ||
return { | ||
// Even the endpoint being /users/authmethods we don't want to revalidate it | ||
// when users change so its better add a unique query key | ||
queryKey: ["authMethods"], | ||
queryFn: API.getAuthMethods, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,20 +353,18 @@ const PresetMenu = ({ | |
View advanced filtering | ||
</MenuItem> | ||
{learnMoreLink2 && learnMoreLabel2 && ( | ||
<> | ||
<MenuItem | ||
component="a" | ||
href={learnMoreLink2} | ||
target="_blank" | ||
sx={{ fontSize: 13, fontWeight: 500 }} | ||
onClick={() => { | ||
setIsOpen(false); | ||
}} | ||
> | ||
<OpenInNewOutlined sx={{ fontSize: "14px !important" }} /> | ||
{learnMoreLabel2} | ||
</MenuItem> | ||
</> | ||
Comment on lines
-356
to
-369
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice bit of cleanup! |
||
<MenuItem | ||
component="a" | ||
href={learnMoreLink2} | ||
target="_blank" | ||
sx={{ fontSize: 13, fontWeight: 500 }} | ||
onClick={() => { | ||
setIsOpen(false); | ||
}} | ||
> | ||
<OpenInNewOutlined sx={{ fontSize: "14px !important" }} /> | ||
{learnMoreLabel2} | ||
</MenuItem> | ||
)} | ||
</Menu> | ||
</> | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PaginationWidgetBase } from "./PaginationWidgetBase"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta: Meta<typeof PaginationWidgetBase> = { | ||
title: "components/PaginationWidgetBase", | ||
component: PaginationWidgetBase, | ||
args: { | ||
page: 1, | ||
limit: 12, | ||
count: 200, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof PaginationWidgetBase>; | ||
|
||
export const MoreThan8Pages: Story = {}; | ||
|
||
export const LessThan8Pages: Story = { | ||
args: { | ||
count: 84, | ||
}, | ||
}; | ||
|
||
export const MoreThan7PagesWithActivePageCloseToStart: Story = { | ||
args: { page: 2, limit: 12 }, | ||
}; | ||
|
||
export const MoreThan7PagesWithActivePageFarFromBoundaries: Story = { | ||
args: { page: 4, limit: 12 }, | ||
}; | ||
|
||
export const MoreThan7PagesWithActivePageCloseToEnd: Story = { | ||
args: { page: 17, limit: 12 }, | ||
}; |
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.
should we really be using
req
as a key here? notreq.id
or something?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.
Req is basically the
page
,offset
andfilter
params so in this case I think makes sense to use them together. Reference: https://tanstack.com/query/v4/docs/react/guides/query-keys#query-keys-are-hashed-deterministicallyThere 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.
Yeah, it's not always needed, but I've seen the pattern where the payload for the query is treated as the last argument of the query key. It also makes it possible for the query function to access it via the
queryKey
property on its options argument, even if you extract the query function outside the hook