Skip to content

Commit 5d40b1f

Browse files
authored
feat: Add switches for auto-start and auto-stop (#3358)
* Add elements * Add Loading story * Make form show empty values when manual * Make form depend on switches * Fix style * Format * Update unit tests * Tweaks * Update storybook * Move util files * Pull out more util functions * Pull out strings * Add border to section * Make min ttl 1 * Format * Fix import * Fix validation for falsey values * Format and fix tests * Put switches in form, persist form state * Fix bug * Remove helper text when disabled * Fix storybook * Revert "Remove helper text when disabled" This reverts commit a6271ca. * Format * Use nicer function to set values * Format
1 parent cee0d1f commit 5d40b1f

File tree

9 files changed

+423
-326
lines changed

9 files changed

+423
-326
lines changed

site/src/components/Section/Section.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const Section: SectionFC = ({
3030
}) => {
3131
const styles = useStyles({ layout })
3232
return (
33-
<div className={combineClasses([styles.root, className])}>
33+
<section className={combineClasses([styles.root, className])}>
3434
<div className={styles.inner}>
3535
{(title || description) && (
3636
<div className={styles.header}>
@@ -49,7 +49,7 @@ export const Section: SectionFC = ({
4949
{alert && <div className={styles.alert}>{alert}</div>}
5050
{children}
5151
</div>
52-
</div>
52+
</section>
5353
)
5454
}
5555

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

6768
[theme.breakpoints.down("sm")]: {
6869
padding: theme.spacing(4, 3, 4, 3),

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.stories.tsx

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import dayjs from "dayjs"
33
import advancedFormat from "dayjs/plugin/advancedFormat"
44
import timezone from "dayjs/plugin/timezone"
55
import utc from "dayjs/plugin/utc"
6+
import { defaultSchedule, emptySchedule } from "pages/WorkspaceSchedulePage/schedule"
7+
import { defaultTTL, emptyTTL } from "pages/WorkspaceSchedulePage/ttl"
68
import { makeMockApiError } from "testHelpers/entities"
7-
import {
8-
defaultWorkspaceSchedule,
9-
WorkspaceScheduleForm,
10-
WorkspaceScheduleFormProps,
11-
} from "./WorkspaceScheduleForm"
9+
import { WorkspaceScheduleForm, WorkspaceScheduleFormProps } from "./WorkspaceScheduleForm"
1210

1311
dayjs.extend(advancedFormat)
1412
dayjs.extend(utc)
@@ -29,51 +27,60 @@ export default {
2927

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

32-
export const WorkspaceWillNotShutDown = Template.bind({})
33-
WorkspaceWillNotShutDown.args = {
30+
const defaultInitialValues = {
31+
autoStartEnabled: true,
32+
...defaultSchedule(),
33+
autoStopEnabled: true,
34+
ttl: defaultTTL,
35+
}
36+
37+
export const AllDisabled = Template.bind({})
38+
AllDisabled.args = {
3439
initialValues: {
35-
...defaultWorkspaceSchedule(5),
36-
ttl: 0,
40+
autoStartEnabled: false,
41+
...emptySchedule,
42+
autoStopEnabled: false,
43+
ttl: emptyTTL,
3744
},
3845
}
3946

40-
export const WorkspaceWillShutdownInAnHour = Template.bind({})
41-
WorkspaceWillShutdownInAnHour.args = {
47+
export const AutoStart = Template.bind({})
48+
AutoStart.args = {
4249
initialValues: {
43-
...defaultWorkspaceSchedule(5),
44-
ttl: 1,
50+
autoStartEnabled: true,
51+
...defaultSchedule(),
52+
autoStopEnabled: false,
53+
ttl: emptyTTL,
4554
},
4655
}
4756

4857
export const WorkspaceWillShutdownInTwoHours = Template.bind({})
4958
WorkspaceWillShutdownInTwoHours.args = {
50-
initialValues: {
51-
...defaultWorkspaceSchedule(2),
52-
ttl: 2,
53-
},
59+
initialValues: { ...defaultInitialValues, ttl: 2 },
5460
}
5561

5662
export const WorkspaceWillShutdownInADay = Template.bind({})
5763
WorkspaceWillShutdownInADay.args = {
58-
initialValues: {
59-
...defaultWorkspaceSchedule(2),
60-
ttl: 24,
61-
},
64+
initialValues: { ...defaultInitialValues, ttl: 24 },
6265
}
6366

6467
export const WorkspaceWillShutdownInTwoDays = Template.bind({})
6568
WorkspaceWillShutdownInTwoDays.args = {
66-
initialValues: {
67-
...defaultWorkspaceSchedule(2),
68-
ttl: 48,
69-
},
69+
initialValues: { ...defaultInitialValues, ttl: 48 },
7070
}
7171

7272
export const WithError = Template.bind({})
7373
WithError.args = {
74+
initialValues: { ...defaultInitialValues, ttl: 100 },
7475
initialTouched: { ttl: true },
7576
submitScheduleError: makeMockApiError({
7677
message: "Something went wrong.",
7778
validations: [{ field: "ttl_ms", detail: "Invalid time until shutdown." }],
7879
}),
7980
}
81+
82+
export const Loading = Template.bind({})
83+
Loading.args = {
84+
initialValues: defaultInitialValues,
85+
isLoading: true,
86+
}

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,36 @@ import {
77
import { zones } from "./zones"
88

99
const valid: WorkspaceScheduleFormValues = {
10+
autoStartEnabled: true,
1011
sunday: false,
1112
monday: true,
1213
tuesday: true,
1314
wednesday: true,
1415
thursday: true,
1516
friday: true,
1617
saturday: false,
17-
1818
startTime: "09:30",
1919
timezone: "Canada/Eastern",
20+
21+
autoStopEnabled: true,
2022
ttl: 120,
2123
}
2224

2325
describe("validationSchema", () => {
24-
it("allows everything to be falsy", () => {
26+
it("allows everything to be falsy when switches are off", () => {
2527
const values: WorkspaceScheduleFormValues = {
28+
autoStartEnabled: false,
2629
sunday: false,
2730
monday: false,
2831
tuesday: false,
2932
wednesday: false,
3033
thursday: false,
3134
friday: false,
3235
saturday: false,
33-
3436
startTime: "",
3537
timezone: "",
38+
39+
autoStopEnabled: false,
3640
ttl: 0,
3741
}
3842
const validate = () => validationSchema.validateSync(values)
@@ -48,7 +52,7 @@ describe("validationSchema", () => {
4852
expect(validate).toThrow()
4953
})
5054

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

66-
it("disallows empty startTime when at least one day is set", () => {
70+
it("disallows empty startTime when auto-start is enabled", () => {
6771
const values: WorkspaceScheduleFormValues = {
6872
...valid,
6973
sunday: false,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy