mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
fix: initialValues for ws schedule (#2213)
Summary: When a schedule is not set, we default to M-F, 5 hours ttl
This commit is contained in:
@ -151,21 +151,28 @@ export const validationSchema = Yup.object({
|
||||
.max(24 * 7 /* 7 days */),
|
||||
})
|
||||
|
||||
export const defaultWorkspaceScheduleTTL = 8
|
||||
|
||||
export const defaultWorkspaceSchedule = (
|
||||
ttl = defaultWorkspaceScheduleTTL,
|
||||
timezone = dayjs.tz.guess(),
|
||||
): WorkspaceScheduleFormValues => ({
|
||||
sunday: false,
|
||||
monday: true,
|
||||
tuesday: true,
|
||||
wednesday: true,
|
||||
thursday: true,
|
||||
friday: true,
|
||||
saturday: false,
|
||||
|
||||
startTime: "09:30",
|
||||
timezone,
|
||||
ttl,
|
||||
})
|
||||
|
||||
export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
|
||||
fieldErrors,
|
||||
initialValues = {
|
||||
sunday: false,
|
||||
monday: true,
|
||||
tuesday: true,
|
||||
wednesday: true,
|
||||
thursday: true,
|
||||
friday: true,
|
||||
saturday: false,
|
||||
|
||||
startTime: "09:30",
|
||||
timezone: "",
|
||||
ttl: 5,
|
||||
},
|
||||
initialValues = defaultWorkspaceSchedule(),
|
||||
isLoading,
|
||||
onCancel,
|
||||
onSubmit,
|
||||
|
@ -162,15 +162,15 @@ describe("WorkspaceSchedulePage", () => {
|
||||
},
|
||||
{
|
||||
sunday: false,
|
||||
monday: false,
|
||||
tuesday: false,
|
||||
wednesday: false,
|
||||
thursday: false,
|
||||
friday: false,
|
||||
monday: true,
|
||||
tuesday: true,
|
||||
wednesday: true,
|
||||
thursday: true,
|
||||
friday: true,
|
||||
saturday: false,
|
||||
startTime: "",
|
||||
startTime: "09:30",
|
||||
timezone: "",
|
||||
ttl: 0,
|
||||
ttl: 8,
|
||||
},
|
||||
],
|
||||
|
||||
@ -183,13 +183,13 @@ describe("WorkspaceSchedulePage", () => {
|
||||
},
|
||||
{
|
||||
sunday: false,
|
||||
monday: false,
|
||||
tuesday: false,
|
||||
wednesday: false,
|
||||
thursday: false,
|
||||
friday: false,
|
||||
monday: true,
|
||||
tuesday: true,
|
||||
wednesday: true,
|
||||
thursday: true,
|
||||
friday: true,
|
||||
saturday: false,
|
||||
startTime: "",
|
||||
startTime: "09:30",
|
||||
timezone: "",
|
||||
ttl: 2,
|
||||
},
|
||||
|
@ -9,6 +9,8 @@ import * as TypesGen from "../../api/typesGenerated"
|
||||
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
|
||||
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
|
||||
import {
|
||||
defaultWorkspaceSchedule,
|
||||
defaultWorkspaceScheduleTTL,
|
||||
WorkspaceScheduleForm,
|
||||
WorkspaceScheduleFormValues,
|
||||
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
|
||||
@ -97,21 +99,10 @@ export const workspaceToInitialValues = (
|
||||
defaultTimeZone = "",
|
||||
): WorkspaceScheduleFormValues => {
|
||||
const schedule = workspace.autostart_schedule
|
||||
const ttlHours = workspace.ttl_ms ? Math.round(workspace.ttl_ms / (1000 * 60 * 60)) : 0
|
||||
const ttlHours = workspace.ttl_ms ? Math.round(workspace.ttl_ms / (1000 * 60 * 60)) : defaultWorkspaceScheduleTTL
|
||||
|
||||
if (!schedule) {
|
||||
return {
|
||||
sunday: false,
|
||||
monday: false,
|
||||
tuesday: false,
|
||||
wednesday: false,
|
||||
thursday: false,
|
||||
friday: false,
|
||||
saturday: false,
|
||||
startTime: "",
|
||||
timezone: defaultTimeZone,
|
||||
ttl: ttlHours,
|
||||
}
|
||||
return defaultWorkspaceSchedule(ttlHours, defaultTimeZone)
|
||||
}
|
||||
|
||||
const timezone = extractTimezone(schedule, defaultTimeZone)
|
||||
|
Reference in New Issue
Block a user