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
Improve error handling
  • Loading branch information
presleyp committed Dec 14, 2022
commit 9a267d60bfb539a2bccb9311d3aa1e14c1d497b5
2 changes: 0 additions & 2 deletions site/src/i18n/en/workspaceSchedulePage.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"forbiddenError": "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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import {
WorkspaceScheduleFormValues,
Language as FormLanguage,
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
import {
WorkspaceSchedulePage,
} from "./WorkspaceSchedulePage"
import { WorkspaceSchedulePage } from "./WorkspaceSchedulePage"
import i18next from "i18next"

const { t } = i18next
Expand Down
55 changes: 32 additions & 23 deletions site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { makeStyles } from "@material-ui/core/styles"
import { useMachine } from "@xstate/react"
import { AlertBanner } from "components/AlertBanner/AlertBanner"
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
import { Margins } from "components/Margins/Margins"
import { scheduleToAutoStart } from "pages/WorkspaceSchedulePage/schedule"
import { ttlMsToAutoStop } from "pages/WorkspaceSchedulePage/ttl"
import React, { useEffect } from "react"
Expand All @@ -22,8 +24,15 @@ const getAutoStart = (workspace?: TypesGen.Workspace) =>
const getAutoStop = (workspace?: TypesGen.Workspace) =>
ttlMsToAutoStop(workspace?.ttl_ms)

const useStyles = makeStyles((theme) => ({
topMargin: {
marginTop: `${theme.spacing(3)}px`,
},
}))

export const WorkspaceSchedulePage: React.FC = () => {
const { t } = useTranslation("workspaceSchedulePage")
const styles = useStyles()
const { username: usernameQueryParam, workspace: workspaceQueryParam } =
useParams()
const navigate = useNavigate()
Expand All @@ -34,6 +43,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
checkPermissionsError,
submitScheduleError,
getWorkspaceError,
getTemplateError,
permissions,
workspace,
} = scheduleState.context
Expand All @@ -51,34 +61,37 @@ export const WorkspaceSchedulePage: React.FC = () => {
}

if (
scheduleState.matches("idle") ||
scheduleState.matches("gettingWorkspace") ||
scheduleState.matches("gettingPermissions") ||
scheduleState.matches("gettingTemplate") ||
!workspace
scheduleState.hasTag("loading")
) {
return <FullScreenLoader />
}

if (scheduleState.matches("error")) {
return (
<AlertBanner
severity="error"
error={getWorkspaceError || checkPermissionsError}
text={
getWorkspaceError
? t("getWorkspaceError")
: t("checkPermissionsError")
}
retry={() =>
scheduleSend({ type: "GET_WORKSPACE", username, workspaceName })
}
/>
<Margins>
<div className={styles.topMargin}>
<AlertBanner
severity="error"
error={
getWorkspaceError || checkPermissionsError || getTemplateError
}
retry={() =>
scheduleSend({ type: "GET_WORKSPACE", username, workspaceName })
}
/>
</div>
</Margins>
)
}

if (!permissions?.updateWorkspace) {
return <AlertBanner severity="error" error={Error(t("forbiddenError"))} />
return (
<Margins>
<div className={styles.topMargin}>
<AlertBanner severity="error" error={Error(t("forbiddenError"))} />
</div>
</Margins>
)
}

if (
Expand Down Expand Up @@ -129,11 +142,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
}

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

// Theoretically impossible - log and bail
Expand Down
16 changes: 10 additions & 6 deletions site/src/xServices/workspaceSchedule/workspaceScheduleXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const workspaceSchedule =
services: {} as {
getWorkspace: {
data: TypesGen.Workspace
},
}
getTemplate: {
data: TypesGen.Template
}
Expand Down Expand Up @@ -117,6 +117,7 @@ export const workspaceSchedule =
},
],
},
tags: "loading"
},
gettingTemplate: {
entry: "clearGetTemplateError",
Expand Down Expand Up @@ -200,13 +201,13 @@ export const workspaceSchedule =
checkPermissionsError: (_, event) => event.data,
}),
assignTemplate: assign({
template: (_, event) => event.data
template: (_, event) => event.data,
}),
assignGetTemplateError: assign({
getTemplateError: (_, event) => event.data
getTemplateError: (_, event) => event.data,
}),
clearGetTemplateError: assign({
getTemplateError: (_) => undefined
getTemplateError: (_) => undefined,
}),
assignAutoStopChanged: assign({
autoStopChanged: (_, event) => event.autoStopChanged,
Expand All @@ -224,9 +225,12 @@ export const workspaceSchedule =
// user can return to the workspace page to see the restart
restartWorkspace: (context) => {
if (context.workspace && context.template) {
return API.startWorkspace(context.workspace.id, context.template.active_version_id)
return API.startWorkspace(
context.workspace.id,
context.template.active_version_id,
)
}
}
},
},

services: {
Expand Down