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 */),
|
.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> = ({
|
export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
|
||||||
fieldErrors,
|
fieldErrors,
|
||||||
initialValues = {
|
initialValues = defaultWorkspaceSchedule(),
|
||||||
sunday: false,
|
|
||||||
monday: true,
|
|
||||||
tuesday: true,
|
|
||||||
wednesday: true,
|
|
||||||
thursday: true,
|
|
||||||
friday: true,
|
|
||||||
saturday: false,
|
|
||||||
|
|
||||||
startTime: "09:30",
|
|
||||||
timezone: "",
|
|
||||||
ttl: 5,
|
|
||||||
},
|
|
||||||
isLoading,
|
isLoading,
|
||||||
onCancel,
|
onCancel,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
@ -162,15 +162,15 @@ describe("WorkspaceSchedulePage", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
sunday: false,
|
sunday: false,
|
||||||
monday: false,
|
monday: true,
|
||||||
tuesday: false,
|
tuesday: true,
|
||||||
wednesday: false,
|
wednesday: true,
|
||||||
thursday: false,
|
thursday: true,
|
||||||
friday: false,
|
friday: true,
|
||||||
saturday: false,
|
saturday: false,
|
||||||
startTime: "",
|
startTime: "09:30",
|
||||||
timezone: "",
|
timezone: "",
|
||||||
ttl: 0,
|
ttl: 8,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -183,13 +183,13 @@ describe("WorkspaceSchedulePage", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
sunday: false,
|
sunday: false,
|
||||||
monday: false,
|
monday: true,
|
||||||
tuesday: false,
|
tuesday: true,
|
||||||
wednesday: false,
|
wednesday: true,
|
||||||
thursday: false,
|
thursday: true,
|
||||||
friday: false,
|
friday: true,
|
||||||
saturday: false,
|
saturday: false,
|
||||||
startTime: "",
|
startTime: "09:30",
|
||||||
timezone: "",
|
timezone: "",
|
||||||
ttl: 2,
|
ttl: 2,
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,8 @@ import * as TypesGen from "../../api/typesGenerated"
|
|||||||
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
|
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary"
|
||||||
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
|
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader"
|
||||||
import {
|
import {
|
||||||
|
defaultWorkspaceSchedule,
|
||||||
|
defaultWorkspaceScheduleTTL,
|
||||||
WorkspaceScheduleForm,
|
WorkspaceScheduleForm,
|
||||||
WorkspaceScheduleFormValues,
|
WorkspaceScheduleFormValues,
|
||||||
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
|
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
|
||||||
@ -97,21 +99,10 @@ export const workspaceToInitialValues = (
|
|||||||
defaultTimeZone = "",
|
defaultTimeZone = "",
|
||||||
): WorkspaceScheduleFormValues => {
|
): WorkspaceScheduleFormValues => {
|
||||||
const schedule = workspace.autostart_schedule
|
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) {
|
if (!schedule) {
|
||||||
return {
|
return defaultWorkspaceSchedule(ttlHours, defaultTimeZone)
|
||||||
sunday: false,
|
|
||||||
monday: false,
|
|
||||||
tuesday: false,
|
|
||||||
wednesday: false,
|
|
||||||
thursday: false,
|
|
||||||
friday: false,
|
|
||||||
saturday: false,
|
|
||||||
startTime: "",
|
|
||||||
timezone: defaultTimeZone,
|
|
||||||
ttl: ttlHours,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const timezone = extractTimezone(schedule, defaultTimeZone)
|
const timezone = extractTimezone(schedule, defaultTimeZone)
|
||||||
|
Reference in New Issue
Block a user