Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9f7283

Browse files
refactor: Move deploy settings machine to the layout (#5693)
1 parent cd1a2d2 commit f9f7283

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

site/src/components/DeploySettingsLayout/DeploySettingsLayout.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import {
77
PropsWithChildren,
88
Suspense,
99
useContext,
10-
useEffect,
1110
FC,
1211
} from "react"
13-
import { useActor } from "@xstate/react"
14-
import { XServiceContext } from "xServices/StateContext"
12+
import { useMachine } from "@xstate/react"
1513
import { Loader } from "components/Loader/Loader"
1614
import { DeploymentConfig } from "api/typesGenerated"
15+
import { deploymentConfigMachine } from "xServices/deploymentConfig/deploymentConfigMachine"
1716

1817
type DeploySettingsContextValue = { deploymentConfig: DeploymentConfig }
1918

@@ -32,17 +31,10 @@ export const useDeploySettings = (): DeploySettingsContextValue => {
3231
}
3332

3433
export const DeploySettingsLayout: FC<PropsWithChildren> = ({ children }) => {
35-
const xServices = useContext(XServiceContext)
36-
const [state, send] = useActor(xServices.deploymentConfigXService)
34+
const [state] = useMachine(deploymentConfigMachine)
3735
const styles = useStyles()
3836
const { deploymentConfig } = state.context
3937

40-
useEffect(() => {
41-
if (state.matches("idle")) {
42-
send("LOAD")
43-
}
44-
}, [send, state])
45-
4638
return (
4739
<Margins>
4840
<Stack className={styles.wrapper} direction="row" spacing={6}>

site/src/xServices/StateContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ActorRefFrom } from "xstate"
44
import { authMachine } from "./auth/authXService"
55
import { buildInfoMachine } from "./buildInfo/buildInfoXService"
66
import { updateCheckMachine } from "./updateCheck/updateCheckXService"
7-
import { deploymentConfigMachine } from "./deploymentConfig/deploymentConfigMachine"
87
import { entitlementsMachine } from "./entitlements/entitlementsXService"
98
import { appearanceMachine } from "./appearance/appearanceXService"
109

@@ -13,8 +12,6 @@ interface XServiceContextType {
1312
buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
1413
entitlementsXService: ActorRefFrom<typeof entitlementsMachine>
1514
appearanceXService: ActorRefFrom<typeof appearanceMachine>
16-
// Since the info here is used by multiple deployment settings page and we don't want to refetch them every time
17-
deploymentConfigXService: ActorRefFrom<typeof deploymentConfigMachine>
1815
updateCheckXService: ActorRefFrom<typeof updateCheckMachine>
1916
}
2017

@@ -36,7 +33,6 @@ export const XServiceProvider: FC<{ children: ReactNode }> = ({ children }) => {
3633
buildInfoXService: useInterpret(buildInfoMachine),
3734
entitlementsXService: useInterpret(entitlementsMachine),
3835
appearanceXService: useInterpret(appearanceMachine),
39-
deploymentConfigXService: useInterpret(deploymentConfigMachine),
4036
updateCheckXService: useInterpret(updateCheckMachine),
4137
}}
4238
>

site/src/xServices/deploymentConfig/deploymentConfigMachine.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const deploymentConfigMachine = createMachine(
66
{
77
id: "deploymentConfigMachine",
88
predictableActionArguments: true,
9-
initial: "idle",
9+
1010
schema: {
1111
context: {} as {
1212
deploymentConfig?: DeploymentConfig
@@ -20,28 +20,22 @@ export const deploymentConfigMachine = createMachine(
2020
},
2121
},
2222
tsTypes: {} as import("./deploymentConfigMachine.typegen").Typegen0,
23+
initial: "loading",
2324
states: {
24-
idle: {
25-
on: {
26-
LOAD: {
27-
target: "loading",
28-
},
29-
},
30-
},
3125
loading: {
3226
invoke: {
3327
src: "getDeploymentConfig",
3428
onDone: {
35-
target: "loaded",
29+
target: "done",
3630
actions: ["assignDeploymentConfig"],
3731
},
3832
onError: {
39-
target: "idle",
33+
target: "done",
4034
actions: ["assignGetDeploymentConfigError"],
4135
},
4236
},
4337
},
44-
loaded: {
38+
done: {
4539
type: "final",
4640
},
4741
},

0 commit comments

Comments
 (0)