Skip to content

refactor(site): refactor workspace notifications #11520

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 27 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0b28628
Refactor outdated warning
BrunoQuaresma Jan 9, 2024
ab96aab
Move unhealthy warning
BrunoQuaresma Jan 9, 2024
38f213e
Move dormant notification
BrunoQuaresma Jan 9, 2024
9ec5952
Remove mutation errors from alerts
BrunoQuaresma Jan 9, 2024
17ecf0e
Move pending in queue notification
BrunoQuaresma Jan 9, 2024
c969df5
Move deprecated notification
BrunoQuaresma Jan 9, 2024
8f6040d
Move outdated to notifications array
BrunoQuaresma Jan 9, 2024
691c028
Move unhealthy to notifications array
BrunoQuaresma Jan 9, 2024
706bbd5
Fix permissions for restart workspace
BrunoQuaresma Jan 9, 2024
d3e68fb
Move dormant notifications to notifications array
BrunoQuaresma Jan 9, 2024
2f1ac83
Structure notification pills
BrunoQuaresma Jan 9, 2024
c334031
Minor style adjustments
BrunoQuaresma Jan 9, 2024
a78d4cf
Remove bottom bar from workspace page
BrunoQuaresma Jan 9, 2024
24c7552
Display notifications under the pills
BrunoQuaresma Jan 9, 2024
b711018
Improve canAutoStart check
BrunoQuaresma Jan 11, 2024
121005c
Move css into a style
BrunoQuaresma Jan 11, 2024
3234d49
Move css into a style
BrunoQuaresma Jan 11, 2024
b30dc44
Remove unecessary boolean
BrunoQuaresma Jan 11, 2024
04994a4
Refactor props
BrunoQuaresma Jan 11, 2024
5ba0765
Improve semantics
BrunoQuaresma Jan 11, 2024
3d0d70b
Merge branch 'bq/move-alert' of https://github.com/coder/coder into b…
BrunoQuaresma Jan 11, 2024
9299c68
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 11, 2024
6d3148b
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 12, 2024
45be26c
Add tests
BrunoQuaresma Jan 12, 2024
d21be38
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 12, 2024
478a333
Fix storybook
BrunoQuaresma Jan 12, 2024
d62833c
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move dormant notifications to notifications array
  • Loading branch information
BrunoQuaresma committed Jan 9, 2024
commit d3e68fb8bd4b5f4a5eb936a47de334597ef99c60
76 changes: 0 additions & 76 deletions site/src/pages/WorkspacePage/DormantWorkspaceBanner.tsx

This file was deleted.

59 changes: 49 additions & 10 deletions site/src/pages/WorkspacePage/WorkspaceNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import AlertTitle from "@mui/material/AlertTitle";
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
import { Template, TemplateVersion, Workspace } from "api/typesGenerated";
import { Alert, AlertDetail, AlertProps } from "components/Alert/Alert";
import { FC, useEffect, useState } from "react";
import { FC, ReactNode, useEffect, useState } from "react";
import { useQuery } from "react-query";
import { WorkspacePermissions } from "./permissions";
import { DormantWorkspaceBanner } from "./DormantWorkspaceBanner";
import dayjs from "dayjs";
import { useIsWorkspaceActionsEnabled } from "components/Dashboard/DashboardProvider";
import formatDistanceToNow from "date-fns/formatDistanceToNow";

type Notification = {
title: string;
severity: AlertProps["severity"];
detail?: string;
detail?: ReactNode;
actions?: { label: string; onClick: () => void }[];
};

Expand Down Expand Up @@ -72,11 +73,15 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
notifications.push({
title: "Workspace is unhealthy",
severity: "warning",
detail: `Your workspace is running but ${
workspace.health.failing_agents.length > 1
? `${workspace.health.failing_agents.length} agents are unhealthy`
: `1 agent is unhealthy`
}.`,
detail: (
<>
Your workspace is running but{" "}
{workspace.health.failing_agents.length > 1
? `${workspace.health.failing_agents.length} agents are unhealthy`
: `1 agent is unhealthy`}
.
</>
),
actions: permissions.updateWorkspace
? [
{
Expand All @@ -88,6 +93,42 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
});
}

// Dormant
const areActionsEnabled = useIsWorkspaceActionsEnabled();
if (areActionsEnabled && workspace.dormant_at) {
const formatDate = (dateStr: string, timestamp: boolean): string => {
const date = new Date(dateStr);
return date.toLocaleDateString(undefined, {
month: "long",
day: "numeric",
year: "numeric",
...(timestamp ? { hour: "numeric", minute: "numeric" } : {}),
});
};
notifications.push({
title: "Workspace is dormant",
severity: "warning",
detail: workspace.deleting_at ? (
<>
This workspace has not been used for{" "}
{formatDistanceToNow(Date.parse(workspace.last_used_at))} and was
marked dormant on {formatDate(workspace.dormant_at, false)}. It is
scheduled to be deleted on {formatDate(workspace.deleting_at, true)}.
To keep it you must activate the workspace.
</>
) : (
<>
This workspace has not been used for{" "}
{formatDistanceToNow(Date.parse(workspace.last_used_at))} and was
marked dormant on {formatDate(workspace.dormant_at, false)}. It is not
scheduled for auto-deletion but will become a candidate if
auto-deletion is enabled on this template. To keep it you must
activate the workspace.
</>
),
});
}

// Pending in Queue
const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false);
// 2023-11-15 - MES - This effect will be called every single render because
Expand Down Expand Up @@ -127,8 +168,6 @@ export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (

return (
<>
<DormantWorkspaceBanner workspace={workspace} />

{showAlertPendingInQueue && (
<Alert severity="info">
<AlertTitle>Workspace build is pending</AlertTitle>
Expand Down