Skip to content

Commit 95ca5f7

Browse files
committed
fix(site): exclude workspace schedule settings for prebuilt workspaces
1 parent c1b2304 commit 95ca5f7

File tree

2 files changed

+69
-36
lines changed

2 files changed

+69
-36
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Workspace } from "api/typesGenerated";
2+
3+
// Returns true if the workspace is a prebuilt workspace (owned by the prebuilds system user),
4+
// otherwise returns false.
5+
export const isPrebuiltWorkspace = (workspace: Workspace): boolean => {
6+
return workspace.owner_id === "c42fdf75-3097-471c-8c33-fb52454d81c0";
7+
};

site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { Alert } from "components/Alert/Alert";
77
import { ErrorAlert } from "components/Alert/ErrorAlert";
88
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog";
99
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils";
10+
import { Link } from "components/Link/Link";
1011
import { Loader } from "components/Loader/Loader";
1112
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
1213
import dayjs from "dayjs";
14+
import { isPrebuiltWorkspace } from "modules/workspaces/prebuilds";
1315
import {
1416
scheduleChanged,
1517
scheduleToAutostart,
@@ -20,6 +22,7 @@ import { type FC, useState } from "react";
2022
import { Helmet } from "react-helmet-async";
2123
import { useMutation, useQuery, useQueryClient } from "react-query";
2224
import { useNavigate, useParams } from "react-router-dom";
25+
import { docs } from "utils/docs";
2326
import { pageTitle } from "utils/page";
2427
import { WorkspaceScheduleForm } from "./WorkspaceScheduleForm";
2528
import {
@@ -94,42 +97,65 @@ const WorkspaceSchedulePage: FC = () => {
9497
</Alert>
9598
)}
9699

97-
{template && (
98-
<WorkspaceScheduleForm
99-
template={template}
100-
error={submitScheduleMutation.error}
101-
initialValues={{
102-
...getAutostart(workspace),
103-
...getAutostop(workspace),
104-
}}
105-
isLoading={submitScheduleMutation.isPending}
106-
defaultTTL={dayjs.duration(template.default_ttl_ms, "ms").asHours()}
107-
onCancel={() => {
108-
navigate(`/@${username}/${workspaceName}`);
109-
}}
110-
onSubmit={async (values) => {
111-
const data = {
112-
workspace,
113-
autostart: formValuesToAutostartRequest(values),
114-
ttl: formValuesToTTLRequest(values),
115-
autostartChanged: scheduleChanged(
116-
getAutostart(workspace),
117-
values,
118-
),
119-
autostopChanged: scheduleChanged(getAutostop(workspace), values),
120-
};
121-
122-
await submitScheduleMutation.mutateAsync(data);
123-
124-
if (
125-
data.autostopChanged &&
126-
getAutostop(workspace).autostopEnabled
127-
) {
128-
setIsConfirmingApply(true);
129-
}
130-
}}
131-
/>
132-
)}
100+
{template &&
101+
// Prebuilt workspaces have their own scheduling system,
102+
// so we avoid showing the workspace-level schedule settings form.
103+
// Instead, show an informational message with a link to the relevant docs.
104+
(isPrebuiltWorkspace(workspace) ? (
105+
<Alert severity="info">
106+
Prebuilt workspaces do not support workspace-level scheduling. For
107+
prebuilt workspace specific scheduling refer to the{" "}
108+
<Link
109+
title="Prebuilt Workspaces Scheduling"
110+
href={docs(
111+
"/admin/templates/extending-templates/prebuilt-workspaces#scheduling",
112+
)}
113+
target="_blank"
114+
rel="noreferrer"
115+
>
116+
Prebuilt Workspaces Scheduling
117+
</Link>
118+
documentation page.
119+
</Alert>
120+
) : (
121+
<WorkspaceScheduleForm
122+
template={template}
123+
error={submitScheduleMutation.error}
124+
initialValues={{
125+
...getAutostart(workspace),
126+
...getAutostop(workspace),
127+
}}
128+
isLoading={submitScheduleMutation.isPending}
129+
defaultTTL={dayjs.duration(template.default_ttl_ms, "ms").asHours()}
130+
onCancel={() => {
131+
navigate(`/@${username}/${workspaceName}`);
132+
}}
133+
onSubmit={async (values) => {
134+
const data = {
135+
workspace,
136+
autostart: formValuesToAutostartRequest(values),
137+
ttl: formValuesToTTLRequest(values),
138+
autostartChanged: scheduleChanged(
139+
getAutostart(workspace),
140+
values,
141+
),
142+
autostopChanged: scheduleChanged(
143+
getAutostop(workspace),
144+
values,
145+
),
146+
};
147+
148+
await submitScheduleMutation.mutateAsync(data);
149+
150+
if (
151+
data.autostopChanged &&
152+
getAutostop(workspace).autostopEnabled
153+
) {
154+
setIsConfirmingApply(true);
155+
}
156+
}}
157+
/>
158+
))}
133159

134160
<ConfirmDialog
135161
open={isConfirmingApply}

0 commit comments

Comments
 (0)