Skip to content

Commit f550258

Browse files
committed
fix: remove eventhandler
1 parent 3331f50 commit f550258

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

src/components/AutoRefreshControl/AutoRefreshControl.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ const b = cn('auto-refresh-control');
1313

1414
interface AutoRefreshControlProps {
1515
className?: string;
16-
onManualRefresh?: () => void;
1716
}
1817

19-
export function AutoRefreshControl({className, onManualRefresh}: AutoRefreshControlProps) {
18+
export function AutoRefreshControl({className}: AutoRefreshControlProps) {
2019
const dispatch = useTypedDispatch();
2120
const [autoRefreshInterval, setAutoRefreshInterval] = useAutoRefreshInterval();
2221
return (
2322
<div className={b(null, className)}>
2423
<Button
2524
view="flat-secondary"
2625
onClick={() => {
27-
dispatch(api.util.invalidateTags(['All']));
28-
onManualRefresh?.();
26+
dispatch(api.util.invalidateTags(['All', 'ManualRefresh']));
2927
}}
3028
extraProps={{'aria-label': i18n('Refresh')}}
3129
>

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,7 @@ function Diagnostics(props: DiagnosticsProps) {
174174
}}
175175
allowNotSelected={true}
176176
/>
177-
<AutoRefreshControl
178-
onManualRefresh={() => {
179-
//this is needed to collect healthcheck if it is disabled by default https://github.com/ydb-platform/ydb-embedded-ui/issues/1889
180-
const event = new CustomEvent('diagnosticsRefresh');
181-
document.dispatchEvent(event);
182-
}}
183-
/>
177+
<AutoRefreshControl />
184178
</div>
185179
</div>
186180
);

src/containers/Tenant/Diagnostics/TenantOverview/Healthcheck/HealthcheckPreview.tsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,13 @@ export function HealthcheckPreview(props: HealthcheckPreviewProps) {
6363
},
6464
);
6565

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]);
66+
const {currentData: manualData, isFetching: isFetchingManually} =
67+
healthcheckApi.useGetManualHealthcheckInfoQuery(
68+
{database: tenantName},
69+
{
70+
skip: !healthcheckPreviewDisabled || metricsTab !== 'healthcheck',
71+
},
72+
);
8673

8774
const loading =
8875
(isFetching && data === undefined) || (isFetchingManually && manualData === undefined);

src/store/reducers/api.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ export const api = createApi({
99
*/
1010
endpoints: () => ({}),
1111
invalidationBehavior: 'immediately',
12-
tagTypes: ['All', 'PDiskData', 'PreviewData', 'StorageData', 'Tablet', 'UserData', 'VDiskData'],
12+
tagTypes: [
13+
'All',
14+
'PDiskData',
15+
'PreviewData',
16+
'StorageData',
17+
'Tablet',
18+
'UserData',
19+
'VDiskData',
20+
'ManualRefresh',
21+
],
1322
});
1423

1524
export const _NEVER = Symbol();

src/store/reducers/healthcheckInfo/healthcheckInfo.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ export const healthcheckApi = api.injectEndpoints({
2525
},
2626
providesTags: ['All'],
2727
}),
28+
getManualHealthcheckInfo: builder.query({
29+
queryFn: async (
30+
{database, maxLevel}: {database: string; maxLevel?: number; disabled?: boolean},
31+
{signal},
32+
) => {
33+
try {
34+
const data = await window.api.viewer.getHealthcheckInfo(
35+
{database, maxLevel},
36+
{signal},
37+
);
38+
return {data};
39+
} catch (error) {
40+
return {error};
41+
}
42+
},
43+
providesTags: ['ManualRefresh'],
44+
}),
2845
}),
2946
overrideExisting: 'throw',
3047
});

0 commit comments

Comments
 (0)