Skip to content

Commit f770ce0

Browse files
committed
Dashboard
1 parent ae39e40 commit f770ce0

File tree

7 files changed

+110
-6
lines changed

7 files changed

+110
-6
lines changed

site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface CreateTemplateData {
6262
description: string;
6363
icon: string;
6464
default_ttl_hours: number;
65+
activity_bump_hours: number;
6566
use_max_ttl: boolean;
6667
max_ttl_hours: number;
6768
autostart_requirement_days_of_week: TemplateAutostartRequirementDaysValue[];
@@ -90,6 +91,13 @@ const validationSchema = Yup.object({
9091
24 * MAX_TTL_DAYS /* 30 days in hours */,
9192
"Please enter a limit that is less than or equal to 720 hours (30 days).",
9293
),
94+
activity_bump_hours: Yup.number()
95+
.integer()
96+
.min(0, "Activity bump must not be less than 0.")
97+
.max(
98+
24 * MAX_TTL_DAYS /* 30 days in hours */,
99+
"Please enter an activity bump duration that is less than or equal to 720 hours (30 days).",
100+
),
93101
max_ttl_hours: Yup.number()
94102
.integer()
95103
.min(0, "Maximum time until autostop must not be less than 0.")
@@ -108,6 +116,7 @@ const defaultInitialValues: CreateTemplateData = {
108116
description: "",
109117
icon: "",
110118
default_ttl_hours: 24,
119+
activity_bump_hours: 1,
111120
// max_ttl is an enterprise-only feature, and the server ignores the value if
112121
// you are not licensed. We hide the form value based on entitlements.
113122
//
@@ -376,6 +385,21 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
376385
label="Default autostop (hours)"
377386
type="number"
378387
/>
388+
389+
<TextField
390+
{...getFieldHelpers("activity_bump_hours", {
391+
helperText: (
392+
<ActivityBumpHelperText
393+
bump={form.values.activity_bump_hours}
394+
/>
395+
),
396+
})}
397+
disabled={isSubmitting}
398+
onChange={onChangeTrimmed(form)}
399+
fullWidth
400+
label="Activity bump (hours)"
401+
type="number"
402+
/>
379403
</Stack>
380404

381405
<Stack direction="row" css={styles.ttlFields}>
@@ -732,8 +756,33 @@ const DefaultTTLHelperText = (props: { ttl?: number }) => {
732756

733757
return (
734758
<span>
735-
Workspaces will default to stopping after {ttl} {hours(ttl)}. This will be
736-
extended by 1 hour after last activity in the workspace was detected.
759+
Workspaces will default to stopping after {ttl} {hours(ttl)} after being
760+
started.
761+
</span>
762+
);
763+
};
764+
765+
const ActivityBumpHelperText = (props: { bump?: number }) => {
766+
const { bump = 0 } = props;
767+
768+
// Error will show once field is considered touched
769+
if (bump < 0) {
770+
return null;
771+
}
772+
773+
if (bump === 0) {
774+
return (
775+
<span>
776+
Workspaces will not have their stop time automatically extended based on
777+
user activity. Users can still manually delay the stop time.
778+
</span>
779+
);
780+
}
781+
782+
return (
783+
<span>
784+
Workspaces will be automatically bumped by {bump} {hours(bump)} when user
785+
activity is detected.
737786
</span>
738787
);
739788
};

site/src/pages/CreateTemplatePage/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CreateTemplateRequest,
23
Entitlements,
34
ProvisionerType,
45
TemplateExample,
@@ -11,7 +12,9 @@ const provisioner: ProvisionerType =
1112
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Playwright needs to use a different provisioner type!
1213
typeof (window as any).playwright !== "undefined" ? "echo" : "terraform";
1314

14-
export const newTemplate = (formData: CreateTemplateData) => {
15+
export const newTemplate = (
16+
formData: CreateTemplateData,
17+
): Omit<CreateTemplateRequest, "template_version_id"> => {
1518
let {
1619
max_ttl_hours,
1720
autostop_requirement_days_of_week,
@@ -42,6 +45,7 @@ export const newTemplate = (formData: CreateTemplateData) => {
4245
...safeTemplateData,
4346
disable_everyone_group_access: !formData.allow_everyone_group_access,
4447
default_ttl_ms: formData.default_ttl_hours * 60 * 60 * 1000, // Convert hours to ms
48+
activity_bump_ms: formData.activity_bump_hours * 60 * 60 * 1000, // Convert hours to ms
4549
max_ttl_ms: max_ttl_hours * 60 * 60 * 1000, // Convert hours to ms
4650
autostop_requirement: {
4751
days_of_week: calculateAutostopRequirementDaysValue(

site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { TemplateSettingsPage } from "./TemplateSettingsPage";
1414
type FormValues = Required<
1515
Omit<
1616
UpdateTemplateMeta,
17-
"default_ttl_ms" | "max_ttl_ms" | "deprecation_message"
17+
"default_ttl_ms" | "activity_bump_ms" | "max_ttl_ms" | "deprecation_message"
1818
>
1919
>;
2020

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TTLHelperText.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,33 @@ export const DefaultTTLHelperText = (props: { ttl?: number }) => {
1515

1616
return (
1717
<span>
18-
Workspaces will default to stopping after {ttl} {hours(ttl)}. This will be
19-
extended by 1 hour after last activity in the workspace was detected.
18+
Workspaces will default to stopping after {ttl} {hours(ttl)} after being
19+
started.
20+
</span>
21+
);
22+
};
23+
24+
export const ActivityBumpHelperText = (props: { bump?: number }) => {
25+
const { bump = 0 } = props;
26+
27+
// Error will show once field is considered touched
28+
if (bump < 0) {
29+
return null;
30+
}
31+
32+
if (bump === 0) {
33+
return (
34+
<span>
35+
Workspaces will not have their stop time automatically extended based on
36+
user activity. Users can still manually delay the stop time.
37+
</span>
38+
);
39+
}
40+
41+
return (
42+
<span>
43+
Workspaces will be automatically bumped by {bump} {hours(bump)} when user
44+
activity is detected.
2045
</span>
2146
);
2247
};

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateScheduleForm.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from "./useWorkspacesToBeDeleted";
2727
import { TemplateScheduleFormValues, getValidationSchema } from "./formHelpers";
2828
import {
29+
ActivityBumpHelperText,
2930
DefaultTTLHelperText,
3031
DormancyAutoDeletionTTLHelperText,
3132
DormancyTTLHelperText,
@@ -72,6 +73,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
7273
initialValues: {
7374
// on display, convert from ms => hours
7475
default_ttl_ms: template.default_ttl_ms / MS_HOUR_CONVERSION,
76+
activity_bump_ms: template.activity_bump_ms / MS_HOUR_CONVERSION,
7577
// the API ignores these values, but to avoid tripping up validation set
7678
// it to zero if the user can't set the field.
7779
use_max_ttl:
@@ -206,6 +208,9 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
206208
default_ttl_ms: form.values.default_ttl_ms
207209
? form.values.default_ttl_ms * MS_HOUR_CONVERSION
208210
: undefined,
211+
activity_bump_ms: form.values.activity_bump_ms
212+
? form.values.activity_bump_ms * MS_HOUR_CONVERSION
213+
: undefined,
209214
max_ttl_ms:
210215
form.values.max_ttl_ms && form.values.use_max_ttl
211216
? form.values.max_ttl_ms * MS_HOUR_CONVERSION
@@ -365,6 +370,19 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
365370
label="Default autostop (hours)"
366371
type="number"
367372
/>
373+
374+
<TextField
375+
{...getFieldHelpers("activity_bump_ms", {
376+
helperText: (
377+
<ActivityBumpHelperText bump={form.values.activity_bump_ms} />
378+
),
379+
})}
380+
disabled={isSubmitting}
381+
fullWidth
382+
inputProps={{ min: 0, step: 1 }}
383+
label="Activity bump (hours)"
384+
type="number"
385+
/>
368386
</Stack>
369387
</FormSection>
370388

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/formHelpers.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
3030
24 * MAX_TTL_DAYS /* 30 days in hours */,
3131
"Please enter a limit that is less than or equal to 720 hours (30 days).",
3232
),
33+
activity_bump_ms: Yup.number()
34+
.integer()
35+
.min(0, "Activity bump must not be less than 0.")
36+
.max(
37+
24 * MAX_TTL_DAYS /* 30 days in hours */,
38+
"Please enter an activity bump duration that is less than or equal to 720 hours (30 days).",
39+
),
3340
max_ttl_ms: Yup.number()
3441
.integer()
3542
.min(0, "Maximum time until autostop must not be less than 0.")

site/src/testHelpers/entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ export const MockTemplate: TypesGen.Template = {
458458
},
459459
description: "This is a test description.",
460460
default_ttl_ms: 24 * 60 * 60 * 1000,
461+
activity_bump_ms: 1 * 60 * 60 * 1000,
461462
use_max_ttl: false,
462463
max_ttl_ms: 0,
463464
autostop_requirement: {

0 commit comments

Comments
 (0)