Skip to content

feat: offer to restart workspace when ttl is changed #5391

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

Merged
merged 19 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Restart workspace
  • Loading branch information
presleyp committed Dec 7, 2022
commit 09d2214c41a6d1f5551857075d6e57a0aaa51a13
4 changes: 3 additions & 1 deletion site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMachine } from "@xstate/react"
import { AlertBanner } from "components/AlertBanner/AlertBanner"
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
import { FC, useEffect } from "react"
import { useParams } from "react-router-dom"
import { useLocation, useParams } from "react-router-dom"
import { Loader } from "components/Loader/Loader"
import { firstOrItem } from "util/array"
import { workspaceMachine } from "xServices/workspace/workspaceXService"
Expand All @@ -15,6 +15,7 @@ export const WorkspacePage: FC = () => {
useParams()
const username = firstOrItem(usernameQueryParam, null)
const workspaceName = firstOrItem(workspaceQueryParam, null)
const shouldRestartWorkspace = useLocation().state?.shouldRestartWorkspace ?? false
const [workspaceState, workspaceSend] = useMachine(workspaceMachine)
const {
workspace,
Expand Down Expand Up @@ -69,6 +70,7 @@ export const WorkspacePage: FC = () => {
workspaceState={workspaceState}
quotaState={quotaState}
workspaceSend={workspaceSend}
shouldRestartWorkspace={shouldRestartWorkspace}
/>
</Cond>
<Cond>
Expand Down
9 changes: 9 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ interface WorkspaceReadyPageProps {
workspaceState: StateFrom<typeof workspaceMachine>
quotaState: StateFrom<typeof quotaMachine>
workspaceSend: (event: WorkspaceEvent) => void
shouldRestartWorkspace: boolean
}

export const WorkspaceReadyPage = ({
workspaceState,
quotaState,
workspaceSend,
shouldRestartWorkspace
}: WorkspaceReadyPageProps): JSX.Element => {
const [bannerState, bannerSend] = useActor(
workspaceState.children["scheduleBannerMachine"],
Expand Down Expand Up @@ -71,6 +73,13 @@ export const WorkspaceReadyPage = ({
bannerSend({ type: "REFRESH_WORKSPACE", workspace })
}, [bannerSend, workspace])

useEffect(() => {
// workspaces can be started without being stopped first
shouldRestartWorkspace && workspaceSend({ type: "START" })
// clear location state
window.history.replaceState({}, document.title)
}, [shouldRestartWorkspace, workspaceSend])

return (
<>
<Helmet>
Expand Down