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:
Kira Pilot
2023-05-18 11:08:55 -07:00
committed by GitHub
parent 8e31ed4072
commit 0b15b1bcd1
20 changed files with 422 additions and 142 deletions
-18
View File
@@ -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)
})
})
})
-24
View File
@@ -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),
)
)
}