@@ -2,16 +2,17 @@ import AlertTitle from "@mui/material/AlertTitle";
2
2
import { workspaceResolveAutostart } from "api/queries/workspaceQuota" ;
3
3
import { Template , TemplateVersion , Workspace } from "api/typesGenerated" ;
4
4
import { Alert , AlertDetail , AlertProps } from "components/Alert/Alert" ;
5
- import { FC , useEffect , useState } from "react" ;
5
+ import { FC , ReactNode , useEffect , useState } from "react" ;
6
6
import { useQuery } from "react-query" ;
7
7
import { WorkspacePermissions } from "./permissions" ;
8
- import { DormantWorkspaceBanner } from "./DormantWorkspaceBanner" ;
9
8
import dayjs from "dayjs" ;
9
+ import { useIsWorkspaceActionsEnabled } from "components/Dashboard/DashboardProvider" ;
10
+ import formatDistanceToNow from "date-fns/formatDistanceToNow" ;
10
11
11
12
type Notification = {
12
13
title : string ;
13
14
severity : AlertProps [ "severity" ] ;
14
- detail ?: string ;
15
+ detail ?: ReactNode ;
15
16
actions ?: { label : string ; onClick : ( ) => void } [ ] ;
16
17
} ;
17
18
@@ -72,11 +73,15 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
72
73
notifications . push ( {
73
74
title : "Workspace is unhealthy" ,
74
75
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
+ ) ,
80
85
actions : permissions . updateWorkspace
81
86
? [
82
87
{
@@ -88,6 +93,42 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
88
93
} ) ;
89
94
}
90
95
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
+
91
132
// Pending in Queue
92
133
const [ showAlertPendingInQueue , setShowAlertPendingInQueue ] = useState ( false ) ;
93
134
// 2023-11-15 - MES - This effect will be called every single render because
@@ -127,8 +168,6 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
127
168
128
169
return (
129
170
< >
130
- < DormantWorkspaceBanner workspace = { workspace } />
131
-
132
171
{ showAlertPendingInQueue && (
133
172
< Alert severity = "info" >
134
173
< AlertTitle > Workspace build is pending</ AlertTitle >
0 commit comments