- Notifications
You must be signed in to change notification settings - Fork928
Closed
Description
User Story 👥
A real user story (thanks@ammario 🎉):
Allow setting "Days of Week" when "Start time" is unset
This one confused me. We shouldn't assume that users will fill out the form in top to bottom order.
Implementation Notes
Under the hood, the form has logic like:
disabled={form.isSubmitting||isLoading||!form.values.startTime} |
At the parent level, whereby the form values are transformed into an API request, nothing should change:
exportconstformValuesToAutoStartRequest=( | |
values:WorkspaceScheduleFormValues, | |
):TypesGen.UpdateWorkspaceAutostartRequest=>{ | |
if(!values.startTime){ | |
return{ | |
schedule:"", | |
} | |
} | |
const[HH,mm]=values.startTime.split(":") | |
// Note: Space after CRON_TZ if timezone is defined | |
constpreparedTZ=values.timezone ?`CRON_TZ=${values.timezone} ` :"" | |
constmakeCronString=(dow:string)=>`${preparedTZ}${mm}${HH} * *${dow}` | |
constdays=[ | |
values.sunday, | |
values.monday, | |
values.tuesday, | |
values.wednesday, | |
values.thursday, | |
values.friday, | |
values.saturday, | |
] | |
constisEveryDay=days.every((day)=>day) | |
constisMonThroughFri= | |
!values.sunday&& | |
values.monday&& | |
values.tuesday&& | |
values.wednesday&& | |
values.thursday&& | |
values.friday&& | |
!values.saturday&& | |
!values.sunday | |
// Handle special cases, falling through to comma-separation | |
if(isEveryDay){ | |
return{ | |
schedule:makeCronString("*"), | |
} | |
}elseif(isMonThroughFri){ | |
return{ | |
schedule:makeCronString("1-5"), | |
} | |
}else{ | |
constdow=days.reduce((previous,current,idx)=>{ | |
if(!current){ | |
returnprevious | |
}else{ | |
constprefix=previous ?"," :"" | |
returnprevious+prefix+idx | |
} | |
},"") | |
return{ | |
schedule:makeCronString(dow), | |
} | |
} | |
} | |
exportconstformValuesToTTLRequest=(values:WorkspaceScheduleFormValues):TypesGen.UpdateWorkspaceTTLRequest=>{ | |
return{ | |
// minutes to nanoseconds | |
ttl:values.ttl ?values.ttl*60*60*1000*1_000_000 :undefined, | |
} | |
} |