Skip to content

feat: Add switches for auto-start and auto-stop #3358

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 26 commits into from
Aug 10, 2022
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
5 changes: 3 additions & 2 deletions site/src/components/Section/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Section: SectionFC = ({
}) => {
const styles = useStyles({ layout })
return (
<div className={combineClasses([styles.root, className])}>
<section className={combineClasses([styles.root, className])}>
<div className={styles.inner}>
{(title || description) && (
<div className={styles.header}>
Expand All @@ -49,7 +49,7 @@ export const Section: SectionFC = ({
{alert && <div className={styles.alert}>{alert}</div>}
{children}
</div>
</div>
</section>
)
}

Expand All @@ -63,6 +63,7 @@ const useStyles = makeStyles((theme) => ({
marginBottom: theme.spacing(1),
padding: theme.spacing(6),
borderRadius: theme.shape.borderRadius,
border: `1px solid ${theme.palette.divider}`,

[theme.breakpoints.down("sm")]: {
padding: theme.spacing(4, 3, 4, 3),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import dayjs from "dayjs"
import advancedFormat from "dayjs/plugin/advancedFormat"
import timezone from "dayjs/plugin/timezone"
import utc from "dayjs/plugin/utc"
import { defaultSchedule, emptySchedule } from "pages/WorkspaceSchedulePage/schedule"
import { defaultTTL, emptyTTL } from "pages/WorkspaceSchedulePage/ttl"
import { makeMockApiError } from "testHelpers/entities"
import {
defaultWorkspaceSchedule,
WorkspaceScheduleForm,
WorkspaceScheduleFormProps,
} from "./WorkspaceScheduleForm"
import { WorkspaceScheduleForm, WorkspaceScheduleFormProps } from "./WorkspaceScheduleForm"

dayjs.extend(advancedFormat)
dayjs.extend(utc)
Expand All @@ -29,51 +27,60 @@ export default {

const Template: Story<WorkspaceScheduleFormProps> = (args) => <WorkspaceScheduleForm {...args} />

export const WorkspaceWillNotShutDown = Template.bind({})
WorkspaceWillNotShutDown.args = {
const defaultInitialValues = {
autoStartEnabled: true,
...defaultSchedule(),
autoStopEnabled: true,
ttl: defaultTTL,
}

export const AllDisabled = Template.bind({})
AllDisabled.args = {
initialValues: {
...defaultWorkspaceSchedule(5),
ttl: 0,
autoStartEnabled: false,
...emptySchedule,
autoStopEnabled: false,
ttl: emptyTTL,
},
}

export const WorkspaceWillShutdownInAnHour = Template.bind({})
WorkspaceWillShutdownInAnHour.args = {
export const AutoStart = Template.bind({})
AutoStart.args = {
initialValues: {
...defaultWorkspaceSchedule(5),
ttl: 1,
autoStartEnabled: true,
...defaultSchedule(),
autoStopEnabled: false,
ttl: emptyTTL,
},
}

export const WorkspaceWillShutdownInTwoHours = Template.bind({})
WorkspaceWillShutdownInTwoHours.args = {
initialValues: {
...defaultWorkspaceSchedule(2),
ttl: 2,
},
initialValues: { ...defaultInitialValues, ttl: 2 },
}

export const WorkspaceWillShutdownInADay = Template.bind({})
WorkspaceWillShutdownInADay.args = {
initialValues: {
...defaultWorkspaceSchedule(2),
ttl: 24,
},
initialValues: { ...defaultInitialValues, ttl: 24 },
}

export const WorkspaceWillShutdownInTwoDays = Template.bind({})
WorkspaceWillShutdownInTwoDays.args = {
initialValues: {
...defaultWorkspaceSchedule(2),
ttl: 48,
},
initialValues: { ...defaultInitialValues, ttl: 48 },
}

export const WithError = Template.bind({})
WithError.args = {
initialValues: { ...defaultInitialValues, ttl: 100 },
initialTouched: { ttl: true },
submitScheduleError: makeMockApiError({
message: "Something went wrong.",
validations: [{ field: "ttl_ms", detail: "Invalid time until shutdown." }],
}),
}

export const Loading = Template.bind({})
Loading.args = {
initialValues: defaultInitialValues,
isLoading: true,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ import {
import { zones } from "./zones"

const valid: WorkspaceScheduleFormValues = {
autoStartEnabled: true,
sunday: false,
monday: true,
tuesday: true,
wednesday: true,
thursday: true,
friday: true,
saturday: false,

startTime: "09:30",
timezone: "Canada/Eastern",

autoStopEnabled: true,
ttl: 120,
}

describe("validationSchema", () => {
it("allows everything to be falsy", () => {
it("allows everything to be falsy when switches are off", () => {
const values: WorkspaceScheduleFormValues = {
autoStartEnabled: false,
sunday: false,
monday: false,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
saturday: false,

startTime: "",
timezone: "",

autoStopEnabled: false,
ttl: 0,
}
const validate = () => validationSchema.validateSync(values)
Expand All @@ -48,7 +52,7 @@ describe("validationSchema", () => {
expect(validate).toThrow()
})

it("disallows all days-of-week to be false when startTime is set", () => {
it("disallows all days-of-week to be false when auto-start is enabled", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
sunday: false,
Expand All @@ -63,7 +67,7 @@ describe("validationSchema", () => {
expect(validate).toThrowError(Language.errorNoDayOfWeek)
})

it("disallows empty startTime when at least one day is set", () => {
it("disallows empty startTime when auto-start is enabled", () => {
const values: WorkspaceScheduleFormValues = {
...valid,
sunday: false,
Expand Down
Loading