Skip to content

feat: add frontend for locked workspaces #8655

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 16 commits into from
Aug 4, 2023
Prev Previous commit
Next Next commit
remove some redundant code
  • Loading branch information
sreya committed Aug 2, 2023
commit 90b6adefeacc70fd5633ad07faf081ae695bf4ac
19 changes: 2 additions & 17 deletions site/src/components/WorkspaceDeletion/ImpendingDeletionBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Workspace } from "api/typesGenerated"
import { displayLockedWorkspace } from "./utils"
import { useDashboard } from "components/Dashboard/DashboardProvider"
import { isWorkspaceActionsEnabled } from "components/Dashboard/DashboardProvider"
import { Pill } from "components/Pill/Pill"
import LockIcon from "@mui/icons-material/Lock"

Expand All @@ -9,21 +8,7 @@ export const LockedBadge = ({
}: {
workspace: Workspace
}): JSX.Element | null => {
const { entitlements, experiments } = useDashboard()
const allowAdvancedScheduling =
entitlements.features["advanced_template_scheduling"].enabled
// This check can be removed when https://github.com/coder/coder/milestone/19
// is merged up
const allowWorkspaceActions = experiments.includes("workspace_actions")
// return null

if (
!displayLockedWorkspace(
workspace,
allowAdvancedScheduling,
allowWorkspaceActions,
)
) {
if (!workspace.locked_at || !isWorkspaceActionsEnabled()) {
return null
}

Expand Down
15 changes: 5 additions & 10 deletions site/src/components/WorkspaceDeletion/ImpendingDeletionBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Workspace } from "api/typesGenerated"
import { useDashboard } from "components/Dashboard/DashboardProvider"
import {
isWorkspaceActionsEnabled,
useDashboard,
} from "components/Dashboard/DashboardProvider"
import { Alert } from "components/Alert/Alert"
import { formatDistanceToNow, differenceInDays, add, format } from "date-fns"
import Link from "@mui/material/Link"
Expand All @@ -21,13 +24,6 @@ export const LockedWorkspaceBanner = ({
shouldRedisplayBanner: boolean
count?: Count
}): JSX.Element | null => {
const { entitlements, experiments } = useDashboard()
const allowAdvancedScheduling =
entitlements.features["advanced_template_scheduling"].enabled
// This check can be removed when https://github.com/coder/coder/milestone/19
// is merged up
const allowWorkspaceActions = experiments.includes("workspace_actions")

if (!workspaces) {
return null
}
Expand All @@ -45,8 +41,7 @@ export const LockedWorkspaceBanner = ({
// Banners should be redisplayed after dismissal when additional workspaces are newly scheduled for deletion
!shouldRedisplayBanner) &&
// Only show this if the experiment is included.
allowWorkspaceActions &&
allowAdvancedScheduling
isWorkspaceActionsEnabled()
) {
return null
}
Expand Down
22 changes: 0 additions & 22 deletions site/src/components/WorkspaceDeletion/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@ import { Workspace } from "api/typesGenerated"
// 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 displayLockedWorkspace = (
workspace: Workspace,
allowAdvancedScheduling: boolean,
allowWorkspaceActions: boolean,
) => {
if (
!workspace.locked_at ||
!allowAdvancedScheduling ||
!allowWorkspaceActions
) {
return false
}
return workspace.locked_at
}

/**
* Returns a boolean indicating if an impending deletion indicator should be
* displayed in the UI. Impending deletions are configured by setting the
Expand Down