Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d40b1f

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 commita6271ca.* Format* Use nicer function to set values* Format
1 parentcee0d1f commit5d40b1f

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
conststyles=useStyles({ layout})
3232
return(
33-
<divclassName={combineClasses([styles.root,className])}>
33+
<sectionclassName={combineClasses([styles.root,className])}>
3434
<divclassName={styles.inner}>
3535
{(title||description)&&(
3636
<divclassName={styles.header}>
@@ -49,7 +49,7 @@ export const Section: SectionFC = ({
4949
{alert&&<divclassName={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
importadvancedFormatfrom"dayjs/plugin/advancedFormat"
44
importtimezonefrom"dayjs/plugin/timezone"
55
importutcfrom"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
constTemplate:Story<WorkspaceScheduleFormProps>=(args)=><WorkspaceScheduleForm{...args}/>
3129

32-
exportconstWorkspaceWillNotShutDown=Template.bind({})
33-
WorkspaceWillNotShutDown.args={
30+
constdefaultInitialValues={
31+
autoStartEnabled:true,
32+
...defaultSchedule(),
33+
autoStopEnabled:true,
34+
ttl:defaultTTL,
35+
}
36+
37+
exportconstAllDisabled=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-
exportconstWorkspaceWillShutdownInAnHour=Template.bind({})
41-
WorkspaceWillShutdownInAnHour.args={
47+
exportconstAutoStart=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
exportconstWorkspaceWillShutdownInTwoHours=Template.bind({})
4958
WorkspaceWillShutdownInTwoHours.args={
50-
initialValues:{
51-
...defaultWorkspaceSchedule(2),
52-
ttl:2,
53-
},
59+
initialValues:{ ...defaultInitialValues,ttl:2},
5460
}
5561

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

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

7272
exportconstWithError=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+
exportconstLoading=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
constvalid: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
constvalues: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
constvalidate=()=>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 whenstartTime isset",()=>{
55+
it("disallows all days-of-week to be false whenauto-start isenabled",()=>{
5256
constvalues: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 whenat least one dayisset",()=>{
70+
it("disallows empty startTime whenauto-startisenabled",()=>{
6771
constvalues:WorkspaceScheduleFormValues={
6872
...valid,
6973
sunday:false,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp