mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add impending deletion indicators to the workspace page (#7588)
* created WorkspaceDeletion directory * remove commented code * attempting to fix workspace stories * fix lint * fix the rest of the stories * fix right stories * PR comments * fix lint
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
getDisplayVersionStatus,
|
||||
getDisplayWorkspaceBuildInitiatedBy,
|
||||
getDisplayWorkspaceTemplateName,
|
||||
displayImpendingDeletion,
|
||||
isWorkspaceOn,
|
||||
} from "./workspace"
|
||||
|
||||
@@ -140,21 +139,4 @@ describe("util > workspace", () => {
|
||||
expect(displayed).toEqual(workspace.template_display_name)
|
||||
})
|
||||
})
|
||||
|
||||
describe("displayImpendingDeletion", () => {
|
||||
const today = new Date()
|
||||
it.each<[string, boolean]>([
|
||||
[new Date(new Date().setDate(today.getDate() + 15)).toISOString(), false], // today + 15 days out
|
||||
[new Date(new Date().setDate(today.getDate() + 14)).toISOString(), true], // today + 14
|
||||
[new Date(new Date().setDate(today.getDate() + 13)).toISOString(), true], // today + 13
|
||||
[new Date(new Date().setDate(today.getDate() + 1)).toISOString(), true], // today + 1
|
||||
[new Date().toISOString(), true], // today + 0
|
||||
])(`deleting_at=%p, isWorkspaceOn=%p`, (deleting_at, shouldDisplay) => {
|
||||
const workspace: TypesGen.Workspace = {
|
||||
...Mocks.MockWorkspace,
|
||||
deleting_at,
|
||||
}
|
||||
expect(displayImpendingDeletion(workspace)).toBe(shouldDisplay)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -185,27 +185,3 @@ export const getDisplayWorkspaceTemplateName = (
|
||||
? workspace.template_display_name
|
||||
: workspace.template_name
|
||||
}
|
||||
|
||||
// This const dictates how far out we alert the user that a workspace
|
||||
// has an impending deletion (due to template.InactivityTTL being set)
|
||||
const IMPENDING_DELETION_DISPLAY_THRESHOLD = 14 // 14 days
|
||||
|
||||
/**
|
||||
* Returns a boolean indicating if an impending deletion indicator should be
|
||||
* displayed in the UI. Impending deletions are configured by setting the
|
||||
* Template.InactivityTTL
|
||||
* @param {TypesGen.Workspace} workspace
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const displayImpendingDeletion = (workspace: TypesGen.Workspace) => {
|
||||
const today = new Date()
|
||||
if (!workspace.deleting_at) {
|
||||
return false
|
||||
}
|
||||
return (
|
||||
new Date(workspace.deleting_at) <=
|
||||
new Date(
|
||||
today.setDate(today.getDate() + IMPENDING_DELETION_DISPLAY_THRESHOLD),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user