Skip to content

feat: add frontend warning when autostart disabled due to automatic updates #10508

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 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
12 changes: 12 additions & 0 deletions site/src/api/queries/workspaceQuota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
};
8 changes: 8 additions & 0 deletions site/src/pages/WorkspacePage/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 29 additions & 6 deletions site/src/pages/WorkspacePage/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface WorkspaceProps {
onLoadMoreBuilds: () => void;
isLoadingMoreBuilds: boolean;
hasMoreBuilds: boolean;
canAutostart: boolean;
}

/**
Expand Down Expand Up @@ -111,6 +112,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
onLoadMoreBuilds,
isLoadingMoreBuilds,
hasMoreBuilds,
canAutostart,
}) => {
const navigate = useNavigate();
const serverVersion = buildInfo?.version || "";
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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" &&
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/WorkspacePage/WorkspaceActions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const actionsByWorkspaceStatus = (
}
if (
workspace.outdated &&
workspaceUpdatePolicy(workspace, canChangeVersions)
workspaceUpdatePolicy(workspace, canChangeVersions) === "always"
) {
if (status === "running") {
return {
Expand Down
12 changes: 11 additions & 1 deletion site/src/pages/WorkspacePage/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -70,6 +79,7 @@ export const WorkspacePage: FC = () => {
await buildsQuery.fetchNextPage();
}}
hasMoreBuilds={Boolean(buildsQuery.hasNextPage)}
canAutostart={canAutostart}
/>
</RequirePermission>
);
Expand Down
3 changes: 3 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface WorkspaceReadyPageProps {
onLoadMoreBuilds: () => void;
isLoadingMoreBuilds: boolean;
hasMoreBuilds: boolean;
canAutostart: boolean;
}

export const WorkspaceReadyPage = ({
Expand All @@ -57,6 +58,7 @@ export const WorkspaceReadyPage = ({
onLoadMoreBuilds,
isLoadingMoreBuilds,
hasMoreBuilds,
canAutostart,
}: WorkspaceReadyPageProps): JSX.Element => {
const { buildInfo } = useDashboard();
const featureVisibility = useFeatureVisibility();
Expand Down Expand Up @@ -213,6 +215,7 @@ export const WorkspaceReadyPage = ({
<WorkspaceBuildLogsSection logs={buildLogs} />
)
}
canAutostart={canAutostart}
/>
<DeleteDialog
entity="workspace"
Expand Down