Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reformat
  • Loading branch information
Emyrk committed Oct 13, 2023
commit 0f0edcb3758f44011162fa3ecd1f35c91dddc62f
1 change: 1 addition & 0 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
req.DefaultTTLMillis == time.Duration(template.DefaultTTL).Milliseconds() &&
req.MaxTTLMillis == time.Duration(template.MaxTTL).Milliseconds() &&
autostopRequirementDaysOfWeekParsed == scheduleOpts.AutostopRequirement.DaysOfWeek &&
autostartRequirementDaysOfWeekParsed == scheduleOpts.AutostartRequirement.DaysOfWeek &&
req.AutostopRequirement.Weeks == scheduleOpts.AutostopRequirement.Weeks &&
req.FailureTTLMillis == time.Duration(template.FailureTTL).Milliseconds() &&
req.TimeTilDormantMillis == time.Duration(template.TimeTilDormant).Milliseconds() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ export const sortedDays = [
] as TemplateAutostartRequirementDaysValue[];

export const AutostartRequirementDaysHelperText: FC<{
allowed?: boolean;
days: TemplateAutostartRequirementDaysValue[];
}> = ({ days: unsortedDays }) => {
}> = ({ 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,74 +360,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
</Stack>
</FormSection>

{allowAdvancedScheduling && (
<FormSection
title="Autostart Requirement"
description="Define when workspaces created from this template are allowed to auto start. Days not selected will block auto start actions from occurring."
>
<Stack direction="column">
<Stack direction="row" css={styles.ttlFields} spacing={0}>
{(
[
{ 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={styles.dayButtons}
// TODO: Adding a background color would also help
color={
form.values.autostart_requirement_days_of_week.includes(
day.value,
)
? "primary"
: "secondary"
}
disabled={isSubmitting}
onClick={async () => {
if (
!form.values.autostart_requirement_days_of_week.includes(
day.value,
)
) {
await form.setFieldValue(
"autostart_requirement_days_of_week",
form.values.autostart_requirement_days_of_week.concat(
day.value,
),
);
} else {
await form.setFieldValue(
"autostart_requirement_days_of_week",
form.values.autostart_requirement_days_of_week.filter(
(obj) => obj !== day.value,
),
);
}
}}
>
{day.key}
</Button>
))}
</Stack>
<FormHelperText>
<AutostartRequirementDaysHelperText
days={form.values.autostart_requirement_days_of_week}
/>
</FormHelperText>
</Stack>
</FormSection>
)}

{allowAutostopRequirement && (
<FormSection
title="Autostop Requirement"
Expand Down Expand Up @@ -509,6 +441,84 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
</strong>
</Stack>
</Stack>

{allowAdvancedScheduling && (
<Stack
direction="column"
width="100%"
alignItems="center"
css={{
marginBottom: "20px",
}}
>
<Stack
direction="row"
css={styles.ttlFields}
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={styles.dayButtons}
// TODO: Adding a background color would also help
color={
form.values.autostart_requirement_days_of_week.includes(
day.value,
)
? "primary"
: "secondary"
}
disabled={isSubmitting || !form.values.allow_user_autostart}
onClick={async () => {
if (
!form.values.autostart_requirement_days_of_week.includes(
day.value,
)
) {
await form.setFieldValue(
"autostart_requirement_days_of_week",
form.values.autostart_requirement_days_of_week.concat(
day.value,
),
);
} else {
await form.setFieldValue(
"autostart_requirement_days_of_week",
form.values.autostart_requirement_days_of_week.filter(
(obj) => obj !== day.value,
),
);
}
}}
>
{day.key}
</Button>
))}
</Stack>
<FormHelperText>
<AutostartRequirementDaysHelperText
allowed={form.values.allow_user_autostart}
days={form.values.autostart_requirement_days_of_week}
/>
</FormHelperText>
</Stack>
)}

<Stack direction="row" alignItems="center">
<Checkbox
id="allow-user-autostop"
Expand Down