@@ -25,6 +25,7 @@ const MS_HOUR_CONVERSION = 3600000
25
25
const MS_DAY_CONVERSION = 86400000
26
26
const FAILURE_CLEANUP_DEFAULT = 7
27
27
const INACTIVITY_CLEANUP_DEFAULT = 180
28
+ const LOCKED_CLEANUP_DEFAULT = 30
28
29
29
30
export interface TemplateScheduleForm {
30
31
template : Template
@@ -65,13 +66,18 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
65
66
inactivity_ttl_ms : allowAdvancedScheduling
66
67
? template . inactivity_ttl_ms / MS_DAY_CONVERSION
67
68
: 0 ,
69
+ locked_ttl_ms : allowAdvancedScheduling
70
+ ? template . locked_ttl_ms / MS_DAY_CONVERSION
71
+ : 0 ,
68
72
69
73
allow_user_autostart : template . allow_user_autostart ,
70
74
allow_user_autostop : template . allow_user_autostop ,
71
75
failure_cleanup_enabled :
72
76
allowAdvancedScheduling && Boolean ( template . failure_ttl_ms ) ,
73
77
inactivity_cleanup_enabled :
74
78
allowAdvancedScheduling && Boolean ( template . inactivity_ttl_ms ) ,
79
+ locked_cleanup_enabled :
80
+ allowAdvancedScheduling && Boolean ( template . locked_ttl_ms ) ,
75
81
} ,
76
82
validationSchema,
77
83
onSubmit : ( ) => {
@@ -114,6 +120,9 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
114
120
inactivity_ttl_ms : form . values . inactivity_ttl_ms
115
121
? form . values . inactivity_ttl_ms * MS_DAY_CONVERSION
116
122
: undefined ,
123
+ locked_ttl_ms : form . values . locked_ttl_ms
124
+ ? form . values . locked_ttl_ms * MS_DAY_CONVERSION
125
+ : undefined ,
117
126
118
127
allow_user_autostart : form . values . allow_user_autostart ,
119
128
allow_user_autostop : form . values . allow_user_autostop ,
@@ -158,6 +167,25 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
158
167
}
159
168
}
160
169
170
+ const handleToggleLockedCleanup = async ( e : ChangeEvent ) => {
171
+ form . handleChange ( e )
172
+ if ( ! form . values . locked_cleanup_enabled ) {
173
+ // fill failure_ttl_ms with defaults
174
+ await form . setValues ( {
175
+ ...form . values ,
176
+ locked_cleanup_enabled : true ,
177
+ locked_ttl_ms : LOCKED_CLEANUP_DEFAULT ,
178
+ } )
179
+ } else {
180
+ // clear failure_ttl_ms
181
+ await form . setValues ( {
182
+ ...form . values ,
183
+ locked_cleanup_enabled : false ,
184
+ locked_ttl_ms : 0 ,
185
+ } )
186
+ }
187
+ }
188
+
161
189
return (
162
190
< HorizontalForm
163
191
onSubmit = { form . handleSubmit }
@@ -298,7 +326,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
298
326
</ FormSection >
299
327
< FormSection
300
328
title = "Inactivity Cleanup"
301
- description = "When enabled, Coder will automatically delete workspaces that are in an inactive state after a specified number of days."
329
+ description = "When enabled, Coder will lock workspaces that have not been accessed after a specified number of days."
302
330
>
303
331
< FormFields >
304
332
< FormControlLabel
@@ -330,6 +358,38 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
330
358
/>
331
359
</ FormFields >
332
360
</ FormSection >
361
+ < FormSection
362
+ title = "Locked Cleanup"
363
+ description = "When enabled, Coder will permanently delete workspaces that have been locked for a specified number of days."
364
+ >
365
+ < FormFields >
366
+ < FormControlLabel
367
+ control = {
368
+ < Switch
369
+ name = "lockedCleanupEnabled"
370
+ checked = { form . values . locked_cleanup_enabled }
371
+ onChange = { handleToggleLockedCleanup }
372
+ />
373
+ }
374
+ label = "Enable Locked Cleanup"
375
+ />
376
+ < TextField
377
+ { ...getFieldHelpers (
378
+ "locked_ttl_ms" ,
379
+ < TTLHelperText
380
+ translationName = "lockedTTLHelperText"
381
+ ttl = { form . values . locked_ttl_ms }
382
+ /> ,
383
+ ) }
384
+ disabled = { isSubmitting || ! form . values . locked_cleanup_enabled }
385
+ fullWidth
386
+ inputProps = { { min : 0 , step : "any" } }
387
+ label = "Time until cleanup (days)"
388
+ type = "number"
389
+ aria-label = "Locked Cleanup"
390
+ />
391
+ </ FormFields >
392
+ </ FormSection >
333
393
</ >
334
394
) }
335
395
< InactivityDialog
0 commit comments