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

Commit3b088a5

Browse files
chore(site): refactor deployment values service to react-query (#9669)
1 parent225cf8a commit3b088a5

File tree

10 files changed

+39
-126
lines changed

10 files changed

+39
-126
lines changed

‎site/src/api/api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ export type DeploymentConfig = {
10061006
readonlyoptions:DeploymentOption[];
10071007
};
10081008

1009-
exportconstgetDeploymentValues=async():Promise<DeploymentConfig>=>{
1009+
exportconstgetDeploymentConfig=async():Promise<DeploymentConfig>=>{
10101010
constresponse=awaitaxios.get(`/api/v2/deployment/config`);
10111011
returnresponse.data;
10121012
};

‎site/src/api/queries/deployment.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import*asAPIfrom"api/api";
2+
3+
exportconstdeploymentConfig=()=>{
4+
return{
5+
queryKey:["deployment","config"],
6+
queryFn:API.getDeploymentConfig,
7+
};
8+
};
9+
10+
exportconstdeploymentDAUs=()=>{
11+
return{
12+
queryKey:["deployment","daus"],
13+
queryFn:()=>API.getDeploymentDAUs(),
14+
};
15+
};

‎site/src/components/DeploySettingsLayout/DeploySettingsLayout.tsx‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ import { Margins } from "components/Margins/Margins";
33
import{Stack}from"components/Stack/Stack";
44
import{Sidebar}from"./Sidebar";
55
import{createContext,Suspense,useContext,FC}from"react";
6-
import{useMachine}from"@xstate/react";
76
import{Loader}from"components/Loader/Loader";
8-
import{DAUsResponse}from"api/typesGenerated";
9-
import{deploymentConfigMachine}from"xServices/deploymentConfig/deploymentConfigMachine";
107
import{RequirePermission}from"components/RequirePermission/RequirePermission";
118
import{usePermissions}from"hooks/usePermissions";
129
import{Outlet}from"react-router-dom";
1310
import{DeploymentConfig}from"api/api";
11+
import{useQuery}from"@tanstack/react-query";
12+
import{deploymentConfig}from"api/queries/deployment";
1413

1514
typeDeploySettingsContextValue={
1615
deploymentValues:DeploymentConfig;
17-
getDeploymentValuesError:unknown;
18-
deploymentDAUs?:DAUsResponse;
19-
getDeploymentDAUsError:unknown;
2016
};
2117

2218
constDeploySettingsContext=createContext<
@@ -34,14 +30,8 @@ export const useDeploySettings = (): DeploySettingsContextValue => {
3430
};
3531

3632
exportconstDeploySettingsLayout:FC=()=>{
37-
const[state]=useMachine(deploymentConfigMachine);
33+
constdeploymentConfigQuery=useQuery(deploymentConfig());
3834
conststyles=useStyles();
39-
const{
40-
deploymentValues,
41-
deploymentDAUs,
42-
getDeploymentValuesError,
43-
getDeploymentDAUsError,
44-
}=state.context;
4535
constpermissions=usePermissions();
4636

4737
return(
@@ -50,13 +40,10 @@ export const DeploySettingsLayout: FC = () => {
5040
<StackclassName={styles.wrapper}direction="row"spacing={6}>
5141
<Sidebar/>
5242
<mainclassName={styles.content}>
53-
{deploymentValues ?(
43+
{deploymentConfigQuery.data ?(
5444
<DeploySettingsContext.Provider
5545
value={{
56-
deploymentValues,
57-
getDeploymentValuesError,
58-
deploymentDAUs,
59-
getDeploymentDAUsError,
46+
deploymentValues:deploymentConfigQuery.data,
6047
}}
6148
>
6249
<Suspensefallback={<Loader/>}>

‎site/src/pages/DeploySettingsPage/GeneralSettingsPage/GeneralSettingsPage.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { FC } from "react";
33
import{Helmet}from"react-helmet-async";
44
import{pageTitle}from"utils/page";
55
import{GeneralSettingsPageView}from"./GeneralSettingsPageView";
6+
import{useQuery}from"@tanstack/react-query";
7+
import{deploymentDAUs}from"api/queries/deployment";
68

79
constGeneralSettingsPage:FC=()=>{
8-
const{ deploymentValues, deploymentDAUs, getDeploymentDAUsError}=
9-
useDeploySettings();
10+
const{ deploymentValues}=useDeploySettings();
11+
constdeploymentDAUsQuery=useQuery(deploymentDAUs());
1012

1113
return(
1214
<>
@@ -15,8 +17,8 @@ const GeneralSettingsPage: FC = () => {
1517
</Helmet>
1618
<GeneralSettingsPageView
1719
deploymentOptions={deploymentValues.options}
18-
deploymentDAUs={deploymentDAUs}
19-
getDeploymentDAUsError={getDeploymentDAUsError}
20+
deploymentDAUs={deploymentDAUsQuery.data}
21+
deploymentDAUsError={deploymentDAUsQuery.error}
2022
/>
2123
</>
2224
);

‎site/src/pages/DeploySettingsPage/GeneralSettingsPage/GeneralSettingsPageView.stories.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const NoDAUs: Story = {
5959
exportconstDAUError:Story={
6060
args:{
6161
deploymentDAUs:undefined,
62-
getDeploymentDAUsError:mockApiError({
62+
deploymentDAUsError:mockApiError({
6363
message:"Error fetching DAUs.",
6464
}),
6565
},

‎site/src/pages/DeploySettingsPage/GeneralSettingsPage/GeneralSettingsPageView.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import { DeploymentOption } from "api/api";
1313
exporttypeGeneralSettingsPageViewProps={
1414
deploymentOptions:DeploymentOption[];
1515
deploymentDAUs?:DAUsResponse;
16-
getDeploymentDAUsError:unknown;
16+
deploymentDAUsError:unknown;
1717
};
1818
exportconstGeneralSettingsPageView=({
1919
deploymentOptions,
2020
deploymentDAUs,
21-
getDeploymentDAUsError,
21+
deploymentDAUsError,
2222
}:GeneralSettingsPageViewProps):JSX.Element=>{
2323
return(
2424
<>
@@ -28,8 +28,8 @@ export const GeneralSettingsPageView = ({
2828
docsHref={docs("/admin/configure")}
2929
/>
3030
<Stackspacing={4}>
31-
{Boolean(getDeploymentDAUsError)&&(
32-
<ErrorAlerterror={getDeploymentDAUsError}/>
31+
{Boolean(deploymentDAUsError)&&(
32+
<ErrorAlerterror={deploymentDAUsError}/>
3333
)}
3434
{deploymentDAUs&&(
3535
<Boxheight={200}sx={{mb:3}}>

‎site/src/pages/UsersPage/UsersPage.tsx‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { UsersPageView } from "./UsersPageView";
1818
import{useStatusFilterMenu}from"./UsersFilter";
1919
import{useFilter}from"components/Filter/filter";
2020
import{useDashboard}from"components/Dashboard/DashboardProvider";
21-
import{deploymentConfigMachine}from"xServices/deploymentConfig/deploymentConfigMachine";
2221
import{useQuery}from"@tanstack/react-query";
2322
import{getAuthMethods}from"api/api";
2423
import{roles}from"api/queries/roles";
24+
import{deploymentConfig}from"api/queries/deployment";
2525

2626
exportconstLanguage={
2727
suspendDialogTitle:"Suspend user",
@@ -62,14 +62,12 @@ export const UsersPage: FC<{ children?: ReactNode }> = () => {
6262
paginationRef,
6363
count,
6464
}=usersState.context;
65-
6665
const{updateUsers:canEditUsers, viewDeploymentValues}=usePermissions();
6766
constrolesQuery=useQuery({ ...roles(),enabled:canEditUsers});
68-
69-
// Ideally this only runs if 'canViewDeployment' is true.
70-
// TODO: Prevent api call if the user does not have the perms.
71-
const[state]=useMachine(deploymentConfigMachine);
72-
const{ deploymentValues}=state.context;
67+
const{data:deploymentValues}=useQuery({
68+
...deploymentConfig(),
69+
enabled:viewDeploymentValues,
70+
});
7371
// Indicates if oidc roles are synced from the oidc idp.
7472
// Assign 'false' if unknown.
7573
constoidcRoleSyncEnabled=

‎site/src/pages/WorkspacePage/WorkspacePage.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const renderWorkspacePage = async () => {
3838
jest.spyOn(api,"getTemplate").mockResolvedValueOnce(MockTemplate);
3939
jest.spyOn(api,"getTemplateVersionRichParameters").mockResolvedValueOnce([]);
4040
jest
41-
.spyOn(api,"getDeploymentValues")
41+
.spyOn(api,"getDeploymentConfig")
4242
.mockResolvedValueOnce(MockDeploymentConfig);
4343
jest
4444
.spyOn(api,"watchWorkspaceAgentLogs")

‎site/src/xServices/deploymentConfig/deploymentConfigMachine.ts‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

‎site/src/xServices/workspace/workspaceXService.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ async function loadInitialWorkspaceData({
781781
(permissionsasPermissions)?.viewDeploymentValues,
782782
);
783783
constdeploymentValues=canViewDeploymentValues
784-
?(awaitAPI.getDeploymentValues())?.config
784+
?(awaitAPI.getDeploymentConfig())?.config
785785
:undefined;
786786
return{
787787
workspace,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp