mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
feat: add frontend warning when autostart disabled due to automatic updates (#10508)
This commit is contained in:
@@ -1287,6 +1287,15 @@ export const updateWorkspace = async (
|
||||
});
|
||||
};
|
||||
|
||||
export const getWorkspaceResolveAutostart = async (
|
||||
workspaceId: string,
|
||||
): Promise<TypesGen.ResolveAutostartResponse> => {
|
||||
const response = await axios.get(
|
||||
`/api/v2/workspaces/${workspaceId}/resolve-autostart`,
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
const getMissingParameters = (
|
||||
oldBuildParameters: TypesGen.WorkspaceBuildParameter[],
|
||||
newBuildParameters: TypesGen.WorkspaceBuildParameter[],
|
||||
|
||||
@@ -11,3 +11,15 @@ export const workspaceQuota = (username: string) => {
|
||||
queryFn: () => API.getWorkspaceQuota(username),
|
||||
};
|
||||
};
|
||||
|
||||
const getWorkspaceResolveAutostartQueryKey = (workspaceId: string) => [
|
||||
workspaceId,
|
||||
"workspaceResolveAutostart",
|
||||
];
|
||||
|
||||
export const workspaceResolveAutostart = (workspaceId: string) => {
|
||||
return {
|
||||
queryKey: getWorkspaceResolveAutostartQueryKey(workspaceId),
|
||||
queryFn: () => API.getWorkspaceResolveAutostart(workspaceId),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -212,6 +212,14 @@ export const Outdated: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const CantAutostart: Story = {
|
||||
args: {
|
||||
...Running.args,
|
||||
canAutostart: false,
|
||||
workspace: Mocks.MockOutdatedRunningWorkspaceRequireActiveVersion,
|
||||
},
|
||||
};
|
||||
|
||||
export const GetBuildsError: Story = {
|
||||
args: {
|
||||
...Running.args,
|
||||
|
||||
@@ -73,6 +73,7 @@ export interface WorkspaceProps {
|
||||
onLoadMoreBuilds: () => void;
|
||||
isLoadingMoreBuilds: boolean;
|
||||
hasMoreBuilds: boolean;
|
||||
canAutostart: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,6 +112,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
|
||||
onLoadMoreBuilds,
|
||||
isLoadingMoreBuilds,
|
||||
hasMoreBuilds,
|
||||
canAutostart,
|
||||
}) => {
|
||||
const navigate = useNavigate();
|
||||
const serverVersion = buildInfo?.version || "";
|
||||
@@ -168,6 +170,14 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
|
||||
clearTimeout(showTimer);
|
||||
};
|
||||
}, [workspace, now, showAlertPendingInQueue]);
|
||||
|
||||
const updateRequired =
|
||||
(workspace.template_require_active_version ||
|
||||
workspace.automatic_updates === "always") &&
|
||||
workspace.outdated;
|
||||
const autoStartFailing = workspace.autostart_schedule && !canAutostart;
|
||||
const requiresManualUpdate = updateRequired && autoStartFailing;
|
||||
|
||||
return (
|
||||
<>
|
||||
<FullWidthPageHeader>
|
||||
@@ -220,12 +230,25 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
|
||||
|
||||
<Margins css={styles.content}>
|
||||
<Stack direction="column" css={styles.firstColumnSpacer} spacing={4}>
|
||||
{workspace.outdated && (
|
||||
<Alert severity="info">
|
||||
<AlertTitle>An update is available for your workspace</AlertTitle>
|
||||
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
|
||||
</Alert>
|
||||
)}
|
||||
{workspace.outdated &&
|
||||
(requiresManualUpdate ? (
|
||||
<Alert severity="warning">
|
||||
<AlertTitle>
|
||||
Autostart has been disabled for your workspace.
|
||||
</AlertTitle>
|
||||
<AlertDetail>
|
||||
Autostart is unable to automatically update your workspace.
|
||||
Manually update your workspace to reenable Autostart.
|
||||
</AlertDetail>
|
||||
</Alert>
|
||||
) : (
|
||||
<Alert severity="info">
|
||||
<AlertTitle>
|
||||
An update is available for your workspace
|
||||
</AlertTitle>
|
||||
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
|
||||
</Alert>
|
||||
))}
|
||||
{buildError}
|
||||
{cancellationError}
|
||||
{workspace.latest_build.status === "running" &&
|
||||
|
||||
@@ -45,7 +45,7 @@ export const actionsByWorkspaceStatus = (
|
||||
}
|
||||
if (
|
||||
workspace.outdated &&
|
||||
workspaceUpdatePolicy(workspace, canChangeVersions)
|
||||
workspaceUpdatePolicy(workspace, canChangeVersions) === "always"
|
||||
) {
|
||||
if (status === "running") {
|
||||
return {
|
||||
|
||||
@@ -9,7 +9,10 @@ import { ErrorAlert } from "components/Alert/ErrorAlert";
|
||||
import { useOrganizationId } from "hooks";
|
||||
import { isAxiosError } from "axios";
|
||||
import { Margins } from "components/Margins/Margins";
|
||||
import { workspaceQuota } from "api/queries/workspaceQuota";
|
||||
import {
|
||||
workspaceQuota,
|
||||
workspaceResolveAutostart,
|
||||
} from "api/queries/workspaceQuota";
|
||||
import { useInfiniteQuery, useQuery } from "react-query";
|
||||
import { infiniteWorkspaceBuilds } from "api/queries/workspaceBuilds";
|
||||
|
||||
@@ -41,6 +44,12 @@ export const WorkspacePage: FC = () => {
|
||||
enabled: Boolean(workspace),
|
||||
});
|
||||
|
||||
const canAutostartResponse = useQuery(
|
||||
workspaceResolveAutostart(workspace?.id ?? ""),
|
||||
);
|
||||
|
||||
const canAutostart = !canAutostartResponse.data?.parameter_mismatch ?? false;
|
||||
|
||||
if (pageError) {
|
||||
return (
|
||||
<Margins>
|
||||
@@ -70,6 +79,7 @@ export const WorkspacePage: FC = () => {
|
||||
await buildsQuery.fetchNextPage();
|
||||
}}
|
||||
hasMoreBuilds={Boolean(buildsQuery.hasNextPage)}
|
||||
canAutostart={canAutostart}
|
||||
/>
|
||||
</RequirePermission>
|
||||
);
|
||||
|
||||
@@ -46,6 +46,7 @@ interface WorkspaceReadyPageProps {
|
||||
onLoadMoreBuilds: () => void;
|
||||
isLoadingMoreBuilds: boolean;
|
||||
hasMoreBuilds: boolean;
|
||||
canAutostart: boolean;
|
||||
}
|
||||
|
||||
export const WorkspaceReadyPage = ({
|
||||
@@ -57,6 +58,7 @@ export const WorkspaceReadyPage = ({
|
||||
onLoadMoreBuilds,
|
||||
isLoadingMoreBuilds,
|
||||
hasMoreBuilds,
|
||||
canAutostart,
|
||||
}: WorkspaceReadyPageProps): JSX.Element => {
|
||||
const { buildInfo } = useDashboard();
|
||||
const featureVisibility = useFeatureVisibility();
|
||||
@@ -213,6 +215,7 @@ export const WorkspaceReadyPage = ({
|
||||
<WorkspaceBuildLogsSection logs={buildLogs} />
|
||||
)
|
||||
}
|
||||
canAutostart={canAutostart}
|
||||
/>
|
||||
<DeleteDialog
|
||||
entity="workspace"
|
||||
|
||||
Reference in New Issue
Block a user