-
Notifications
You must be signed in to change notification settings - Fork 902
feat: add locked TTL field to template meta #8020
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2ea96c5
feat: add locked TTL field to template meta
sreya 939d8ab
add frontend
sreya f89fb32
lint
sreya 2b61d3f
i18
sreya 9528ca2
fix a query
sreya 1cf2bbb
fix migration
sreya 38303a2
fix enterprise scheduler
sreya c5ac779
fix migration
sreya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add frontend
- Loading branch information
commit 939d8ab40672fdf764d25ec84db3cb13e9e4f3d2
There are no files selected for viewing
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ const MS_HOUR_CONVERSION = 3600000 | |
const MS_DAY_CONVERSION = 86400000 | ||
const FAILURE_CLEANUP_DEFAULT = 7 | ||
const INACTIVITY_CLEANUP_DEFAULT = 180 | ||
const LOCKED_CLEANUP_DEFAULT = 30 | ||
|
||
export interface TemplateScheduleForm { | ||
template: Template | ||
|
@@ -65,13 +66,18 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({ | |
inactivity_ttl_ms: allowAdvancedScheduling | ||
? template.inactivity_ttl_ms / MS_DAY_CONVERSION | ||
: 0, | ||
locked_ttl_ms: allowAdvancedScheduling | ||
? template.locked_ttl_ms / MS_DAY_CONVERSION | ||
: 0, | ||
|
||
allow_user_autostart: template.allow_user_autostart, | ||
allow_user_autostop: template.allow_user_autostop, | ||
failure_cleanup_enabled: | ||
allowAdvancedScheduling && Boolean(template.failure_ttl_ms), | ||
inactivity_cleanup_enabled: | ||
allowAdvancedScheduling && Boolean(template.inactivity_ttl_ms), | ||
locked_cleanup_enabled: | ||
allowAdvancedScheduling && Boolean(template.locked_ttl_ms), | ||
}, | ||
validationSchema, | ||
onSubmit: () => { | ||
|
@@ -114,6 +120,9 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({ | |
inactivity_ttl_ms: form.values.inactivity_ttl_ms | ||
? form.values.inactivity_ttl_ms * MS_DAY_CONVERSION | ||
: undefined, | ||
locked_ttl_ms: form.values.locked_ttl_ms | ||
? form.values.locked_ttl_ms * MS_DAY_CONVERSION | ||
: undefined, | ||
|
||
allow_user_autostart: form.values.allow_user_autostart, | ||
allow_user_autostop: form.values.allow_user_autostop, | ||
|
@@ -158,6 +167,25 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({ | |
} | ||
} | ||
|
||
const handleToggleLockedCleanup = async (e: ChangeEvent) => { | ||
form.handleChange(e) | ||
if (!form.values.locked_cleanup_enabled) { | ||
// fill failure_ttl_ms with defaults | ||
sreya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await form.setValues({ | ||
...form.values, | ||
locked_cleanup_enabled: true, | ||
locked_ttl_ms: LOCKED_CLEANUP_DEFAULT, | ||
}) | ||
} else { | ||
// clear failure_ttl_ms | ||
sreya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await form.setValues({ | ||
...form.values, | ||
locked_cleanup_enabled: false, | ||
locked_ttl_ms: 0, | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<HorizontalForm | ||
onSubmit={form.handleSubmit} | ||
|
@@ -298,7 +326,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({ | |
</FormSection> | ||
<FormSection | ||
title="Inactivity Cleanup" | ||
description="When enabled, Coder will automatically delete workspaces that are in an inactive state after a specified number of days." | ||
description="When enabled, Coder will lock workspaces that have not been accessed after a specified number of days." | ||
> | ||
<FormFields> | ||
<FormControlLabel | ||
|
@@ -330,6 +358,38 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({ | |
/> | ||
</FormFields> | ||
</FormSection> | ||
<FormSection | ||
title="Locked Cleanup" | ||
description="When enabled, Coder will permanently delete workspaces that have been locked for a specified number of days." | ||
> | ||
<FormFields> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
name="lockedCleanupEnabled" | ||
checked={form.values.locked_cleanup_enabled} | ||
onChange={handleToggleLockedCleanup} | ||
/> | ||
} | ||
label="Enable Locked Cleanup" | ||
/> | ||
<TextField | ||
{...getFieldHelpers( | ||
"locked_ttl_ms", | ||
<TTLHelperText | ||
translationName="lockedTTLHelperText" | ||
ttl={form.values.locked_ttl_ms} | ||
/>, | ||
)} | ||
disabled={isSubmitting || !form.values.locked_cleanup_enabled} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think that probably makes sense, we can fix it in a follow up PR. |
||
fullWidth | ||
inputProps={{ min: 0, step: "any" }} | ||
label="Time until cleanup (days)" | ||
type="number" | ||
aria-label="Locked Cleanup" | ||
/> | ||
</FormFields> | ||
</FormSection> | ||
</> | ||
)} | ||
<InactivityDialog | ||
|
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Since we now have 3 toggling functions, we might be able to refactor into one function that takes two form values, e.g.
locked_cleanup_enabled
andlocked_ttl_ms
and appropriately toggles TTL.