feat: add template activity_bump property (#11734)

Allows template admins to configure the activity bump duration. Defaults to 1h.
This commit is contained in:
Dean Sheather
2024-02-13 07:00:35 +00:00
committed by GitHub
parent fead57f304
commit e1e352d8c1
34 changed files with 354 additions and 90 deletions
+3
View File
@@ -225,6 +225,7 @@ export interface CreateTemplateRequest {
readonly icon?: string;
readonly template_version_id: string;
readonly default_ttl_ms?: number;
readonly activity_bump_ms?: number;
readonly max_ttl_ms?: number;
readonly autostop_requirement?: TemplateAutostopRequirement;
readonly autostart_requirement?: TemplateAutostartRequirement;
@@ -1028,6 +1029,7 @@ export interface Template {
readonly deprecation_message: string;
readonly icon: string;
readonly default_ttl_ms: number;
readonly activity_bump_ms: number;
readonly use_max_ttl: boolean;
readonly max_ttl_ms: number;
readonly autostop_requirement: TemplateAutostopRequirement;
@@ -1285,6 +1287,7 @@ export interface UpdateTemplateMeta {
readonly description?: string;
readonly icon?: string;
readonly default_ttl_ms?: number;
readonly activity_bump_ms?: number;
readonly max_ttl_ms?: number;
readonly autostop_requirement?: TemplateAutostopRequirement;
readonly autostart_requirement?: TemplateAutostartRequirement;
@@ -14,7 +14,7 @@ import { TemplateSettingsPage } from "./TemplateSettingsPage";
type FormValues = Required<
Omit<
UpdateTemplateMeta,
"default_ttl_ms" | "max_ttl_ms" | "deprecation_message"
"default_ttl_ms" | "activity_bump_ms" | "max_ttl_ms" | "deprecation_message"
>
>;
@@ -15,8 +15,33 @@ export const DefaultTTLHelperText = (props: { ttl?: number }) => {
return (
<span>
Workspaces will default to stopping after {ttl} {hours(ttl)}. This will be
extended by 1 hour after last activity in the workspace was detected.
Workspaces will default to stopping after {ttl} {hours(ttl)} after being
started.
</span>
);
};
export const ActivityBumpHelperText = (props: { bump?: number }) => {
const { bump = 0 } = props;
// Error will show once field is considered touched
if (bump < 0) {
return null;
}
if (bump === 0) {
return (
<span>
Workspaces will not have their stop time automatically extended based on
user activity. Users can still manually delay the stop time.
</span>
);
}
return (
<span>
Workspaces will be automatically bumped by {bump} {hours(bump)} when user
activity is detected.
</span>
);
};
@@ -28,6 +28,7 @@ import {
} from "./useWorkspacesToBeDeleted";
import { TemplateScheduleFormValues, getValidationSchema } from "./formHelpers";
import {
ActivityBumpHelperText,
DefaultTTLHelperText,
DormancyAutoDeletionTTLHelperText,
DormancyTTLHelperText,
@@ -72,6 +73,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
initialValues: {
// on display, convert from ms => hours
default_ttl_ms: template.default_ttl_ms / MS_HOUR_CONVERSION,
activity_bump_ms: template.activity_bump_ms / MS_HOUR_CONVERSION,
// the API ignores these values, but to avoid tripping up validation set
// it to zero if the user can't set the field.
use_max_ttl:
@@ -206,6 +208,9 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
default_ttl_ms: form.values.default_ttl_ms
? form.values.default_ttl_ms * MS_HOUR_CONVERSION
: undefined,
activity_bump_ms: form.values.activity_bump_ms
? form.values.activity_bump_ms * MS_HOUR_CONVERSION
: undefined,
max_ttl_ms:
form.values.max_ttl_ms && form.values.use_max_ttl
? form.values.max_ttl_ms * MS_HOUR_CONVERSION
@@ -365,6 +370,19 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
label="Default autostop (hours)"
type="number"
/>
<TextField
{...getFieldHelpers("activity_bump_ms", {
helperText: (
<ActivityBumpHelperText bump={form.values.activity_bump_ms} />
),
})}
disabled={isSubmitting}
fullWidth
inputProps={{ min: 0, step: 1 }}
label="Activity bump (hours)"
type="number"
/>
</Stack>
</FormSection>
@@ -15,6 +15,7 @@ import TemplateSchedulePage from "./TemplateSchedulePage";
const validFormValues: TemplateScheduleFormValues = {
default_ttl_ms: 1,
activity_bump_ms: 1,
use_max_ttl: true,
max_ttl_ms: 2,
failure_ttl_ms: 7,
@@ -25,19 +25,31 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
Yup.object({
default_ttl_ms: Yup.number()
.integer()
.required()
.min(0, "Default time until autostop must not be less than 0.")
.max(
24 * MAX_TTL_DAYS /* 30 days in hours */,
"Please enter a limit that is less than or equal to 720 hours (30 days).",
),
activity_bump_ms: Yup.number()
.integer()
.required()
.min(0, "Activity bump must not be less than 0.")
.max(
24 * MAX_TTL_DAYS /* 30 days in hours */,
"Please enter an activity bump duration that is less than or equal to 720 hours (30 days).",
),
max_ttl_ms: Yup.number()
.integer()
.required()
.min(0, "Maximum time until autostop must not be less than 0.")
.max(
24 * MAX_TTL_DAYS /* 30 days in hours */,
"Please enter a limit that is less than or equal to 720 hours (30 days).",
),
failure_ttl_ms: Yup.number()
.integer()
.required()
.min(0, "Failure cleanup days must not be less than 0.")
.test(
"positive-if-enabled",
@@ -52,6 +64,8 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
},
),
time_til_dormant_ms: Yup.number()
.integer()
.required()
.min(0, "Dormancy threshold days must not be less than 0.")
.test(
"positive-if-enabled",
@@ -66,6 +80,8 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
},
),
time_til_dormant_autodelete_ms: Yup.number()
.integer()
.required()
.min(0, "Dormancy auto-deletion days must not be less than 0.")
.test(
"positive-if-enabled",
+1
View File
@@ -459,6 +459,7 @@ export const MockTemplate: TypesGen.Template = {
},
description: "This is a test description.",
default_ttl_ms: 24 * 60 * 60 * 1000,
activity_bump_ms: 1 * 60 * 60 * 1000,
use_max_ttl: false,
max_ttl_ms: 0,
autostop_requirement: {