Skip to content

Commit 5d14e80

Browse files
committed
refactor(Healthcheck): rewrite in ts
1 parent 75f9851 commit 5d14e80

File tree

9 files changed

+217
-199
lines changed

9 files changed

+217
-199
lines changed

src/containers/Tenant/Diagnostics/DetailedOverview/DetailedOverview.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import type {EPathType} from '../../../../types/api/schema';
88
//@ts-ignore
99
import Icon from '../../../../components/Icon/Icon';
1010
import Overview from '../Overview/Overview';
11-
//@ts-ignore
12-
import Healthcheck from '../Healthcheck/Healthcheck';
11+
import {Healthcheck} from '../Healthcheck';
1312
//@ts-ignore
1413
import TenantOverview from '../TenantOverview/TenantOverview';
1514

src/containers/Tenant/Diagnostics/Healthcheck/Healthcheck.js

Lines changed: 0 additions & 196 deletions
This file was deleted.

src/containers/Tenant/Diagnostics/Healthcheck/Healthcheck.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
@import '../../../../styles/mixins.scss';
33

44
.healthcheck {
5-
padding: 25px 20px 20px;
5+
&__issues-list {
6+
padding: 25px 20px 20px;
7+
}
68

79
&__issues {
810
overflow-x: hidden;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import {useCallback} from 'react';
2+
import {useDispatch, useSelector} from 'react-redux';
3+
import cn from 'bem-cn-lite';
4+
5+
import {Loader} from '@gravity-ui/uikit';
6+
7+
import {getHealthcheckInfo} from '../../../../store/reducers/healthcheckInfo';
8+
import {useAutofetcher} from '../../../../utils/hooks';
9+
10+
import {IssuesList} from './IssuesList';
11+
import {Preview} from './Preview';
12+
13+
import i18n from './i18n';
14+
import './Healthcheck.scss';
15+
16+
interface HealthcheckProps {
17+
tenant: string;
18+
preview?: boolean;
19+
showMoreHandler?: VoidFunction;
20+
}
21+
22+
const b = cn('healthcheck');
23+
24+
export const Healthcheck = (props: HealthcheckProps) => {
25+
const {
26+
tenant,
27+
preview,
28+
showMoreHandler,
29+
} = props;
30+
31+
const dispatch = useDispatch();
32+
33+
const {data, loading, wasLoaded, error} = useSelector((state: any) => state.healthcheckInfo);
34+
const {autorefresh} = useSelector((state: any) => state.schema);
35+
36+
const fetchHealthcheck = useCallback(() => {
37+
dispatch(getHealthcheckInfo(tenant));
38+
}, [dispatch, tenant]);
39+
40+
useAutofetcher(fetchHealthcheck, [fetchHealthcheck], autorefresh);
41+
42+
const renderContent = () => {
43+
if (error) {
44+
return error.statusText;
45+
}
46+
47+
if (loading && !wasLoaded) {
48+
return (
49+
<div className={b('loader')}>
50+
<Loader size="m" />
51+
</div>
52+
);
53+
}
54+
55+
if (data && data['self_check_result']) {
56+
return preview ? (
57+
<Preview
58+
data={data}
59+
loading={loading}
60+
onShowMore={showMoreHandler}
61+
onUpdate={fetchHealthcheck}
62+
/>
63+
) : (
64+
<IssuesList
65+
data={data}
66+
loading={loading}
67+
onUpdate={fetchHealthcheck}
68+
/>
69+
);
70+
}
71+
72+
return (
73+
<div className="error">{i18n('no-data')}</div>
74+
);
75+
};
76+
77+
return (
78+
<div className={b()}>
79+
{renderContent()}
80+
</div>
81+
);
82+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import cn from 'bem-cn-lite';
2+
3+
import {Button} from '@gravity-ui/uikit';
4+
5+
import IssuesViewer from '../IssuesViewer/IssuesViewer';
6+
7+
import i18n from '../i18n';
8+
9+
const b = cn('healthcheck');
10+
11+
interface IssuesListProps {
12+
data?: any;
13+
loading?: boolean;
14+
onUpdate: VoidFunction;
15+
}
16+
17+
export const IssuesList = (props: IssuesListProps) => {
18+
const {
19+
data,
20+
loading,
21+
onUpdate,
22+
} = props;
23+
24+
if (!data) {
25+
return null;
26+
}
27+
28+
const renderOverviewStatus = () => {
29+
const {self_check_result: selfCheckResult} = data;
30+
const modifier = selfCheckResult.toLowerCase();
31+
32+
return (
33+
<div className={b('self-check-status')}>
34+
<h3 className={b('self-check-status-label')}>{i18n('title.self-check-status')}</h3>
35+
<div className={b('self-check-status-indicator', {[modifier]: true})} />
36+
{selfCheckResult}
37+
<div className={b('self-check-update')}>
38+
<Button size="s" onClick={onUpdate} loading={loading}>
39+
{i18n('label.update')}
40+
</Button>
41+
</div>
42+
</div>
43+
);
44+
};
45+
46+
const renderHealthcheckIssues = () => {
47+
const {issue_log: issueLog} = data;
48+
49+
if (!issueLog) {
50+
return null;
51+
}
52+
53+
return (
54+
<div className={b('issues')}>
55+
<h3>{i18n('title.issues')}</h3>
56+
<IssuesViewer issues={issueLog} />
57+
</div>
58+
);
59+
}
60+
61+
return (
62+
<div className={b('issues-list')}>
63+
{renderOverviewStatus()}
64+
{renderHealthcheckIssues()}
65+
</div>
66+
);
67+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './IssuesList';

0 commit comments

Comments
 (0)