8000 feat: add frontend warning when autostart disabled due to automatic updates by sreya · Pull Request #10508 · coder/coder · GitHub
[go: up one dir, main page]

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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading 10000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add frontend warning when autostart disabled due to automatic u…
…pdates
  • Loading branch information
sreya committed Nov 9, 2023
commit 1d88c5cbf53c922ec38c736abecc3145505e41d9
7 changes: 7 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,13 @@ export const updateWorkspace = async (
});
};

export const getWorkspaceResolveAutostart = async (
workspaceId: string,
): Promise<TypesGen.ResolveAutostartResponse> => {
const response = await axios.get(`/api/v2/workspaces/${workspaceId}/resolve`);
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
23 changes: 22 additions & 1 deletion 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,23 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({

<Margins css={styles.content}>
<Stack direction="column" css={styles.firstColumnSpacer} spacing={4}>
{workspace.outdated && (
{requiresManualUpdate && workspace.outdated && (
<Alert severity="info">
<AlertTitle>An update is available for your workspace</AlertTitle>
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
</Alert>
)}
{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>
)}
{buildError}
{cancellationError}
{workspace.latest_build.status === "running" &&
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
0