Skip to content

Commit e804f42

Browse files
committed
wip: feat(site): add refresh button on health page
1 parent 3dd35e0 commit e804f42

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

site/src/api/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,9 +1565,10 @@ export const getInsightsTemplate = async (
15651565
return response.data;
15661566
};
15671567

1568-
export const getHealth = async () => {
1568+
export const getHealth = async (force: boolean = false) => {
1569+
const params = new URLSearchParams({ force: force.toString() });
15691570
const response = await axios.get<TypesGen.HealthcheckReport>(
1570-
"/api/v2/debug/health",
1571+
`/api/v2/debug/health?${params}`,
15711572
);
15721573
return response.data;
15731574
};

site/src/api/queries/deployment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const deploymentStats = () => {
2424
export const health = () => {
2525
return {
2626
queryKey: ["deployment", "health"],
27-
queryFn: API.getHealth,
27+
queryFn: () => API.getHealth(false),
2828
};
2929
};
3030

site/src/pages/HealthPage/HealthPage.tsx

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Interpolation, type Theme } from "@emotion/react";
22
import Box from "@mui/material/Box";
3-
import { useQuery } from "react-query";
3+
import { useQuery, useQueryClient } from "react-query";
44
import { getHealth } from "api/api";
55
import { Loader } from "components/Loader/Loader";
66
import { useTab } from "hooks";
@@ -19,6 +19,9 @@ import {
1919
import { Stats, StatsItem } from "components/Stats/Stats";
2020
import { createDayString } from "utils/createDayString";
2121
import { DashboardFullPage } from "components/Dashboard/DashboardLayout";
22+
import { LoadingButton } from "@mui/lab";
23+
import ReplayIcon from "@mui/icons-material/Replay";
24+
import { FC } from "react";
2225

2326
const sections = {
2427
derp: "DERP",
@@ -29,10 +32,16 @@ const sections = {
2932

3033
export default function HealthPage() {
3134
const tab = useTab("tab", "derp");
35+
const queryClient = useQueryClient();
36+
const forceRefresh = async () => {
37+
await queryClient.invalidateQueries(["health"]);
38+
}
3239
const { data: healthStatus } = useQuery({
3340
queryKey: ["health"],
34-
queryFn: () => getHealth(),
35-
refetchInterval: 120_000,
41+
// TODO: We don't want to set force=true each time.
42+
// Only if the "refresh" button is clicked.
43+
queryFn: async () => getHealth(true),
44+
refetchInterval: 30_000,
3645
});
3746

3847
return (
@@ -42,7 +51,7 @@ export default function HealthPage() {
4251
</Helmet>
4352

4453
{healthStatus ? (
45-
<HealthPageView healthStatus={healthStatus} tab={tab} />
54+
<HealthPageView healthStatus={healthStatus} tab={tab} forceRefresh={forceRefresh} />
4655
) : (
4756
<Loader />
4857
)}
@@ -53,9 +62,11 @@ export default function HealthPage() {
5362
export function HealthPageView({
5463
healthStatus,
5564
tab,
65+
forceRefresh,
5666
}: {
5767
healthStatus: Awaited<ReturnType<typeof getHealth>>;
5868
tab: ReturnType<typeof useTab>;
69+
forceRefresh: () => Promise<void>;
5970
}) {
6071
return (
6172
<DashboardFullPage>
@@ -103,6 +114,15 @@ export function HealthPageView({
103114
value={healthStatus.coder_version}
104115
/>
105116
</Stats>
117+
<RefreshButton
118+
loading={false}
119+
handleAction={async () => {
120+
await forceRefresh().catch((e) => {
121+
// handle error
122+
console.log("error forcing refresh: "+ e)
123+
})
124+
}}
125+
/>
106126
</FullWidthPageHeader>
107127
<Box
108128
sx={{
@@ -237,3 +257,25 @@ const styles = {
237257
},
238258
},
239259
} satisfies Record<string, Interpolation<Theme>>;
260+
261+
interface HealthcheckAction {
262+
handleAction: () => void;
263+
loading: boolean;
264+
}
265+
266+
export const RefreshButton: FC<HealthcheckAction> = ({
267+
handleAction,
268+
loading,
269+
}) => {
270+
return (
271+
<LoadingButton
272+
loading={loading}
273+
loadingPosition="start"
274+
data-testid="healthcheck-refresh-button"
275+
startIcon={<ReplayIcon />}
276+
onClick={handleAction}
277+
>
278+
{loading ? <>Refreshing&hellip;</> : <>Refresh</>}
279+
</LoadingButton>
280+
);
281+
};

0 commit comments

Comments
 (0)