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
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
Add dialog
  • Loading branch information
presleyp committed Dec 7, 2022
commit 9408e24bbff0b4f43f2037dd6d08eaadfae663d4
35 changes: 33 additions & 2 deletions site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMachine } from "@xstate/react"
import { AlertBanner } from "components/AlertBanner/AlertBanner"
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
import { scheduleToAutoStart } from "pages/WorkspaceSchedulePage/schedule"
import { ttlMsToAutoStop } from "pages/WorkspaceSchedulePage/ttl"
import React, { useEffect, useState } from "react"
Expand All @@ -20,6 +21,11 @@ const Language = {
"You don't have permissions to update the schedule for this workspace.",
getWorkspaceError: "Failed to fetch workspace.",
checkPermissionsError: "Failed to fetch permissions.",
dialogTitle: "Restart workspace?",
dialogDescription: `Would you like to restart your workspace now to apply your new auto-stop setting,
or let it apply after your next workspace start?`,
restart: "Restart workspace now",
applyLater: "Apply update later",
}

export const WorkspaceSchedulePage: React.FC = () => {
Expand All @@ -35,6 +41,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
getWorkspaceError,
permissions,
workspace,
shouldRestartWorkspace,
} = scheduleState.context

// Get workspace on mount and whenever the args for getting a workspace change.
Expand Down Expand Up @@ -119,8 +126,32 @@ export const WorkspaceSchedulePage: React.FC = () => {
)
}

if (scheduleState.matches("submitSuccess")) {
return <Navigate to={`/@${username}/${workspaceName}`} />
if (scheduleState.matches("showingRestartDialog")) {
return (
<ConfirmDialog
open
title={Language.dialogTitle}
description={Language.dialogDescription}
confirmText={Language.restart}
cancelText={Language.applyLater}
hideCancel={false}
onConfirm={() => {
scheduleSend("RESTART_WORKSPACE")
}}
onClose={() => {
scheduleSend("APPLY_LATER")
}}
/>
)
}

if (scheduleState.matches("done")) {
return (
<Navigate
to={`/@${username}/${workspaceName}`}
state={{ shouldRestartWorkspace }}
/>
)
}

// Theoretically impossible - log and bail
Expand Down