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 { 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,9 @@ 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" ;
22
25
23
26
const sections = {
24
27
derp : "DERP" ,
@@ -29,10 +32,16 @@ const sections = {
29
32
30
33
export default function HealthPage ( ) {
31
34
const tab = useTab ( "tab" , "derp" ) ;
35
+ const queryClient = useQueryClient ( ) ;
36
+ const forceRefresh = async ( ) => {
37
+ await queryClient . invalidateQueries ( [ "health" ] ) ;
38
+ }
32
39
const { data : healthStatus } = useQuery ( {
33
40
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 ,
36
45
} ) ;
37
46
38
47
return (
@@ -42,7 +51,7 @@ export default function HealthPage() {
42
51
</ Helmet >
43
52
44
53
{ healthStatus ? (
45
- < HealthPageView healthStatus = { healthStatus } tab = { tab } />
54
+ < HealthPageView healthStatus = { healthStatus } tab = { tab } forceRefresh = { forceRefresh } />
46
55
) : (
47
56
< Loader />
48
57
) }
@@ -53,9 +62,11 @@ export default function HealthPage() {
53
62
export function HealthPageView ( {
54
63
healthStatus,
55
64
tab,
65
+ forceRefresh,
56
66
} : {
57
67
healthStatus : Awaited < ReturnType < typeof getHealth > > ;
58
68
tab : ReturnType < typeof useTab > ;
69
+ forceRefresh : ( ) => Promise < void > ;
59
70
} ) {
60
71
return (
61
72
< DashboardFullPage >
@@ -103,6 +114,15 @@ export function HealthPageView({
103
114
value = { healthStatus . coder_version }
104
115
/>
105
116
</ 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
+ />
106
126
</ FullWidthPageHeader >
107
127
< Box
108
128
sx = { {
@@ -237,3 +257,25 @@ const styles = {
237
257
} ,
238
258
} ,
239
259
} 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…</ > : < > Refresh</ > }
279
+ </ LoadingButton >
280
+ ) ;
281
+ } ;
0 commit comments