From 4732f085888504f9a2d86bfc8803bb49dbe576f2 Mon Sep 17 00:00:00 2001 From: brettkolodny Date: Wed, 19 Feb 2025 10:54:35 -0500 Subject: [PATCH] fix: show an error when a user doesn't have permission to view the health page (#16580) --- site/src/pages/HealthPage/HealthLayout.tsx | 281 +++++++++++---------- 1 file changed, 148 insertions(+), 133 deletions(-) diff --git a/site/src/pages/HealthPage/HealthLayout.tsx b/site/src/pages/HealthPage/HealthLayout.tsx index 2c566500d8..33ca8cbe31 100644 --- a/site/src/pages/HealthPage/HealthLayout.tsx +++ b/site/src/pages/HealthPage/HealthLayout.tsx @@ -7,6 +7,7 @@ import IconButton from "@mui/material/IconButton"; import Tooltip from "@mui/material/Tooltip"; import { health, refreshHealth } from "api/queries/debug"; import type { HealthSeverity } from "api/typesGenerated"; +import { ErrorAlert } from "components/Alert/ErrorAlert"; import { Loader } from "components/Loader/Loader"; import { type ClassName, useClassName } from "hooks/useClassName"; import kebabCase from "lodash/fp/kebabCase"; @@ -22,7 +23,11 @@ import { HealthIcon } from "./Content"; export const HealthLayout: FC = () => { const theme = useTheme(); const queryClient = useQueryClient(); - const { data: healthStatus } = useQuery({ + const { + data: healthStatus, + isLoading, + error, + } = useQuery({ ...health(), refetchInterval: 30_000, }); @@ -42,161 +47,171 @@ export const HealthLayout: FC = () => { const link = useClassName(classNames.link, []); const activeLink = useClassName(classNames.activeLink, []); + if (isLoading || !healthStatus) { + return ( +
+ +
+ ); + } + + if (error) { + return ( +
+ +
+ ); + } + return ( <> {pageTitle("Health")} - {healthStatus ? ( - + +
-
-
-
- +
+
+ - - { - forceRefresh(); - }} - > - {isRefreshing ? ( - - ) : ( - - )} - - -
-
- {healthStatus.healthy ? "Healthy" : "Unhealthy"} -
-
- {healthStatus.healthy - ? Object.keys(visibleSections).some((key) => { - const section = - healthStatus[key as keyof typeof visibleSections]; - return ( - section.warnings && section.warnings.length > 0 - ); - }) - ? "All systems operational, but performance might be degraded" - : "All systems operational" - : "Some issues have been detected"} -
+ + { + forceRefresh(); + }} + > + {isRefreshing ? ( + + ) : ( + + )} + +
- -
- Last check - - {createDayString(healthStatus.time)} - +
+ {healthStatus.healthy ? "Healthy" : "Unhealthy"}
- -
- Version - - {healthStatus.coder_version} - +
+ {healthStatus.healthy + ? Object.keys(visibleSections).some((key) => { + const section = + healthStatus[key as keyof typeof visibleSections]; + return section.warnings && section.warnings.length > 0; + }) + ? "All systems operational, but performance might be degraded" + : "All systems operational" + : "Some issues have been detected"}
-
+
+ + -
- -
- }> - - -
+ )} + + ); + })} +
- - ) : ( - - )} + +
+ }> + + +
+
+ ); };