1
+ import React from 'react' ;
2
+
1
3
import {
2
4
CircleCheck ,
3
5
CircleInfo ,
@@ -15,7 +17,7 @@ import {useClusterBaseInfo} from '../../../../../store/reducers/cluster/cluster'
15
17
import { healthcheckApi } from '../../../../../store/reducers/healthcheckInfo/healthcheckInfo' ;
16
18
import { SelfCheckResult } from '../../../../../types/api/healthcheck' ;
17
19
import { cn } from '../../../../../utils/cn' ;
18
- import { useAutoRefreshInterval } from '../../../../../utils/hooks' ;
20
+ import { useAutoRefreshInterval , useTypedSelector } from '../../../../../utils/hooks' ;
19
21
20
22
import i18n from './i18n' ;
21
23
@@ -42,8 +44,11 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
42
44
const { tenantName, active} = props ;
43
45
const [ autoRefreshInterval ] = useAutoRefreshInterval ( ) ;
44
46
47
+ const { metricsTab} = useTypedSelector ( ( state ) => state . tenant ) ;
48
+
45
49
const { name} = useClusterBaseInfo ( ) ;
46
- const healthcheckPreviewAutorefreshDisabled = name === 'ydb_ru' ;
50
+
51
+ const healthcheckPreviewDisabled = name === 'ydb_ru' ;
47
52
48
53
const {
49
54
currentData : data ,
@@ -53,23 +58,44 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
53
58
{ database : tenantName } ,
54
59
{
55
60
//FIXME https://github.com/ydb-platform/ydb-embedded-ui/issues/1889
56
- pollingInterval : healthcheckPreviewAutorefreshDisabled
57
- ? undefined
58
- : autoRefreshInterval ,
61
+ pollingInterval : healthcheckPreviewDisabled ? undefined : autoRefreshInterval ,
62
+ skip : healthcheckPreviewDisabled ,
59
63
} ,
60
64
) ;
61
65
62
- const loading = isFetching && data === undefined ;
66
+ const [ getHealthcheckQuery , { currentData : manualData , isFetching : isFetchingManually } ] =
67
+ healthcheckApi . useLazyGetHealthcheckInfoQuery ( ) ;
68
+
69
+ React . useEffect ( ( ) => {
70
+ if ( metricsTab === 'healthcheck' && healthcheckPreviewDisabled ) {
71
+ getHealthcheckQuery ( { database : tenantName } ) ;
72
+ }
73
+ } , [ metricsTab , healthcheckPreviewDisabled , tenantName , getHealthcheckQuery ] ) ;
74
+
75
+ React . useEffect ( ( ) => {
76
+ const fetchHealthcheck = ( ) => {
77
+ if ( healthcheckPreviewDisabled ) {
78
+ getHealthcheckQuery ( { database : tenantName } ) ;
79
+ }
80
+ } ;
81
+ document . addEventListener ( 'diagnosticsRefresh' , fetchHealthcheck ) ;
82
+ return ( ) => {
83
+ document . removeEventListener ( 'diagnosticsRefresh' , fetchHealthcheck ) ;
84
+ } ;
85
+ } , [ tenantName , healthcheckPreviewDisabled , getHealthcheckQuery ] ) ;
86
+
87
+ const loading =
88
+ ( isFetching && data === undefined ) || ( isFetchingManually && manualData === undefined ) ;
63
89
64
90
const renderHeader = ( ) => {
65
91
return (
66
92
< div className = { b ( 'preview-header' ) } >
67
93
< div className = { b ( 'preview-title-wrapper' ) } >
68
94
< div className = { b ( 'preview-title' ) } > { i18n ( 'title.healthcheck' ) } </ div >
69
95
{ /* FIXME https://github.com/ydb-platform/ydb-embedded-ui/issues/1889 */ }
70
- { autoRefreshInterval && healthcheckPreviewAutorefreshDisabled ? (
96
+ { healthcheckPreviewDisabled ? (
71
97
< Popover
72
- content = { 'Autorefresh is disabled. Please update healthcheck manually.' }
98
+ content = { 'Healthcheck is disabled. Please update healthcheck manually.' }
73
99
placement = { [ 'top' ] }
74
100
className = { b ( 'icon-wrapper' ) }
75
101
>
@@ -96,7 +122,8 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
96
122
return < Loader size = "m" /> ;
97
123
}
98
124
99
- const selfCheckResult = data ?. self_check_result || SelfCheckResult . UNSPECIFIED ;
125
+ const selfCheckResult =
126
+ data ?. self_check_result || manualData ?. self_check_result || SelfCheckResult . UNSPECIFIED ;
100
127
const modifier = selfCheckResult . toLowerCase ( ) ;
101
128
return (
102
129
< div className = { b ( 'preview-content' ) } >
0 commit comments