- Notifications
You must be signed in to change notification settings - Fork928
fix: FE parsing of schedule with day strings#2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { useMachine } from "@xstate/react" | ||
import * as cronParser from "cron-parser" | ||
import dayjs from "dayjs" | ||
import timezone from "dayjs/plugin/timezone" | ||
import utc from "dayjs/plugin/utc" | ||
@@ -12,7 +13,7 @@ import { | ||
WorkspaceScheduleFormValues, | ||
} from "../../components/WorkspaceScheduleForm/WorkspaceScheduleForm" | ||
import { firstOrItem } from "../../util/array" | ||
import { extractTimezone, stripTimezone } from "../../util/schedule" | ||
import { workspaceSchedule } from "../../xServices/workspaceSchedule/workspaceScheduleXService" | ||
// REMARK: timezone plugin depends on UTC | ||
@@ -93,7 +94,7 @@ export const formValuesToTTLRequest = (values: WorkspaceScheduleFormValues): Typ | ||
export const workspaceToInitialValues = (workspace: TypesGen.Workspace): WorkspaceScheduleFormValues => { | ||
const schedule = workspace.autostart_schedule | ||
constttlHours = workspace.ttl_ms ?Math.round(workspace.ttl_ms / (1000 * 60 * 60)) : 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. REVIEW: This is technically a separate change/uncaught previously. Basically if you set your ttl via CLI to something like 1.5 hours, we'd show the 1.5 initially in the form, but you were forced to change it to an integer. This feels safer until we have a form that allows minutes in addition to hours. | ||
if (!schedule) { | ||
return { | ||
@@ -106,22 +107,22 @@ export const workspaceToInitialValues = (workspace: TypesGen.Workspace): Workspa | ||
saturday: false, | ||
startTime: "", | ||
timezone: "", | ||
ttl: ttlHours, | ||
} | ||
} | ||
const timezone = extractTimezone(schedule, dayjs.tz.guess()) | ||
const expression = cronParser.parseExpression(stripTimezone(schedule)) | ||
const HH = expression.fields.hour.join("").padStart(2, "0") | ||
const mm = expression.fields.minute.join("").padStart(2, "0") | ||
const weeklyFlags = [false, false, false, false, false, false, false] | ||
for (const day of expression.fields.dayOfWeek) { | ||
weeklyFlags[day % 7] = true | ||
} | ||
return { | ||
sunday: weeklyFlags[0], | ||
@@ -131,9 +132,9 @@ export const workspaceToInitialValues = (workspace: TypesGen.Workspace): Workspa | ||
thursday: weeklyFlags[4], | ||
friday: weeklyFlags[5], | ||
saturday: weeklyFlags[6], | ||
startTime: `${HH}:${mm}`, | ||
timezone, | ||
ttl: ttlHours, | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -30,72 +30,3 @@ export const extractTimezone = (raw: string, defaultTZ = DEFAULT_TIMEZONE): stri | ||
return defaultTZ | ||
} | ||
} | ||