fix: add link to troubleshooting (#16592)

Fixes: https://github.com/coder/coder/issues/14933
This commit is contained in:
Marcin Tojek
2025-02-17 14:00:51 +01:00
committed by GitHub
parent e39f39ee20
commit 42f6b716f2
2 changed files with 43 additions and 6 deletions
@@ -100,7 +100,10 @@ export const NotificationActionButton: FC<ButtonProps> = (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" },
@@ -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<WorkspaceNotificationsProps> = ({
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<WorkspaceNotificationsProps> = ({
.
</>
),
actions: permissions.updateWorkspace ? (
<NotificationActionButton onClick={onRestartWorkspace}>
Restart
</NotificationActionButton>
actions: hasActions ? (
<>
{permissions.updateWorkspace && (
<NotificationActionButton onClick={onRestartWorkspace}>
Restart
</NotificationActionButton>
)}
{troubleshootingURL && (
<NotificationActionButton
onClick={() => window.open(troubleshootingURL, "_blank")}
>
Troubleshooting
</NotificationActionButton>
)}
</>
) : undefined,
});
}
@@ -254,3 +273,18 @@ const styles = {
gap: 12,
},
} satisfies Record<string, Interpolation<Theme>>;
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;
};