Skip to content

fix(site): disable autostart and autostop according to template settings #11809

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 5 commits into from
Jan 26, 2024
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
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
checking form values again; wrote tests
  • Loading branch information
Kira-Pilot committed Jan 25, 2024
commit 735fca127e7de4d210bc363e685de91dcb220a96
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,47 @@ describe("templateInheritance", () => {
const autoStopToggle = await screen.findByLabelText("Enable Autostop");
expect(autoStopToggle).toBeDisabled();

const ttlInput = await screen.findByLabelText(
"Time until shutdown (hours)",
);
expect(ttlInput).toBeDisabled();
});
it("disables secondary autostart fields if main feature switch is toggled off", async () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
render(
<WorkspaceScheduleForm
{...defaultFormProps}
initialValues={{
...defaultFormProps.initialValues,
autostartEnabled: false,
}}
/>,
);

const startTimeInput = await screen.findByLabelText("Start time");
expect(startTimeInput).toBeDisabled();

const timezoneInput = await screen.findByLabelText("Timezone");
// MUI's input is wrapped in a div so we look at the aria-attribute instead
expect(timezoneInput).toHaveAttribute("aria-disabled");

autoStartDays.forEach(async (label) => {
const checkbox = await screen.findByLabelText(label);
expect(checkbox).toBeDisabled();
});
});
it("disables secondary autostop fields if main feature switch is toggled off", async () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
render(
<WorkspaceScheduleForm
{...defaultFormProps}
initialValues={{
...defaultFormProps.initialValues,
autostopEnabled: false,
}}
/>,
);

const ttlInput = await screen.findByLabelText(
"Time until shutdown (hours)",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,26 @@ export const WorkspaceScheduleForm: FC<
<Stack direction="row">
<TextField
{...formHelpers("startTime")}
disabled={isLoading || !allowTemplateAutoStart}
// disabled if template does not allow autostart
// or if primary feature is toggled off via the switch above
disabled={
isLoading ||
!allowTemplateAutoStart ||
!form.values.autostartEnabled
}
label={Language.startTimeLabel}
type="time"
fullWidth
/>
<TextField
{...formHelpers("timezone")}
disabled={isLoading || !allowTemplateAutoStart}
// disabled if template does not allow autostart
// or if primary feature is toggled off via the switch above
disabled={
isLoading ||
!allowTemplateAutoStart ||
!form.values.autostartEnabled
}
label={Language.timezoneLabel}
select
fullWidth
Expand Down Expand Up @@ -354,11 +366,13 @@ export const WorkspaceScheduleForm: FC<
<Checkbox
checked={checkbox.value}
// template admins can disable the autostart feature in general,
// or they can disallow autostart on specific days of the week
// or they can disallow autostart on specific days of the week.
// also disabled if primary feature switch (above) is toggled off
disabled={
isLoading ||
!allowTemplateAutoStart ||
!allowedTemplateAutoStartDays.includes(checkbox.name)
!allowedTemplateAutoStartDays.includes(checkbox.name) ||
!form.values.autostartEnabled
}
onChange={form.handleChange}
name={checkbox.name}
Expand Down Expand Up @@ -413,7 +427,13 @@ export const WorkspaceScheduleForm: FC<
helperText: ttlShutdownAt(form.values.ttl),
backendFieldName: "ttl_ms",
})}
disabled={isLoading || !allowTemplateAutoStop}
// disabled if autostop disabled at template level or
// if autostop feature is toggled off via the switch above
disabled={
isLoading ||
!allowTemplateAutoStop ||
!form.values.autostopEnabled
}
inputProps={{ min: 0, step: "any" }}
label={Language.ttlLabel}
type="number"
Expand Down