mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
licensing and feature flagging
This commit is contained in:
@@ -9,7 +9,6 @@ import {
|
||||
MockStartingWorkspace,
|
||||
MockStoppedWorkspace,
|
||||
MockStoppingWorkspace,
|
||||
MockWorkspaceImpendingDeletion,
|
||||
MockWorkspace,
|
||||
} from "testHelpers/entities"
|
||||
import {
|
||||
@@ -75,8 +74,3 @@ export const Pending = Template.bind({})
|
||||
Pending.args = {
|
||||
workspace: MockPendingWorkspace,
|
||||
}
|
||||
|
||||
export const ImpendingDeletion = Template.bind({})
|
||||
ImpendingDeletion.args = {
|
||||
workspace: MockWorkspaceImpendingDeletion,
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { FC, PropsWithChildren } from "react"
|
||||
import { makeStyles } from "@mui/styles"
|
||||
import { combineClasses } from "utils/combineClasses"
|
||||
import { displayImpendingDeletion } from "utils/workspace"
|
||||
import { useDashboard } from "components/Dashboard/DashboardProvider"
|
||||
|
||||
const LoadingIcon: FC = () => {
|
||||
return <CircularProgress size={10} style={{ color: "#FFF" }} />
|
||||
@@ -92,18 +93,34 @@ export type WorkspaceStatusBadgeProps = {
|
||||
className?: string
|
||||
}
|
||||
|
||||
const ImpendingDeletionBadge: FC<
|
||||
PropsWithChildren<Partial<WorkspaceStatusBadgeProps>>
|
||||
> = ({ className }) => {
|
||||
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 (!allowAdvancedScheduling || !allowWorkspaceActions) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<Pill
|
||||
className={className}
|
||||
icon={<ErrorIcon />}
|
||||
text="Impending deletion"
|
||||
type="error"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const WorkspaceStatusBadge: FC<
|
||||
PropsWithChildren<WorkspaceStatusBadgeProps>
|
||||
> = ({ workspace, className }) => {
|
||||
if (displayImpendingDeletion(workspace)) {
|
||||
return (
|
||||
<Pill
|
||||
className={className}
|
||||
icon={<ErrorIcon />}
|
||||
text="Impending deletion"
|
||||
type="error"
|
||||
/>
|
||||
)
|
||||
return <ImpendingDeletionBadge className={className} />
|
||||
}
|
||||
|
||||
const { text, icon, type } = getStatus(workspace.latest_build.status)
|
||||
|
||||
@@ -806,12 +806,6 @@ export const MockPendingWorkspace: TypesGen.Workspace = {
|
||||
},
|
||||
}
|
||||
|
||||
export const MockWorkspaceImpendingDeletion: TypesGen.Workspace = {
|
||||
...MockWorkspace,
|
||||
id: "test-workspace-impending-deletion",
|
||||
deleting_at: new Date().toISOString(),
|
||||
}
|
||||
|
||||
// just over one page of workspaces
|
||||
export const MockWorkspacesResponse: TypesGen.WorkspacesResponse = {
|
||||
workspaces: range(1, 27).map((id: number) => ({
|
||||
|
||||
@@ -202,24 +202,6 @@ export const displayImpendingDeletion = (workspace: TypesGen.Workspace) => {
|
||||
if (!workspace.deleting_at) {
|
||||
return false
|
||||
}
|
||||
|
||||
console.log("today", today)
|
||||
console.log("workspace.deletingAt", new Date(workspace.deleting_at))
|
||||
console.log(
|
||||
"set",
|
||||
new Date(
|
||||
today.setDate(today.getDate() - IMPENDING_DELETION_DISPLAY_THRESHOLD),
|
||||
),
|
||||
)
|
||||
|
||||
console.log(
|
||||
"compare",
|
||||
new Date(workspace.deleting_at) <=
|
||||
new Date(
|
||||
today.setDate(today.getDate() + IMPENDING_DELETION_DISPLAY_THRESHOLD),
|
||||
),
|
||||
)
|
||||
|
||||
return (
|
||||
new Date(workspace.deleting_at) <=
|
||||
new Date(
|
||||
|
||||
Reference in New Issue
Block a user