Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ describe("templateInheritance", () => {
};
render(<WorkspaceScheduleForm {...props} />);

const autoStartToggle = await screen.findByLabelText("Enable Autostart");
const autoStartToggle = await screen.findByLabelText("Enable Autostart", {
exact: false,
});
expect(autoStartToggle).toBeDisabled();

const startTimeInput = await screen.findByLabelText("Start time");
Expand Down Expand Up @@ -313,7 +315,9 @@ describe("templateInheritance", () => {

render(<WorkspaceScheduleForm {...props} />);

const autoStartToggle = await screen.findByLabelText("Enable Autostart");
const autoStartToggle = await screen.findByLabelText("Enable Autostart", {
exact: false,
});
expect(autoStartToggle).toBeEnabled();

const startTimeInput = await screen.findByLabelText("Start time");
Expand Down Expand Up @@ -346,7 +350,9 @@ describe("templateInheritance", () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValue(MockTemplate);
render(<WorkspaceScheduleForm {...props} />);

const autoStopToggle = await screen.findByLabelText("Enable Autostop");
const autoStopToggle = await screen.findByLabelText("Enable Autostop", {
exact: false,
});
expect(autoStopToggle).toBeDisabled();

const ttlInput = await screen.findByLabelText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import FormLabel from "@mui/material/FormLabel";
import MenuItem from "@mui/material/MenuItem";
import Switch from "@mui/material/Switch";
import TextField from "@mui/material/TextField";
import Tooltip from "@mui/material/Tooltip";
import { formatDuration, intervalToDuration } from "date-fns";
import dayjs from "dayjs";
import advancedFormat from "dayjs/plugin/advancedFormat";
Expand All @@ -19,14 +18,17 @@ import { type FormikTouched, useFormik } from "formik";
import type { ChangeEvent, FC } from "react";
import * as Yup from "yup";
import type { Template } from "api/typesGenerated";
import { DisabledBadge } from "components/Badges/Badges";
import {
HorizontalForm,
FormFooter,
FormSection,
FormFields,
} from "components/Form/Form";
import { Stack } from "components/Stack/Stack";
import {
StackLabel,
StackLabelHelperText,
} from "components/StackLabel/StackLabel";
import {
defaultSchedule,
emptySchedule,
Expand Down Expand Up @@ -180,6 +182,10 @@ export const validationSchema = Yup.object({
}),
});

// This form utilizes complex, visually-intensive fields. Increasing the space
// between these fields enhances readability and cleanliness.
const FIELDS_SPACING = 4;

export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
error,
initialValues,
Expand Down Expand Up @@ -275,31 +281,30 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
<HorizontalForm onSubmit={form.handleSubmit}>
<FormSection
title="Autostart"
description={
<>
<div css={{ marginBottom: 16 }}>
Select the time and days of week on which you want the workspace
starting automatically.
</div>
{!template.allow_user_autostart && (
<Tooltip title="This option can be enabled in the template settings">
<DisabledBadge />
</Tooltip>
)}
</>
}
description="Select the time and days of week on which you want the workspace starting automatically."
>
<FormFields>
<FormFields spacing={FIELDS_SPACING}>
<FormControlLabel
control={
<Switch
disabled={!template.allow_user_autostart}
name="autostartEnabled"
checked={form.values.autostartEnabled}
onChange={handleToggleAutostart}
size="small"
/>
}
label={Language.startSwitch}
label={
<StackLabel>
{Language.startSwitch}
{!template.allow_user_autostart && (
<StackLabelHelperText>
The template for this workspace does not allow modification
of autostart.
</StackLabelHelperText>
)}
</StackLabel>
}
/>
<Stack direction="row">
<TextField
Expand Down Expand Up @@ -387,34 +392,37 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
title="Autostop"
description={
<>
<div css={{ marginBottom: 16 }}>
Set how many hours should elapse after the workspace started
before the workspace automatically shuts down. This will be
extended by{" "}
{dayjs
.duration({ milliseconds: template.activity_bump_ms })
.humanize()}{" "}
after last activity in the workspace was detected.
</div>
{!template.allow_user_autostop && (
<Tooltip title="This option can be enabled in the template settings">
<DisabledBadge />
</Tooltip>
)}
Set how many hours should elapse after the workspace started before
the workspace automatically shuts down. This will be extended by{" "}
{dayjs
.duration({ milliseconds: template.activity_bump_ms })
.humanize()}{" "}
after last activity in the workspace was detected.
</>
}
>
<FormFields>
<FormFields spacing={FIELDS_SPACING}>
<FormControlLabel
control={
<Switch
size="small"
name="autostopEnabled"
checked={form.values.autostopEnabled}
onChange={handleToggleAutostop}
disabled={!template.allow_user_autostop}
/>
}
label={Language.stopSwitch}
label={
<StackLabel>
{Language.stopSwitch}
{!template.allow_user_autostop && (
<StackLabelHelperText>
The template for this workspace does not allow modification
of autostop.
</StackLabelHelperText>
)}
</StackLabel>
}
/>
<TextField
{...formHelpers("ttl", {
Expand Down