diff --git a/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx b/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx index f0706ccc4a..5776fa1d0d 100644 --- a/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx +++ b/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx @@ -1,6 +1,3 @@ -import type { Theme } from "@emotion/react"; -import MenuItem from "@mui/material/MenuItem"; -import TextField from "@mui/material/TextField"; import { useFormik } from "formik"; import upperFirst from "lodash/upperFirst"; import type { FC } from "react"; @@ -17,7 +14,17 @@ import { FormSection, HorizontalForm, } from "#/components/Form/Form"; +import { FormField } from "#/components/FormField/FormField"; +import { Label } from "#/components/Label/Label"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "#/components/Select/Select"; import { Spinner } from "#/components/Spinner/Spinner"; +import { cn } from "#/utils/cn"; import { getFormHelpers, nameValidator, @@ -60,6 +67,12 @@ export const WorkspaceSettingsForm: FC = ({ form, error, ); + const automaticUpdatesField = getFieldHelpers("automatic_updates", { + helperText: workspace.template_require_active_version + ? "The template for this workspace requires automatic updates." + : undefined, + }); + const automaticUpdatesHelperId = `${automaticUpdatesField.id}-helper`; return ( @@ -68,20 +81,22 @@ export const WorkspaceSettingsForm: FC = ({ description="Update the name of your workspace." > - + Depending on the template, renaming your workspace may be + destructive + + ) + : "Renaming your workspace can be destructive and is disabled by the template.", + })} + label="Name" disabled={!workspace.allow_renames || form.isSubmitting} onChange={onChangeTrimmed(form)} autoFocus - fullWidth - label="Name" - css={workspace.allow_renames && styles.nameWarning} - helperText={ - workspace.allow_renames - ? form.values.name !== form.initialValues.name && - "Depending on the template, renaming your workspace may be destructive" - : "Renaming your workspace can be destructive and is disabled by the template." - } + className="w-full" /> @@ -90,30 +105,58 @@ export const WorkspaceSettingsForm: FC = ({ description="Configure your workspace to automatically update when started." > - - {AutomaticUpdateses.map((value) => ( - - {upperFirst(value)} - - ))} - +
+ + + {automaticUpdatesField.helperText && ( + + {automaticUpdatesField.helperText} + + )} +
{formEnabled && ( @@ -131,11 +174,3 @@ export const WorkspaceSettingsForm: FC = ({
); }; - -const styles = { - nameWarning: (theme: Theme) => ({ - "& .MuiFormHelperText-root": { - color: theme.palette.warning.light, - }, - }), -}; diff --git a/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsPageView.stories.tsx b/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsPageView.stories.tsx index 188afc39d8..7c2550c6e3 100644 --- a/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsPageView.stories.tsx +++ b/site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsPageView.stories.tsx @@ -1,5 +1,6 @@ import type { Meta, StoryObj } from "@storybook/react-vite"; import { action } from "storybook/actions"; +import { expect, fn, screen, userEvent, waitFor, within } from "storybook/test"; import { MockWorkspace } from "#/testHelpers/entities"; import { WorkspaceSettingsPageView } from "./WorkspaceSettingsPageView"; @@ -10,6 +11,7 @@ const meta: Meta = { error: undefined, workspace: MockWorkspace, onCancel: action("onCancel"), + onSubmit: fn(), }, }; @@ -23,3 +25,28 @@ export const RenamesDisabled: Story = { workspace: { ...MockWorkspace, allow_renames: false }, }, }; + +export const UpdateAutomaticUpdatesPolicy: Story = { + args: { + workspace: { ...MockWorkspace, automatic_updates: "never" }, + onSubmit: fn(), + }, + play: async ({ canvasElement, args }) => { + const canvas = within(canvasElement); + + await userEvent.click( + canvas.getByRole("combobox", { name: /update policy/i }), + ); + await userEvent.click( + await screen.findByRole("option", { name: /always/i }), + ); + + await userEvent.click(canvas.getByRole("button", { name: /save/i })); + + await waitFor(() => + expect(args.onSubmit).toHaveBeenCalledWith( + expect.objectContaining({ automatic_updates: "always" }), + ), + ); + }, +};