-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathClusterInfo.tsx
More file actions
129 lines (111 loc) · 4.02 KB
/
ClusterInfo.tsx
File metadata and controls
129 lines (111 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import React from 'react';
import {DefinitionList, Flex, Text} from '@gravity-ui/uikit';
import {ResponseError} from '../../../components/Errors/ResponseError';
import {InfoViewerSkeleton} from '../../../components/InfoViewerSkeleton/InfoViewerSkeleton';
import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon';
import type {ClusterGroupsStats} from '../../../store/reducers/cluster/types';
import type {AdditionalClusterProps} from '../../../types/additionalProps';
import type {TClusterInfo} from '../../../types/api/cluster';
import type {IResponseError} from '../../../types/api/error';
import {formatNumber} from '../../../utils/dataFormatters/dataFormatters';
import i18n from '../i18n';
import {getTotalStorageGroupsUsed} from '../utils';
import {b} from './shared';
import {useClusterLinks} from './utils/useClusterLinks';
import {getInfo, getStorageGroupStats} from './utils/utils';
import './ClusterInfo.scss';
interface ClusterInfoProps {
cluster?: TClusterInfo;
loading?: boolean;
error?: IResponseError | string;
additionalClusterProps?: AdditionalClusterProps;
groupStats?: ClusterGroupsStats;
}
export const ClusterInfo = ({
cluster,
loading,
error,
additionalClusterProps = {},
groupStats = {},
}: ClusterInfoProps) => {
const {info = [], links = []} = additionalClusterProps;
const clusterLinks = useClusterLinks();
const linksList = links.concat(clusterLinks);
const clusterInfo = getInfo(cluster ?? {}, info);
const renderDetails = () => {
if (error && !cluster) {
return null;
}
return (
<DefinitionList nameMaxWidth={200}>
{clusterInfo.map(({label, value}) => {
return (
<DefinitionList.Item key={label} name={label}>
{value}
</DefinitionList.Item>
);
})}
{linksList.length > 0 && (
<DefinitionList.Item name={i18n('title_links')}>
<Flex direction="column" gap={2}>
{linksList.map(({title, url}) => {
return <LinkWithIcon key={title} title={title} url={url} />;
})}
</Flex>
</DefinitionList.Item>
)}
</DefinitionList>
);
};
const renderDetailsContent = () => {
if (loading) {
return <InfoViewerSkeleton className={b('skeleton')} rows={4} />;
}
return renderDetails();
};
const renderDetailSection = () => {
return (
<InfoSection>
<Text as="div" variant="subheader-2" className={b('section-title')}>
{i18n('title_details')}
</Text>
{renderDetailsContent()}
</InfoSection>
);
};
const total = getTotalStorageGroupsUsed(groupStats);
const renderGroupsInfoSection = () => {
const stats = getStorageGroupStats(groupStats);
if (loading) {
return null;
}
return (
<InfoSection>
<Text as="div" variant="subheader-2" className={b('section-title')}>
{i18n('title_storage-groups')}{' '}
<Text variant="subheader-2" color="secondary">
{formatNumber(total)}
</Text>
</Text>
<Flex gap={2}>{stats}</Flex>
</InfoSection>
);
};
return (
<Flex gap={4} direction="column" className={b()}>
{error ? <ResponseError error={error} className={b('error')} /> : null}
{renderDetailSection()}
{renderGroupsInfoSection()}
</Flex>
);
};
interface InfoSectionProps {
children: React.ReactNode;
}
function InfoSection({children}: InfoSectionProps) {
return (
<Flex direction="column" gap={3}>
{children}
</Flex>
);
}