Skip to content

fix(site): enable submit when auto start and stop are both disabled #12055

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
Feb 7, 2024
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
16 changes: 13 additions & 3 deletions site/src/components/Badges/Badges.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { PropsWithChildren, FC } from "react";
import {
type PropsWithChildren,
type FC,
forwardRef,
HTMLAttributes,
} from "react";
import Tooltip from "@mui/material/Tooltip";
import { type Interpolation, type Theme } from "@emotion/react";
import { Stack } from "components/Stack/Stack";
Expand Down Expand Up @@ -74,9 +79,14 @@ export const NotReachableBadge: FC = () => {
);
};

export const DisabledBadge: FC = () => {
export const DisabledBadge: FC = forwardRef<
HTMLSpanElement,
HTMLAttributes<HTMLSpanElement>
>((props, ref) => {
return (
<span
{...props}
ref={ref}
css={[
styles.badge,
(theme) => ({
Expand All @@ -89,7 +99,7 @@ export const DisabledBadge: FC = () => {
Disabled
</span>
);
};
});

export const EnterpriseBadge: FC = () => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,13 @@ export const Loading: Story = {
isLoading: true,
},
};

export const AutoStopAndStartOff: Story = {
args: {
initialValues: {
...defaultInitialValues,
autostartEnabled: false,
autostopEnabled: false,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,37 @@ describe("templateInheritance", () => {
expect(ttlInput).toBeDisabled();
});
});

test("form should be enabled when both auto stop and auto start features are disabled, given that the template permits these actions", async () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
render(
<WorkspaceScheduleForm
{...defaultFormProps}
initialValues={{
...defaultFormProps.initialValues,
autostopEnabled: false,
autostartEnabled: false,
}}
/>,
);

const submitButton = await screen.findByRole("button", { name: "Submit" });
expect(submitButton).toBeEnabled();
});

test("form should be disabled when both auto stop and auto start features are disabled at template level", async () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
render(
<WorkspaceScheduleForm
{...defaultFormProps}
allowTemplateAutoStart={false}
allowTemplateAutoStop={false}
initialValues={{
...defaultFormProps.initialValues,
}}
/>,
);

const submitButton = await screen.findByRole("button", { name: "Submit" });
expect(submitButton).toBeDisabled();
});
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,9 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
<FormFooter
onCancel={onCancel}
isLoading={isLoading}
submitDisabled={
(!allowTemplateAutoStart && !allowTemplateAutoStop) ||
(!form.values.autostartEnabled && !form.values.autostopEnabled)
}
// If both options, autostart and autostop, are disabled at the template
// level, the form is disabled.
submitDisabled={!allowTemplateAutoStart && !allowTemplateAutoStop}
/>
</HorizontalForm>
);
Expand Down