Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(site): use react-query to fetch roles#9630

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 3 commits intomainfrombq/chore-refactor-roles
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
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
4 changes: 1 addition & 3 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -719,9 +719,7 @@ export const updateUserPassword = async (
): Promise<undefined> =>
axios.put(`/api/v2/users/${userId}/password`, updatePassword);

export const getSiteRoles = async (): Promise<
Array<TypesGen.AssignableRoles>
> => {
export const getRoles = async (): Promise<Array<TypesGen.AssignableRoles>> => {
const response = await axios.get<Array<TypesGen.AssignableRoles>>(
`/api/v2/users/roles`,
);
Expand Down
8 changes: 8 additions & 0 deletionssite/src/api/queries/roles.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
import * as API from "api/api";

export const roles = () => {
return {
queryKey: ["roles"],
queryFn: API.getRoles,
};
};
13 changes: 4 additions & 9 deletionssite/src/pages/UsersPage/UsersPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@ import { usePermissions } from "hooks/usePermissions";
import { FC, ReactNode, useEffect } from "react";
import { Helmet } from "react-helmet-async";
import { useSearchParams, useNavigate } from "react-router-dom";
import { siteRolesMachine } from "xServices/roles/siteRolesXService";
import { usersMachine } from "xServices/users/usersXService";
import { ConfirmDialog } from "../../components/Dialogs/ConfirmDialog/ConfirmDialog";
import { ResetPasswordDialog } from "./ResetPasswordDialog";
Expand All@@ -22,6 +21,7 @@ import { useDashboard } from "components/Dashboard/DashboardProvider";
import { deploymentConfigMachine } from "xServices/deploymentConfig/deploymentConfigMachine";
import { useQuery } from "@tanstack/react-query";
import { getAuthMethods } from "api/api";
import { roles } from "api/queries/roles";

export const Language = {
suspendDialogTitle: "Suspend user",
Expand DownExpand Up@@ -64,12 +64,7 @@ export const UsersPage: FC<{ children?: ReactNode }> = () => {
} = usersState.context;

const { updateUsers: canEditUsers, viewDeploymentValues } = usePermissions();
const [rolesState] = useMachine(siteRolesMachine, {
context: {
hasPermission: canEditUsers,
},
});
const { roles } = rolesState.context;
const rolesQuery = useQuery({ ...roles(), enabled: canEditUsers });

// Ideally this only runs if 'canViewDeployment' is true.
// TODO: Prevent api call if the user does not have the perms.
Expand DownExpand Up@@ -109,7 +104,7 @@ export const UsersPage: FC<{ children?: ReactNode }> = () => {
// - the user can edit the users but the roles are loading
const isLoading =
usersState.matches("gettingUsers") ||
(canEditUsers && rolesState.matches("gettingRoles")) ||
rolesQuery.isLoading ||
authMethods.isLoading;

return (
Expand All@@ -119,7 +114,7 @@ export const UsersPage: FC<{ children?: ReactNode }> = () => {
</Helmet>
<UsersPageView
oidcRoleSyncEnabled={oidcRoleSyncEnabled}
roles={roles}
roles={rolesQuery.data}
users={users}
authMethods={authMethods.data}
count={count}
Expand Down
79 changes: 0 additions & 79 deletionssite/src/xServices/roles/siteRolesXService.ts
View file
Open in desktop

This file was deleted.


[8]ページ先頭

©2009-2025 Movatter.jp