- Notifications
You must be signed in to change notification settings - Fork929
feat: add UI for autostart workspace days#10263
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
7749baf
feat: add ui for selecting auto start days
Emyrkd1bf614
Add helper text
Emyrkdcf4b6a
Fix patch
Emyrk0f0edcb
reformat
Emyrk585099a
refactor into a component to be reused
Emyrk96a79df
Add to create template flow
Emyrka25f575
Make fmt
Emyrk4aa5f4e
Unused imports
EmyrkFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionscoderd/templates.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletionssite/src/components/TemplateScheduleAutostart/TemplateScheduleAutostart.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { FC } from "react"; | ||
import { TemplateAutostartRequirementDaysValue } from "utils/schedule"; | ||
import Button from "@mui/material/Button"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import FormHelperText from "@mui/material/FormHelperText"; | ||
export interface TemplateScheduleAutostartProps { | ||
allow_user_autostart?: boolean; | ||
autostart_requirement_days_of_week: TemplateAutostartRequirementDaysValue[]; | ||
isSubmitting: boolean; | ||
onChange: (newDaysOfWeek: TemplateAutostartRequirementDaysValue[]) => void; | ||
} | ||
export const TemplateScheduleAutostart: FC< | ||
React.PropsWithChildren<TemplateScheduleAutostartProps> | ||
> = ({ | ||
autostart_requirement_days_of_week, | ||
isSubmitting, | ||
allow_user_autostart, | ||
onChange, | ||
}) => { | ||
return ( | ||
<Stack | ||
direction="column" | ||
width="100%" | ||
alignItems="center" | ||
css={{ | ||
marginBottom: "20px", | ||
}} | ||
> | ||
<Stack | ||
direction="row" | ||
css={{ | ||
width: "100%", | ||
}} | ||
spacing={0} | ||
alignItems="baseline" | ||
justifyContent="center" | ||
> | ||
{( | ||
[ | ||
{ value: "monday", key: "Mon" }, | ||
{ value: "tuesday", key: "Tue" }, | ||
{ value: "wednesday", key: "Wed" }, | ||
{ value: "thursday", key: "Thu" }, | ||
{ value: "friday", key: "Fri" }, | ||
{ value: "saturday", key: "Sat" }, | ||
{ value: "sunday", key: "Sun" }, | ||
] as { | ||
value: TemplateAutostartRequirementDaysValue; | ||
key: string; | ||
}[] | ||
).map((day) => ( | ||
<Button | ||
key={day.key} | ||
css={{ | ||
borderRadius: "0px", | ||
}} | ||
// TODO: Adding a background color would also help | ||
color={ | ||
autostart_requirement_days_of_week.includes(day.value) | ||
? "primary" | ||
: "secondary" | ||
} | ||
disabled={isSubmitting || !allow_user_autostart} | ||
onClick={() => { | ||
if (!autostart_requirement_days_of_week.includes(day.value)) { | ||
onChange(autostart_requirement_days_of_week.concat(day.value)); | ||
} else { | ||
onChange( | ||
autostart_requirement_days_of_week.filter( | ||
(obj) => obj !== day.value, | ||
), | ||
); | ||
} | ||
}} | ||
> | ||
{day.key} | ||
</Button> | ||
))} | ||
</Stack> | ||
<FormHelperText> | ||
<AutostartRequirementDaysHelperText | ||
allowed={allow_user_autostart} | ||
days={autostart_requirement_days_of_week} | ||
/> | ||
</FormHelperText> | ||
</Stack> | ||
); | ||
}; | ||
export const sortedDays = [ | ||
"monday", | ||
"tuesday", | ||
"wednesday", | ||
"thursday", | ||
"friday", | ||
"saturday", | ||
"sunday", | ||
] as TemplateAutostartRequirementDaysValue[]; | ||
const AutostartRequirementDaysHelperText: FC<{ | ||
allowed?: boolean; | ||
days: TemplateAutostartRequirementDaysValue[]; | ||
}> = ({ allowed, days: unsortedDays }) => { | ||
if (!allowed) { | ||
return <span>Workspaces are not allowed to auto start.</span>; | ||
} | ||
// Sort the days | ||
const days = unsortedDays.sort( | ||
(a, b) => sortedDays.indexOf(a) - sortedDays.indexOf(b), | ||
); | ||
let daymsg = `Workspaces can autostart on ${days.join(", ")}.`; | ||
if (days.length === 7) { | ||
// If every day is allowed, no more explaining is needed. | ||
return <span>Workspaces are allowed to auto start on any day.</span>; | ||
} | ||
if (days.length === 0) { | ||
return ( | ||
<span> | ||
Workspaces will never auto start. This is effectively the same as | ||
disabling autostart. | ||
</span> | ||
); | ||
} | ||
if ( | ||
days.length === 5 && | ||
!days.includes("saturday") && | ||
!days.includes("sunday") | ||
) { | ||
daymsg = "Workspaces will never auto start on the weekends."; | ||
} | ||
return ( | ||
<span>{daymsg} These days are relative to the user's timezone.</span> | ||
); | ||
}; |
31 changes: 30 additions & 1 deletionsite/src/pages/CreateTemplatePage/CreateTemplateForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletionssite/src/pages/CreateTemplatePage/utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
32 changes: 31 additions & 1 deletionsite/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateScheduleForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionssite/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePage.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletionssite/src/pages/TemplateSettingsPage/TemplateSchedulePage/formHelpers.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionssite/src/utils/schedule.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.