-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDiskGroupsStats.tsx
More file actions
86 lines (76 loc) · 2.98 KB
/
DiskGroupsStats.tsx
File metadata and controls
86 lines (76 loc) · 2.98 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
import type {ProgressTheme} from '@gravity-ui/uikit';
import {DefinitionList, Flex, Progress, Text} from '@gravity-ui/uikit';
import type {DiskErasureGroupsStats} from '../../../../../store/reducers/cluster/types';
import {formatBytes, getBytesSizeUnit} from '../../../../../utils/bytesParsers';
import {cn} from '../../../../../utils/cn';
import {formatNumber} from '../../../../../utils/dataFormatters/dataFormatters';
import type {ProgressStatus} from '../../../../../utils/progress';
import {calculateProgressStatus} from '../../../../../utils/progress';
import i18n from '../../../i18n';
import './DiskGroupsStats.scss';
const b = cn('ydb-disk-groups-stats');
interface GroupsStatsPopupContentProps {
stats: DiskErasureGroupsStats;
storageType: string;
}
const calculatedStatusToProgressTheme: Record<ProgressStatus, ProgressTheme> = {
good: 'success',
warning: 'warning',
danger: 'danger',
};
export function DiskGroupsStats({stats, storageType}: GroupsStatsPopupContentProps) {
const {erasure, allocatedSize, availableSize} = stats;
const sizeToConvert = getBytesSizeUnit(Math.max(allocatedSize, availableSize));
const convertedAllocatedSize = formatBytes({value: allocatedSize, size: sizeToConvert});
const convertedAvailableSize = formatBytes({value: availableSize, size: sizeToConvert});
const usage = Math.floor((allocatedSize / (allocatedSize + availableSize)) * 100);
const info = [
{
name: i18n('erasure'),
content: erasure,
},
{
name: i18n('allocated'),
content: convertedAllocatedSize,
},
{
name: i18n('available'),
content: convertedAvailableSize,
},
{
name: i18n('usage'),
content: (
<Flex gap={2} alignItems="center">
<Progress
theme={
calculatedStatusToProgressTheme[
calculateProgressStatus({fillWidth: usage})
]
}
className={b('progress')}
value={usage}
size="s"
/>
<Text color="secondary">{usage}%</Text>
</Flex>
),
},
];
return (
<Flex direction="column" gap={3} className={b()}>
<Text variant="body-2">
{storageType}{' '}
<Text color="secondary" variant="body-2">
{`${formatNumber(stats.createdGroups)} ${i18n('context_of')} ${formatNumber(stats.totalGroups)}`}
</Text>
</Text>
<DefinitionList nameMaxWidth={160}>
{info.map(({name, content}) => (
<DefinitionList.Item key={name} name={name}>
{content}
</DefinitionList.Item>
))}
</DefinitionList>
</Flex>
);
}