|
| 1 | +import {Flex} from '@gravity-ui/uikit'; |
| 2 | + |
1 | 3 | import type {PreparedNode} from '../../store/reducers/node/types';
|
2 | 4 | import {cn} from '../../utils/cn';
|
3 |
| -import {LOAD_AVERAGE_TIME_INTERVALS} from '../../utils/constants'; |
| 5 | +import {useNodeDeveloperUIHref} from '../../utils/hooks/useNodeDeveloperUIHref'; |
4 | 6 | import {InfoViewer} from '../InfoViewer/InfoViewer';
|
5 | 7 | import type {InfoViewerItem} from '../InfoViewer/InfoViewer';
|
| 8 | +import {LinkWithIcon} from '../LinkWithIcon/LinkWithIcon'; |
6 | 9 | import {PoolUsage} from '../PoolUsage/PoolUsage';
|
7 | 10 | import {ProgressViewer} from '../ProgressViewer/ProgressViewer';
|
8 | 11 | import {NodeUptime} from '../UptimeViewer/UptimeViewer';
|
9 | 12 |
|
| 13 | +import i18n from './i18n'; |
| 14 | + |
10 | 15 | import './FullNodeViewer.scss';
|
11 | 16 |
|
12 | 17 | const b = cn('full-node-viewer');
|
13 | 18 |
|
14 | 19 | interface FullNodeViewerProps {
|
15 |
| - node: PreparedNode | undefined; |
| 20 | + node?: PreparedNode; |
16 | 21 | className?: string;
|
17 | 22 | }
|
| 23 | +const getLoadAverageIntervalTitle = (index: number) => { |
| 24 | + return [i18n('la-interval-1m'), i18n('la-interval-5m'), i18n('la-interval-15m')][index]; |
| 25 | +}; |
18 | 26 |
|
19 | 27 | export const FullNodeViewer = ({node, className}: FullNodeViewerProps) => {
|
20 |
| - const endpointsInfo = node?.Endpoints?.map(({Name, Address}) => ({ |
21 |
| - label: Name, |
22 |
| - value: Address, |
23 |
| - })); |
| 28 | + const developerUIHref = useNodeDeveloperUIHref(node); |
24 | 29 |
|
25 | 30 | const commonInfo: InfoViewerItem[] = [];
|
26 | 31 |
|
27 |
| - // Do not add DB field for static nodes (they have no Tenants) |
28 | 32 | if (node?.Tenants?.length) {
|
29 |
| - commonInfo.push({label: 'Database', value: node.Tenants[0]}); |
| 33 | + commonInfo.push({label: i18n('database'), value: node.Tenants[0]}); |
30 | 34 | }
|
31 | 35 |
|
32 | 36 | commonInfo.push(
|
33 |
| - {label: 'Version', value: node?.Version}, |
| 37 | + {label: i18n('version'), value: node?.Version}, |
34 | 38 | {
|
35 |
| - label: 'Uptime', |
| 39 | + label: i18n('uptime'), |
36 | 40 | value: <NodeUptime StartTime={node?.StartTime} DisconnectTime={node?.DisconnectTime} />,
|
37 | 41 | },
|
38 |
| - {label: 'DC', value: node?.DataCenterDescription || node?.DC}, |
39 |
| - {label: 'Rack', value: node?.Rack}, |
| 42 | + {label: i18n('dc'), value: node?.DataCenterDescription || node?.DC}, |
40 | 43 | );
|
41 | 44 |
|
| 45 | + if (node?.Rack) { |
| 46 | + commonInfo.push({label: i18n('rack'), value: node?.Rack}); |
| 47 | + } |
| 48 | + |
| 49 | + if (developerUIHref) { |
| 50 | + commonInfo.push({ |
| 51 | + label: i18n('links'), |
| 52 | + value: <LinkWithIcon url={developerUIHref} title={i18n('developer-ui')} />, |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + const endpointsInfo = node?.Endpoints?.map(({Name, Address}) => ({ |
| 57 | + label: Name, |
| 58 | + value: Address, |
| 59 | + })); |
| 60 | + |
42 | 61 | const averageInfo = node?.LoadAveragePercents?.map((load, loadIndex) => ({
|
43 |
| - label: LOAD_AVERAGE_TIME_INTERVALS[loadIndex], |
| 62 | + label: getLoadAverageIntervalTitle(loadIndex), |
44 | 63 | value: (
|
45 | 64 | <ProgressViewer value={load} percents={true} colorizeProgress={true} capacity={100} />
|
46 | 65 | ),
|
47 | 66 | }));
|
48 | 67 |
|
| 68 | + if (!node) { |
| 69 | + return <div className="error">{i18n('no-data')}</div>; |
| 70 | + } |
| 71 | + |
49 | 72 | return (
|
50 |
| - <div className={`${b()} ${className}`}> |
51 |
| - {node ? ( |
52 |
| - <div className={b('common-info')}> |
53 |
| - <div> |
54 |
| - <div className={b('section-title')}>Pools</div> |
55 |
| - <div className={b('section', {pools: true})}> |
56 |
| - {node?.PoolStats?.map((pool, poolIndex) => ( |
57 |
| - <PoolUsage key={poolIndex} data={pool} /> |
58 |
| - ))} |
59 |
| - </div> |
60 |
| - </div> |
| 73 | + <div className={b(null, className)}> |
| 74 | + <Flex wrap gap={2}> |
| 75 | + <Flex direction="column" gap={2}> |
| 76 | + <InfoViewer |
| 77 | + title={i18n('title.common-info')} |
| 78 | + className={b('section')} |
| 79 | + info={commonInfo} |
| 80 | + /> |
61 | 81 |
|
62 | 82 | {endpointsInfo && endpointsInfo.length && (
|
63 | 83 | <InfoViewer
|
64 |
| - title="Endpoints" |
| 84 | + title={i18n('title.endpoints')} |
65 | 85 | className={b('section')}
|
66 | 86 | info={endpointsInfo}
|
67 | 87 | />
|
68 | 88 | )}
|
| 89 | + </Flex> |
69 | 90 |
|
70 |
| - <InfoViewer title="Common info" className={b('section')} info={commonInfo} /> |
| 91 | + <Flex direction="column" gap={2}> |
| 92 | + <div> |
| 93 | + <div className={b('section-title')}>{i18n('title.pools')}</div> |
| 94 | + <div className={b('section', {pools: true})}> |
| 95 | + {node?.PoolStats?.map((pool, poolIndex) => ( |
| 96 | + <PoolUsage key={poolIndex} data={pool} /> |
| 97 | + ))} |
| 98 | + </div> |
| 99 | + </div> |
71 | 100 |
|
72 | 101 | <InfoViewer
|
73 |
| - title="Load average" |
| 102 | + title={i18n('title.load-average')} |
74 | 103 | className={b('section', {average: true})}
|
75 | 104 | info={averageInfo}
|
76 | 105 | />
|
77 |
| - </div> |
78 |
| - ) : ( |
79 |
| - <div className="error">no data</div> |
80 |
| - )} |
| 106 | + </Flex> |
| 107 | + </Flex> |
81 | 108 | </div>
|
82 | 109 | );
|
83 | 110 | };
|
0 commit comments