Skip to content

Commit 377f17c

Browse files
authored
fix: initialValues for ws schedule (#2213)
Summary: When a schedule is not set, we default to M-F, 5 hours ttl
1 parent d04d527 commit 377f17c

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,28 @@ export const validationSchema = Yup.object({
151151
.max(24 * 7 /* 7 days */),
152152
})
153153

154+
export const defaultWorkspaceScheduleTTL = 8
155+
156+
export const defaultWorkspaceSchedule = (
157+
ttl = defaultWorkspaceScheduleTTL,
158+
timezone = dayjs.tz.guess(),
159+
): WorkspaceScheduleFormValues => ({
160+
sunday: false,
161+
monday: true,
162+
tuesday: true,
163+
wednesday: true,
164+
thursday: true,
165+
friday: true,
166+
saturday: false,
167+
168+
startTime: "09:30",
169+
timezone,
170+
ttl,
171+
})
172+
154173
export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
155174
fieldErrors,
156-
initialValues = {
157-
sunday: false,
158-
monday: true,
159-
tuesday: true,
160-
wednesday: true,
161-
thursday: true,
162-
friday: true,
163-
saturday: false,
164-
165-
startTime: "09:30",
166-
timezone: "",
167-
ttl: 5,
168-
},
175+
initialValues = defaultWorkspaceSchedule(),
169176
isLoading,
170177
onCancel,
171178
onSubmit,

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ describe("WorkspaceSchedulePage", () => {
162162
},
163163
{
164164
sunday: false,
165-
monday: false,
166-
tuesday: false,
167-
wednesday: false,
168-
thursday: false,
169-
friday: false,
165+
monday: true,
166+
tuesday: true,
167+
wednesday: true,
168+
thursday: true,
169+
friday: true,
170170
saturday: false,
171-
startTime: "",
171+
startTime: "09:30",
172172
timezone: "",
173-
ttl: 0,
173+
ttl: 8,
174174
},
175175
],
176176

@@ -183,13 +183,13 @@ describe("WorkspaceSchedulePage", () => {
183183
},
184184
{
185185
sunday: false,
186-
monday: false,
187-
tuesday: false,
188-
wednesday: false,
189-
thursday: false,
190-
friday: false,
186+
monday: true,
187+
tuesday: true,
188+
wednesday: true,
189+
thursday: true,
190+
friday: true,
191191
saturday: false,
192-
startTime: "",
192+
startTime: "09:30",
193193
timezone: "",
194194
ttl: 2,
195195
},

site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as TypesGen from "../../api/typesGenerated"
99
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
1010
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
1111
import {
12+
defaultWorkspaceSchedule,
13+
defaultWorkspaceScheduleTTL,
1214
WorkspaceScheduleForm,
1315
WorkspaceScheduleFormValues,
1416
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
@@ -97,21 +99,10 @@ export const workspaceToInitialValues = (
9799
defaultTimeZone = "",
98100
): WorkspaceScheduleFormValues => {
99101
const schedule = workspace.autostart_schedule
100-
const ttlHours = workspace.ttl_ms ? Math.round(workspace.ttl_ms / (1000 * 60 * 60)) : 0
102+
const ttlHours = workspace.ttl_ms ? Math.round(workspace.ttl_ms / (1000 * 60 * 60)) : defaultWorkspaceScheduleTTL
101103

102104
if (!schedule) {
103-
return {
104-
sunday: false,
105-
monday: false,
106-
tuesday: false,
107-
wednesday: false,
108-
thursday: false,
109-
friday: false,
110-
saturday: false,
111-
startTime: "",
112-
timezone: defaultTimeZone,
113-
ttl: ttlHours,
114-
}
105+
return defaultWorkspaceSchedule(ttlHours, defaultTimeZone)
115106
}
116107

117108
const timezone = extractTimezone(schedule, defaultTimeZone)

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