1
1
import { type Interpolation , type Theme } from "@emotion/react" ;
2
2
import Box from "@mui/material/Box" ;
3
- import { useQuery } from "react-query" ;
3
+ import { useMutation , useQuery , useQueryClient } from "react-query" ;
4
4
import { getHealth } from "api/api" ;
5
5
import { Loader } from "components/Loader/Loader" ;
6
6
import { useTab } from "hooks" ;
@@ -19,6 +19,10 @@ import {
19
19
import { Stats , StatsItem } from "components/Stats/Stats" ;
20
20
import { createDayString } from "utils/createDayString" ;
21
21
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" ;
25
+ import { health , refreshHealth } from "api/queries/debug" ;
22
26
23
27
const sections = {
24
28
derp : "DERP" ,
@@ -29,11 +33,14 @@ const sections = {
29
33
30
34
export default function HealthPage ( ) {
31
35
const tab = useTab ( "tab" , "derp" ) ;
36
+ const queryClient = useQueryClient ( ) ;
32
37
const { data : healthStatus } = useQuery ( {
33
- queryKey : [ "health" ] ,
34
- queryFn : ( ) => getHealth ( ) ,
35
- refetchInterval : 120_000 ,
38
+ ...health ( ) ,
39
+ refetchInterval : 30_000 ,
36
40
} ) ;
41
+ const { mutate : forceRefresh , isLoading : isRefreshing } = useMutation (
42
+ refreshHealth ( queryClient ) ,
43
+ ) ;
37
44
38
45
return (
39
46
< >
@@ -42,7 +49,12 @@ export default function HealthPage() {
42
49
</ Helmet >
43
50
44
51
{ healthStatus ? (
45
- < HealthPageView healthStatus = { healthStatus } tab = { tab } />
52
+ < HealthPageView
53
+ tab = { tab }
54
+ healthStatus = { healthStatus }
55
+ forceRefresh = { forceRefresh }
56
+ isRefreshing = { isRefreshing }
57
+ />
46
58
) : (
47
59
< Loader />
48
60
) }
@@ -53,9 +65,13 @@ export default function HealthPage() {
53
65
export function HealthPageView ( {
54
66
healthStatus,
55
67
tab,
68
+ forceRefresh,
69
+ isRefreshing,
56
70
} : {
57
71
healthStatus : Awaited < ReturnType < typeof getHealth > > ;
58
72
tab : ReturnType < typeof useTab > ;
73
+ forceRefresh : ( ) => void ;
74
+ isRefreshing : boolean ;
59
75
} ) {
60
76
return (
61
77
< DashboardFullPage >
@@ -109,6 +125,7 @@ export function HealthPageView({
109
125
value = { healthStatus . coder_version }
110
126
/>
111
127
</ Stats >
128
+ < RefreshButton loading = { isRefreshing } handleAction = { forceRefresh } />
112
129
</ FullWidthPageHeader >
113
130
< Box
114
131
sx = { {
@@ -254,3 +271,25 @@ const styles = {
254
271
} ,
255
272
} ,
256
273
} satisfies Record < string , Interpolation < Theme > > ;
274
+
275
+ interface HealthcheckAction {
276
+ handleAction : ( ) => void ;
277
+ loading : boolean ;
278
+ }
279
+
280
+ export const RefreshButton : FC < HealthcheckAction > = ( {
281
+ handleAction,
282
+ loading,
283
+ } ) => {
284
+ return (
285
+ < LoadingButton
286
+ loading = { loading }
287
+ loadingPosition = "start"
288
+ data-testid = "healthcheck-refresh-button"
289
+ startIcon = { < ReplayIcon /> }
290
+ onClick = { handleAction }
291
+ >
292
+ Refresh
293
+ </ LoadingButton >
294
+ ) ;
295
+ } ;
0 commit comments