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

Skip to content

Commit 9570f91

Browse files
committed
update frontend
1 parent 609af77 commit 9570f91

File tree

6 files changed

+54
-22
lines changed

6 files changed

+54
-22
lines changed

site/src/api/api.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,13 @@ 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(`/api/v2/workspaces/${workspaceId}/resolve`);
1294+
return response.data;
1295+
};
1296+
12901297
const getMissingParameters = (
12911298
oldBuildParameters: TypesGen.WorkspaceBuildParameter[],
12921299
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.tsx

+21-20
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface WorkspaceProps {
7474
onLoadMoreBuilds: () => void;
7575
isLoadingMoreBuilds: boolean;
7676
hasMoreBuilds: boolean;
77+
canAutostart: boolean;
7778
}
7879

7980
/**
@@ -112,6 +113,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
112113
onLoadMoreBuilds,
113114
isLoadingMoreBuilds,
114115
hasMoreBuilds,
116+
canAutostart,
115117
}) => {
116118
const navigate = useNavigate();
117119
const serverVersion = buildInfo?.version || "";
@@ -170,10 +172,12 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
170172
};
171173
}, [workspace, now, showAlertPendingInQueue]);
172174

173-
console.log("policy: " + workspaceUpdatePolicy(workspace, canChangeVersions));
174-
console.log("autostart schedule: " + workspace.autostart_schedule);
175-
console.log("outdated: " + workspace.outdated);
176-
console.log("mismatch: " + workspace.parameter_mismatch);
175+
const showAutostartBanner =
176+
(workspace.template_require_active_version ||
177+
workspace.automatic_updates === "always") &&
178+
workspace.autostart_schedule &&
179+
workspace.outdated &&
180+
!canAutostart;
177181

178182
return (
179183
<>
@@ -227,29 +231,26 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
227231

228232
<Margins css={styles.content}>
229233
<Stack direction="column" css={styles.firstColumnSpacer} spacing={4}>
230-
{workspace.outdated && (
234+
{!showAutostartBanner && workspace.outdated && (
231235
<Alert severity="info">
232236
<AlertTitle>An update is available for your workspace</AlertTitle>
233237
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
234238
</Alert>
235239
)}
240+
{showAutostartBanner && (
241+
<Alert severity="warning">
242+
<AlertTitle>
243+
Autostart has been disabled for your workspace.
244+
</AlertTitle>
245+
<AlertDetail>
246+
A parameter mismatch has been detected between your workspace
247+
and the active template version. Manually update your workspace
248+
to reenable Autostart.
249+
</AlertDetail>
250+
</Alert>
251+
)}
236252
{buildError}
237253
{cancellationError}
238-
{workspaceUpdatePolicy(workspace, canChangeVersions) === "always" &&
239-
workspace.autostart_schedule &&
240-
workspace.outdated &&
241-
workspace.parameter_mismatch && (
242-
<Alert severity="warning">
243-
<AlertTitle>
244-
Autostart has been disabled for your workspace.
245-
</AlertTitle>
246-
<AlertDetail>
247-
A parameter mismatch has been detected between your workspace
248-
and the active template version. Manually update your
249-
workspace to reenable Autostart.
250-
</AlertDetail>
251-
</Alert>
252-
)}
253254
{workspace.latest_build.status === "running" &&
254255
!workspace.health.healthy && (
255256
<Alert

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
@@ -44,6 +44,7 @@ interface WorkspaceReadyPageProps {
4444
onLoadMoreBuilds: () => void;
4545
isLoadingMoreBuilds: boolean;
4646
hasMoreBuilds: boolean;
47+
canAutostart: boolean;
4748
}
4849

4950
export const WorkspaceReadyPage = ({
@@ -55,6 +56,7 @@ export const WorkspaceReadyPage = ({
5556
onLoadMoreBuilds,
5657
isLoadingMoreBuilds,
5758
hasMoreBuilds,
59+
canAutostart,
5860
}: WorkspaceReadyPageProps): JSX.Element => {
5961
const [_, bannerSend] = useActor(
6062
workspaceState.children["scheduleBannerMachine"],
@@ -209,6 +211,7 @@ export const WorkspaceReadyPage = ({
209211
<WorkspaceBuildLogsSection logs={buildLogs} />
210212
)
211213
}
214+
canAutostart={canAutostart}
212215
/>
213216
<DeleteDialog
214217
entity="workspace"

site/src/xServices/workspace/workspaceXService.ts

-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ async function loadInitialWorkspaceData({
690690
workspaceName,
691691
{
692692
include_deleted: true,
693-
resolve_parameters: true,
694693
},
695694
);
696695
const template = await API.getTemplateByName(orgId, workspace.template_name);

0 commit comments

Comments
 (0)