From 42f6b716f23b357d245645213763437aac24d3f7 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Mon, 17 Feb 2025 14:00:51 +0100 Subject: [PATCH] fix: add link to troubleshooting (#16592) Fixes: https://github.com/coder/coder/issues/14933 --- .../WorkspaceNotifications/Notifications.tsx | 5 ++- .../WorkspaceNotifications.tsx | 44 ++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/site/src/pages/WorkspacePage/WorkspaceNotifications/Notifications.tsx b/site/src/pages/WorkspacePage/WorkspaceNotifications/Notifications.tsx index d7220e7028..24fae9d4b0 100644 --- a/site/src/pages/WorkspacePage/WorkspaceNotifications/Notifications.tsx +++ b/site/src/pages/WorkspacePage/WorkspaceNotifications/Notifications.tsx @@ -100,7 +100,10 @@ export const NotificationActionButton: FC = (props) => { variant="text" css={{ textDecoration: "underline", - padding: 0, + paddingLeft: 0, + paddingRight: 8, + paddingTop: 0, + paddingBottom: 0, height: "auto", minWidth: "auto", "&:hover": { background: "none", textDecoration: "underline" }, diff --git a/site/src/pages/WorkspacePage/WorkspaceNotifications/WorkspaceNotifications.tsx b/site/src/pages/WorkspacePage/WorkspaceNotifications/WorkspaceNotifications.tsx index bcab68a9a5..cf4631b34d 100644 --- a/site/src/pages/WorkspacePage/WorkspaceNotifications/WorkspaceNotifications.tsx +++ b/site/src/pages/WorkspacePage/WorkspaceNotifications/WorkspaceNotifications.tsx @@ -2,7 +2,12 @@ import type { Interpolation, Theme } from "@emotion/react"; import InfoOutlined from "@mui/icons-material/InfoOutlined"; import WarningRounded from "@mui/icons-material/WarningRounded"; import { workspaceResolveAutostart } from "api/queries/workspaceQuota"; -import type { Template, TemplateVersion, Workspace } from "api/typesGenerated"; +import type { + Template, + TemplateVersion, + Workspace, + WorkspaceBuild, +} from "api/typesGenerated"; import { MemoizedInlineMarkdown } from "components/Markdown/Markdown"; import formatDistanceToNow from "date-fns/formatDistanceToNow"; import dayjs from "dayjs"; @@ -82,6 +87,9 @@ export const WorkspaceNotifications: FC = ({ workspace.latest_build.status === "running" && !workspace.health.healthy ) { + const troubleshootingURL = findTroubleshootingURL(workspace.latest_build); + const hasActions = permissions.updateWorkspace || troubleshootingURL; + notifications.push({ title: "Workspace is unhealthy", severity: "warning", @@ -94,10 +102,21 @@ export const WorkspaceNotifications: FC = ({ . ), - actions: permissions.updateWorkspace ? ( - - Restart - + actions: hasActions ? ( + <> + {permissions.updateWorkspace && ( + + Restart + + )} + {troubleshootingURL && ( + window.open(troubleshootingURL, "_blank")} + > + Troubleshooting + + )} + ) : undefined, }); } @@ -254,3 +273,18 @@ const styles = { gap: 12, }, } satisfies Record>; + +const findTroubleshootingURL = ( + workspaceBuild: WorkspaceBuild, +): string | undefined => { + for (const resource of workspaceBuild.resources) { + if (resource.agents) { + for (const agent of resource.agents) { + if (agent.troubleshooting_url) { + return agent.troubleshooting_url; + } + } + } + } + return undefined; +};