Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 177affb

Browse files
authored
feat: add frontend warning when autostart disabled due to automatic updates (coder#10508)
1 parent 9c5b631 commit 177affb

File tree

7 files changed

+73
-8
lines changed

7 files changed

+73
-8
lines changed

site/src/api/api.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,15 @@ export const updateWorkspace = async (
12871287
});
12881288
};
12891289

1290+
export const getWorkspaceResolveAutostart = async (
1291+
workspaceId: string,
1292+
): Promise<TypesGen.ResolveAutostartResponse> => {
1293+
const response = await axios.get(
1294+
`/api/v2/workspaces/${workspaceId}/resolve-autostart`,
1295+
);
1296+
return response.data;
1297+
};
1298+
12901299
const getMissingParameters = (
12911300
oldBuildParameters: TypesGen.WorkspaceBuildParameter[],
12921301
newBuildParameters: TypesGen.WorkspaceBuildParameter[],

site/src/api/queries/workspaceQuota.ts

+12
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ export const workspaceQuota = (username: string) => {
1111
queryFn: () => API.getWorkspaceQuota(username),
1212
};
1313
};
14+
15+
const getWorkspaceResolveAutostartQueryKey = (workspaceId: string) => [
16+
workspaceId,
17+
"workspaceResolveAutostart",
18+
];
19+
20+
export const workspaceResolveAutostart = (workspaceId: string) => {
21+
return {
22+
queryKey: getWorkspaceResolveAutostartQueryKey(workspaceId),
23+
queryFn: () => API.getWorkspaceResolveAutostart(workspaceId),
24+
};
25+
};

site/src/pages/WorkspacePage/Workspace.stories.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ export const Outdated: Story = {
212212
},
213213
};
214214

215+
export const CantAutostart: Story = {
216+
args: {
217+
...Running.args,
218+
canAutostart: false,
219+
workspace: Mocks.MockOutdatedRunningWorkspaceRequireActiveVersion,
220+
},
221+
};
222+
215223
export const GetBuildsError: Story = {
216224
args: {
217225
...Running.args,

site/src/pages/WorkspacePage/Workspace.tsx

+29-6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface WorkspaceProps {
7373
onLoadMoreBuilds: () => void;
7474
isLoadingMoreBuilds: boolean;
7575
hasMoreBuilds: boolean;
76+
canAutostart: boolean;
7677
}
7778

7879
/**
@@ -111,6 +112,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
111112
onLoadMoreBuilds,
112113
isLoadingMoreBuilds,
113114
hasMoreBuilds,
115+
canAutostart,
114116
}) => {
115117
const navigate = useNavigate();
116118
const serverVersion = buildInfo?.version || "";
@@ -168,6 +170,14 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
168170
clearTimeout(showTimer);
169171
};
170172
}, [workspace, now, showAlertPendingInQueue]);
173+
174+
const updateRequired =
175+
(workspace.template_require_active_version ||
176+
workspace.automatic_updates === "always") &&
177+
workspace.outdated;
178+
const autoStartFailing = workspace.autostart_schedule && !canAutostart;
179+
const requiresManualUpdate = updateRequired && autoStartFailing;
180+
171181
return (
172182
<>
173183
<FullWidthPageHeader>
@@ -220,12 +230,25 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
220230

221231
<Margins css={styles.content}>
222232
<Stack direction="column" css={styles.firstColumnSpacer} spacing={4}>
223-
{workspace.outdated && (
224-
<Alert severity="info">
225-
<AlertTitle>An update is available for your workspace</AlertTitle>
226-
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
227-
</Alert>
228-
)}
233+
{workspace.outdated &&
234+
(requiresManualUpdate ? (
235+
<Alert severity="warning">
236+
<AlertTitle>
237+
Autostart has been disabled for your workspace.
238+
</AlertTitle>
239+
<AlertDetail>
240+
Autostart is unable to automatically update your workspace.
241+
Manually update your workspace to reenable Autostart.
242+
</AlertDetail>
243+
</Alert>
244+
) : (
245+
<Alert severity="info">
246+
<AlertTitle>
247+
An update is available for your workspace
248+
</AlertTitle>
249+
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
250+
</Alert>
251+
))}
229252
{buildError}
230253
{cancellationError}
231254
{workspace.latest_build.status === "running" &&

site/src/pages/WorkspacePage/WorkspaceActions/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const actionsByWorkspaceStatus = (
4545
}
4646
if (
4747
workspace.outdated &&
48-
workspaceUpdatePolicy(workspace, canChangeVersions)
48+
workspaceUpdatePolicy(workspace, canChangeVersions) === "always"
4949
) {
5050
if (status === "running") {
5151
return {

site/src/pages/WorkspacePage/WorkspacePage.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { ErrorAlert } from "components/Alert/ErrorAlert";
99
import { useOrganizationId } from "hooks";
1010
import { isAxiosError } from "axios";
1111
import { Margins } from "components/Margins/Margins";
12-
import { workspaceQuota } from "api/queries/workspaceQuota";
12+
import {
13+
workspaceQuota,
14+
workspaceResolveAutostart,
15+
} from "api/queries/workspaceQuota";
1316
import { useInfiniteQuery, useQuery } from "react-query";
1417
import { infiniteWorkspaceBuilds } from "api/queries/workspaceBuilds";
1518

@@ -41,6 +44,12 @@ export const WorkspacePage: FC = () => {
4144
enabled: Boolean(workspace),
4245
});
4346

47+
const canAutostartResponse = useQuery(
48+
workspaceResolveAutostart(workspace?.id ?? ""),
49+
);
50+
51+
const canAutostart = !canAutostartResponse.data?.parameter_mismatch ?? false;
52+
4453
if (pageError) {
4554
return (
4655
<Margins>
@@ -70,6 +79,7 @@ export const WorkspacePage: FC = () => {
7079
await buildsQuery.fetchNextPage();
7180
}}
7281
hasMoreBuilds={Boolean(buildsQuery.hasNextPage)}
82+
canAutostart={canAutostart}
7383
/>
7484
</RequirePermission>
7585
);

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface WorkspaceReadyPageProps {
4646
onLoadMoreBuilds: () => void;
4747
isLoadingMoreBuilds: boolean;
4848
hasMoreBuilds: boolean;
49+
canAutostart: boolean;
4950
}
5051

5152
export const WorkspaceReadyPage = ({
@@ -57,6 +58,7 @@ export const WorkspaceReadyPage = ({
5758
onLoadMoreBuilds,
5859
isLoadingMoreBuilds,
5960
hasMoreBuilds,
61+
canAutostart,
6062
}: WorkspaceReadyPageProps): JSX.Element => {
6163
const { buildInfo } = useDashboard();
6264
const featureVisibility = useFeatureVisibility();
@@ -213,6 +215,7 @@ export const WorkspaceReadyPage = ({
213215
<WorkspaceBuildLogsSection logs={buildLogs} />
214216
)
215217
}
218+
canAutostart={canAutostart}
216219
/>
217220
<DeleteDialog
218221
entity="workspace"

0 commit comments

Comments
 (0)