Skip to content

Commit d3e68fb

Browse files
committed
Move dormant notifications to notifications array
1 parent 706bbd5 commit d3e68fb

File tree

2 files changed

+49
-86
lines changed

2 files changed

+49
-86
lines changed

site/src/pages/WorkspacePage/DormantWorkspaceBanner.tsx

Lines changed: 0 additions & 76 deletions
This file was deleted.

site/src/pages/WorkspacePage/WorkspaceNotifications.tsx

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import AlertTitle from "@mui/material/AlertTitle";
22
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
33
import { Template, TemplateVersion, Workspace } from "api/typesGenerated";
44
import { Alert, AlertDetail, AlertProps } from "components/Alert/Alert";
5-
import { FC, useEffect, useState } from "react";
5+
import { FC, ReactNode, useEffect, useState } from "react";
66
import { useQuery } from "react-query";
77
import { WorkspacePermissions } from "./permissions";
8-
import { DormantWorkspaceBanner } from "./DormantWorkspaceBanner";
98
import dayjs from "dayjs";
9+
import { useIsWorkspaceActionsEnabled } from "components/Dashboard/DashboardProvider";
10+
import formatDistanceToNow from "date-fns/formatDistanceToNow";
1011

1112
type Notification = {
1213
title: string;
1314
severity: AlertProps["severity"];
14-
detail?: string;
15+
detail?: ReactNode;
1516
actions?: { label: string; onClick: () => void }[];
1617
};
1718

@@ -72,11 +73,15 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
7273
notifications.push({
7374
title: "Workspace is unhealthy",
7475
severity: "warning",
75-
detail: `Your workspace is running but ${
76-
workspace.health.failing_agents.length > 1
77-
? `${workspace.health.failing_agents.length} agents are unhealthy`
78-
: `1 agent is unhealthy`
79-
}.`,
76+
detail: (
77+
<>
78+
Your workspace is running but{" "}
79+
{workspace.health.failing_agents.length > 1
80+
? `${workspace.health.failing_agents.length} agents are unhealthy`
81+
: `1 agent is unhealthy`}
82+
.
83+
</>
84+
),
8085
actions: permissions.updateWorkspace
8186
? [
8287
{
@@ -88,6 +93,42 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
8893
});
8994
}
9095

96+
// Dormant
97+
const areActionsEnabled = useIsWorkspaceActionsEnabled();
98+
if (areActionsEnabled && workspace.dormant_at) {
99+
const formatDate = (dateStr: string, timestamp: boolean): string => {
100+
const date = new Date(dateStr);
101+
return date.toLocaleDateString(undefined, {
102+
month: "long",
103+
day: "numeric",
104+
year: "numeric",
105+
...(timestamp ? { hour: "numeric", minute: "numeric" } : {}),
106+
});
107+
};
108+
notifications.push({
109+
title: "Workspace is dormant",
110+
severity: "warning",
111+
detail: workspace.deleting_at ? (
112+
<>
113+
This workspace has not been used for{" "}
114+
{formatDistanceToNow(Date.parse(workspace.last_used_at))} and was
115+
marked dormant on {formatDate(workspace.dormant_at, false)}. It is
116+
scheduled to be deleted on {formatDate(workspace.deleting_at, true)}.
117+
To keep it you must activate the workspace.
118+
</>
119+
) : (
120+
<>
121+
This workspace has not been used for{" "}
122+
{formatDistanceToNow(Date.parse(workspace.last_used_at))} and was
123+
marked dormant on {formatDate(workspace.dormant_at, false)}. It is not
124+
scheduled for auto-deletion but will become a candidate if
125+
auto-deletion is enabled on this template. To keep it you must
126+
activate the workspace.
127+
</>
128+
),
129+
});
130+
}
131+
91132
// Pending in Queue
92133
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false);
93134
// 2023-11-15 - MES - This effect will be called every single render because
@@ -127,8 +168,6 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
127168

128169
return (
129170
<>
130-
<DormantWorkspaceBanner workspace={workspace} />
131-
132171
{showAlertPendingInQueue && (
133172
<Alert severity="info">
134173
<AlertTitle>Workspace build is pending</AlertTitle>

0 commit comments

Comments
 (0)