Skip to content

Commit 09d2214

Browse files
committed
Restart workspace
1 parent 9408e24 commit 09d2214

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

site/src/pages/WorkspacePage/WorkspacePage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useMachine } from "@xstate/react"
33
import { AlertBanner } from "components/AlertBanner/AlertBanner"
44
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
55
import { FC, useEffect } from "react"
6-
import { useParams } from "react-router-dom"
6+
import { useLocation, useParams } from "react-router-dom"
77
import { Loader } from "components/Loader/Loader"
88
import { firstOrItem } from "util/array"
99
import { workspaceMachine } from "xServices/workspace/workspaceXService"
@@ -15,6 +15,7 @@ export const WorkspacePage: FC = () => {
1515
useParams()
1616
const username = firstOrItem(usernameQueryParam, null)
1717
const workspaceName = firstOrItem(workspaceQueryParam, null)
18+
const shouldRestartWorkspace = useLocation().state?.shouldRestartWorkspace ?? false
1819
const [workspaceState, workspaceSend] = useMachine(workspaceMachine)
1920
const {
2021
workspace,
@@ -69,6 +70,7 @@ export const WorkspacePage: FC = () => {
6970
workspaceState={workspaceState}
7071
quotaState={quotaState}
7172
workspaceSend={workspaceSend}
73+
shouldRestartWorkspace={shouldRestartWorkspace}
7274
/>
7375
</Cond>
7476
<Cond>

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ interface WorkspaceReadyPageProps {
3030
workspaceState: StateFrom<typeof workspaceMachine>
3131
quotaState: StateFrom<typeof quotaMachine>
3232
workspaceSend: (event: WorkspaceEvent) => void
33+
shouldRestartWorkspace: boolean
3334
}
3435

3536
export const WorkspaceReadyPage = ({
3637
workspaceState,
3738
quotaState,
3839
workspaceSend,
40+
shouldRestartWorkspace
3941
}: WorkspaceReadyPageProps): JSX.Element => {
4042
const [bannerState, bannerSend] = useActor(
4143
workspaceState.children["scheduleBannerMachine"],
@@ -71,6 +73,13 @@ export const WorkspaceReadyPage = ({
7173
bannerSend({ type: "REFRESH_WORKSPACE", workspace })
7274
}, [bannerSend, workspace])
7375

76+
useEffect(() => {
77+
// workspaces can be started without being stopped first
78+
shouldRestartWorkspace && workspaceSend({ type: "START" })
79+
// clear location state
80+
window.history.replaceState({}, document.title)
81+
}, [shouldRestartWorkspace, workspaceSend])
82+
7483
return (
7584
<>
7685
<Helmet>

0 commit comments

Comments
 (0)