Skip to content

Commit d8a8070

Browse files
fix(site): enable submit when auto start and stop are both disabled (#12055)
1 parent 4b1bac3 commit d8a8070

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

site/src/components/Badges/Badges.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { PropsWithChildren, FC } from "react";
1+
import {
2+
type PropsWithChildren,
3+
type FC,
4+
forwardRef,
5+
HTMLAttributes,
6+
} from "react";
27
import Tooltip from "@mui/material/Tooltip";
38
import { type Interpolation, type Theme } from "@emotion/react";
49
import { Stack } from "components/Stack/Stack";
@@ -74,9 +79,14 @@ export const NotReachableBadge: FC = () => {
7479
);
7580
};
7681

77-
export const DisabledBadge: FC = () => {
82+
export const DisabledBadge: FC = forwardRef<
83+
HTMLSpanElement,
84+
HTMLAttributes<HTMLSpanElement>
85+
>((props, ref) => {
7886
return (
7987
<span
88+
{...props}
89+
ref={ref}
8090
css={[
8191
styles.badge,
8292
(theme) => ({
@@ -89,7 +99,7 @@ export const DisabledBadge: FC = () => {
8999
Disabled
90100
</span>
91101
);
92-
};
102+
});
93103

94104
export const EnterpriseBadge: FC = () => {
95105
return (

site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.stories.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@ export const Loading: Story = {
105105
isLoading: true,
106106
},
107107
};
108+
109+
export const AutoStopAndStartOff: Story = {
110+
args: {
111+
initialValues: {
112+
...defaultInitialValues,
113+
autostartEnabled: false,
114+
autostopEnabled: false,
115+
},
116+
},
117+
};

site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.test.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,37 @@ describe("templateInheritance", () => {
379379
expect(ttlInput).toBeDisabled();
380380
});
381381
});
382+
383+
test("form should be enabled when both auto stop and auto start features are disabled, given that the template permits these actions", async () => {
384+
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
385+
render(
386+
<WorkspaceScheduleForm
387+
{...defaultFormProps}
388+
initialValues={{
389+
...defaultFormProps.initialValues,
390+
autostopEnabled: false,
391+
autostartEnabled: false,
392+
}}
393+
/>,
394+
);
395+
396+
const submitButton = await screen.findByRole("button", { name: "Submit" });
397+
expect(submitButton).toBeEnabled();
398+
});
399+
400+
test("form should be disabled when both auto stop and auto start features are disabled at template level", async () => {
401+
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
402+
render(
403+
<WorkspaceScheduleForm
404+
{...defaultFormProps}
405+
allowTemplateAutoStart={false}
406+
allowTemplateAutoStop={false}
407+
initialValues={{
408+
...defaultFormProps.initialValues,
409+
}}
410+
/>,
411+
);
412+
413+
const submitButton = await screen.findByRole("button", { name: "Submit" });
414+
expect(submitButton).toBeDisabled();
415+
});

site/src/pages/WorkspaceSettingsPage/WorkspaceSchedulePage/WorkspaceScheduleForm.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,9 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
441441
<FormFooter
442442
onCancel={onCancel}
443443
isLoading={isLoading}
444-
submitDisabled={
445-
(!allowTemplateAutoStart && !allowTemplateAutoStop) ||
446-
(!form.values.autostartEnabled && !form.values.autostopEnabled)
447-
}
444+
// If both options, autostart and autostop, are disabled at the template
445+
// level, the form is disabled.
446+
submitDisabled={!allowTemplateAutoStart && !allowTemplateAutoStop}
448447
/>
449448
</HorizontalForm>
450449
);

0 commit comments

Comments
 (0)