From e35fa8b9ee3de2a90df778cbcd8d2d35867816c6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Thu, 26 Mar 2026 19:45:16 +0000 Subject: [PATCH] fix(site): use restartWorkspace instead of startWorkspace in schedule dialog (#23658) --- .../WorkspaceSchedulePage.test.tsx | 41 ++++++++++++++++++- .../WorkspaceSchedulePage.tsx | 10 ++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx b/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx index 7b7d4d9f50..9f1b78ad98 100644 --- a/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx +++ b/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx @@ -1,4 +1,8 @@ -import { MockUserOwner, MockWorkspace } from "testHelpers/entities"; +import { + MockUserOwner, + MockWorkspace, + MockWorkspaceBuild, +} from "testHelpers/entities"; import { renderWithWorkspaceSettingsLayout } from "testHelpers/renderHelpers"; import { server } from "testHelpers/server"; import { screen } from "@testing-library/react"; @@ -301,6 +305,41 @@ describe("WorkspaceSchedulePage", () => { expect(dialog).toBeInTheDocument(); }); + it("doesn't show if workspace is stopped", async () => { + server.use( + http.get("/api/v2/users/:userId/workspace/:workspaceName", () => { + return HttpResponse.json({ + ...MockWorkspace, + latest_build: { ...MockWorkspaceBuild, status: "stopped" }, + }); + }), + ); + renderWithWorkspaceSettingsLayout(, { + route: `/@${MockUserOwner.username}/${MockWorkspace.name}/schedule`, + path: "/:username/:workspace/schedule", + extraRoutes: [ + { path: "/:username/:workspace", element:
Workspace
}, + ], + }); + const user = userEvent.setup(); + const autostopToggle = await screen.findByLabelText( + FormLanguage.stopSwitch, + ); + await user.click(autostopToggle); + const submitButton = await screen.findByRole("button", { + name: /save/i, + }); + await user.click(submitButton); + + const notification = await screen.findByText( + `Schedule for workspace "Test-Workspace" updated successfully.`, + ); + expect(notification).toBeInTheDocument(); + + const dialog = screen.queryByText("Restart workspace?"); + expect(dialog).not.toBeInTheDocument(); + }); + it("doesn't show if autostop is not changed", async () => { renderWithWorkspaceSettingsLayout(, { route: `/@${MockUserOwner.username}/${MockWorkspace.name}/schedule`, diff --git a/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx b/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx index c8d3e180d9..4b2e88f77e 100644 --- a/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx +++ b/site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx @@ -66,9 +66,8 @@ const WorkspaceSchedulePage: FC = () => { const isLoading = !template; const [isConfirmingApply, setIsConfirmingApply] = useState(false); - const { mutate: updateWorkspace } = useMutation({ - mutationFn: () => - API.startWorkspace(workspace.id, workspace.template_active_version_id), + const { mutate: restartWorkspace } = useMutation({ + mutationFn: () => API.restartWorkspace({ workspace }), }); return ( @@ -139,7 +138,8 @@ const WorkspaceSchedulePage: FC = () => { if ( data.autostopChanged && - getAutostop(workspace).autostopEnabled + getAutostop(workspace).autostopEnabled && + workspace.latest_build.status === "running" ) { setIsConfirmingApply(true); } @@ -155,7 +155,7 @@ const WorkspaceSchedulePage: FC = () => { cancelText="Apply later" hideCancel={false} onConfirm={() => { - updateWorkspace(); + restartWorkspace(); navigate(`/@${username}/${workspaceName}`); }} onClose={() => {