|
| 1 | +import {Flex} from '@gravity-ui/uikit'; |
| 2 | + |
| 3 | +import type {PreparedStorageGroup} from '../../store/reducers/storage/types'; |
| 4 | +import {valueIsDefined} from '../../utils'; |
| 5 | +import {formatStorageValuesToGb} from '../../utils/dataFormatters/dataFormatters'; |
| 6 | +import {formatToMs} from '../../utils/timeParsers'; |
| 7 | +import {bytesToSpeed} from '../../utils/utils'; |
| 8 | +import {EntityStatus} from '../EntityStatus/EntityStatus'; |
| 9 | +import {InfoViewer} from '../InfoViewer'; |
| 10 | +import type {InfoViewerProps} from '../InfoViewer/InfoViewer'; |
| 11 | +import {ProgressViewer} from '../ProgressViewer/ProgressViewer'; |
| 12 | + |
| 13 | +import {storageGroupInfoKeyset} from './i18n'; |
| 14 | + |
| 15 | +interface StorageGroupInfoProps extends Omit<InfoViewerProps, 'info'> { |
| 16 | + data?: PreparedStorageGroup; |
| 17 | + className?: string; |
| 18 | +} |
| 19 | + |
| 20 | +// eslint-disable-next-line complexity |
| 21 | +export function StorageGroupInfo({data, className, ...infoViewerProps}: StorageGroupInfoProps) { |
| 22 | + const { |
| 23 | + Encryption, |
| 24 | + Overall, |
| 25 | + DiskSpace, |
| 26 | + MediaType, |
| 27 | + ErasureSpecies, |
| 28 | + Used, |
| 29 | + Limit, |
| 30 | + Usage, |
| 31 | + Read, |
| 32 | + Write, |
| 33 | + GroupGeneration, |
| 34 | + Latency, |
| 35 | + AllocationUnits, |
| 36 | + State, |
| 37 | + MissingDisks, |
| 38 | + Available, |
| 39 | + LatencyPutTabletLog, |
| 40 | + LatencyPutUserData, |
| 41 | + LatencyGetFast, |
| 42 | + } = data || {}; |
| 43 | + |
| 44 | + const storageGroupInfoFirstColumn = []; |
| 45 | + |
| 46 | + if (valueIsDefined(GroupGeneration)) { |
| 47 | + storageGroupInfoFirstColumn.push({ |
| 48 | + label: storageGroupInfoKeyset('group-generation'), |
| 49 | + value: GroupGeneration, |
| 50 | + }); |
| 51 | + } |
| 52 | + if (valueIsDefined(ErasureSpecies)) { |
| 53 | + storageGroupInfoFirstColumn.push({ |
| 54 | + label: storageGroupInfoKeyset('erasure-species'), |
| 55 | + value: ErasureSpecies, |
| 56 | + }); |
| 57 | + } |
| 58 | + if (valueIsDefined(MediaType)) { |
| 59 | + storageGroupInfoFirstColumn.push({ |
| 60 | + label: storageGroupInfoKeyset('media-type'), |
| 61 | + value: MediaType, |
| 62 | + }); |
| 63 | + } |
| 64 | + if (valueIsDefined(Encryption)) { |
| 65 | + storageGroupInfoFirstColumn.push({ |
| 66 | + label: storageGroupInfoKeyset('encryption'), |
| 67 | + value: Encryption ? storageGroupInfoKeyset('yes') : storageGroupInfoKeyset('no'), |
| 68 | + }); |
| 69 | + } |
| 70 | + if (valueIsDefined(Overall)) { |
| 71 | + storageGroupInfoFirstColumn.push({ |
| 72 | + label: storageGroupInfoKeyset('overall'), |
| 73 | + value: <EntityStatus status={Overall} />, |
| 74 | + }); |
| 75 | + } |
| 76 | + if (valueIsDefined(State)) { |
| 77 | + storageGroupInfoFirstColumn.push({label: storageGroupInfoKeyset('state'), value: State}); |
| 78 | + } |
| 79 | + if (valueIsDefined(MissingDisks)) { |
| 80 | + storageGroupInfoFirstColumn.push({ |
| 81 | + label: storageGroupInfoKeyset('missing-disks'), |
| 82 | + value: MissingDisks, |
| 83 | + }); |
| 84 | + } |
| 85 | + |
| 86 | + const storageGroupInfoSecondColumn = []; |
| 87 | + |
| 88 | + if (valueIsDefined(Used) && valueIsDefined(Limit)) { |
| 89 | + storageGroupInfoSecondColumn.push({ |
| 90 | + label: storageGroupInfoKeyset('used-space'), |
| 91 | + value: ( |
| 92 | + <ProgressViewer |
| 93 | + value={Number(Used)} |
| 94 | + capacity={Number(Limit)} |
| 95 | + formatValues={formatStorageValuesToGb} |
| 96 | + colorizeProgress={true} |
| 97 | + /> |
| 98 | + ), |
| 99 | + }); |
| 100 | + } |
| 101 | + if (valueIsDefined(Available)) { |
| 102 | + storageGroupInfoSecondColumn.push({ |
| 103 | + label: storageGroupInfoKeyset('available'), |
| 104 | + value: formatStorageValuesToGb(Number(Available)), |
| 105 | + }); |
| 106 | + } |
| 107 | + if (valueIsDefined(Usage)) { |
| 108 | + storageGroupInfoSecondColumn.push({ |
| 109 | + label: storageGroupInfoKeyset('usage'), |
| 110 | + value: `${Usage.toFixed(2)}%`, |
| 111 | + }); |
| 112 | + } |
| 113 | + if (valueIsDefined(DiskSpace)) { |
| 114 | + storageGroupInfoSecondColumn.push({ |
| 115 | + label: storageGroupInfoKeyset('disk-space'), |
| 116 | + value: <EntityStatus status={DiskSpace} />, |
| 117 | + }); |
| 118 | + } |
| 119 | + if (valueIsDefined(Latency)) { |
| 120 | + storageGroupInfoSecondColumn.push({ |
| 121 | + label: storageGroupInfoKeyset('latency'), |
| 122 | + value: <EntityStatus status={Latency} />, |
| 123 | + }); |
| 124 | + } |
| 125 | + if (valueIsDefined(LatencyPutTabletLog)) { |
| 126 | + storageGroupInfoSecondColumn.push({ |
| 127 | + label: storageGroupInfoKeyset('latency-put-tablet-log'), |
| 128 | + value: formatToMs(LatencyPutTabletLog), |
| 129 | + }); |
| 130 | + } |
| 131 | + if (valueIsDefined(LatencyPutUserData)) { |
| 132 | + storageGroupInfoSecondColumn.push({ |
| 133 | + label: storageGroupInfoKeyset('latency-put-user-data'), |
| 134 | + value: formatToMs(LatencyPutUserData), |
| 135 | + }); |
| 136 | + } |
| 137 | + if (valueIsDefined(LatencyGetFast)) { |
| 138 | + storageGroupInfoSecondColumn.push({ |
| 139 | + label: storageGroupInfoKeyset('latency-get-fast'), |
| 140 | + value: formatToMs(LatencyGetFast), |
| 141 | + }); |
| 142 | + } |
| 143 | + if (valueIsDefined(AllocationUnits)) { |
| 144 | + storageGroupInfoSecondColumn.push({ |
| 145 | + label: storageGroupInfoKeyset('allocation-units'), |
| 146 | + value: AllocationUnits, |
| 147 | + }); |
| 148 | + } |
| 149 | + if (valueIsDefined(Read)) { |
| 150 | + storageGroupInfoSecondColumn.push({ |
| 151 | + label: storageGroupInfoKeyset('read-throughput'), |
| 152 | + value: bytesToSpeed(Number(Read)), |
| 153 | + }); |
| 154 | + } |
| 155 | + if (valueIsDefined(Write)) { |
| 156 | + storageGroupInfoSecondColumn.push({ |
| 157 | + label: storageGroupInfoKeyset('write-throughput'), |
| 158 | + value: bytesToSpeed(Number(Write)), |
| 159 | + }); |
| 160 | + } |
| 161 | + |
| 162 | + return ( |
| 163 | + <Flex className={className} gap={2} direction="row" wrap> |
| 164 | + <InfoViewer info={storageGroupInfoFirstColumn} {...infoViewerProps} /> |
| 165 | + <InfoViewer info={storageGroupInfoSecondColumn} {...infoViewerProps} /> |
| 166 | + </Flex> |
| 167 | + ); |
| 168 | +} |
0 commit comments