1- import _ from 'lodash' ;
21import cn from 'bem-cn-lite' ;
32
43import DataTable , { Column , Settings , SortOrder } from '@gravity-ui/react-data-table' ;
54import { Icon , Label , Popover , PopoverBehavior } from '@gravity-ui/uikit' ;
65
76import type { NodesMap } from '../../../types/store/nodesList' ;
8- import type { TVDiskStateInfo } from '../../../types/api/vdisk' ;
9- import type { VisibleEntities } from '../../../store/reducers/storage/types' ;
7+ import type { PreparedStorageGroup , VisibleEntities } from '../../../store/reducers/storage/types' ;
108
119import { VISIBLE_ENTITIES } from '../../../store/reducers/storage/constants' ;
1210import { bytesToGB , bytesToSpeed } from '../../../utils/utils' ;
@@ -43,7 +41,7 @@ type TableColumnsIdsKeys = keyof typeof TableColumnsIds;
4341type TableColumnsIdsValues = typeof TableColumnsIds [ TableColumnsIdsKeys ] ;
4442
4543interface StorageGroupsProps {
46- data : any ;
44+ data : PreparedStorageGroup [ ] ;
4745 nodes ?: NodesMap ;
4846 tableSettings : Settings ;
4947 visibleEntities : VisibleEntities ;
@@ -93,25 +91,25 @@ function setSortOrder(visibleEntities: VisibleEntities): SortOrder | undefined {
9391 }
9492}
9593
96- function StorageGroups ( {
94+ export function StorageGroups ( {
9795 data,
9896 tableSettings,
9997 visibleEntities,
10098 nodes,
10199 onShowAll,
102100} : StorageGroupsProps ) {
103- const allColumns : Column < any > [ ] = [
101+ const allColumns : Column < PreparedStorageGroup > [ ] = [
104102 {
105103 name : TableColumnsIds . PoolName ,
106104 header : tableColumnsNames [ TableColumnsIds . PoolName ] ,
107105 width : 250 ,
108- render : ( { value } ) => {
109- const splitted = ( value as string ) ?. split ( '/' ) ;
106+ render : ( { row } ) => {
107+ const splitted = row . PoolName ?. split ( '/' ) ;
110108 return (
111109 < div className = { b ( 'pool-name-wrapper' ) } >
112110 { splitted && (
113111 < Popover
114- content = { value as string }
112+ content = { row . PoolName }
115113 placement = { [ 'right' ] }
116114 behavior = { PopoverBehavior . Immediate }
117115 >
@@ -129,9 +127,9 @@ function StorageGroups({
129127 name : TableColumnsIds . Type ,
130128 header : tableColumnsNames [ TableColumnsIds . Type ] ,
131129 // prettier-ignore
132- render : ( { value , row} ) => (
130+ render : ( { row} ) => (
133131 < >
134- < Label > { ( value as string ) || '—' } </ Label >
132+ < Label > { row . Type || '—' } </ Label >
135133 { ' ' }
136134 { row . Encryption && (
137135 < Popover
@@ -157,8 +155,12 @@ function StorageGroups({
157155 name : TableColumnsIds . Missing ,
158156 header : tableColumnsNames [ TableColumnsIds . Missing ] ,
159157 width : 100 ,
160- render : ( { value, row} ) =>
161- value ? < Label theme = { getDegradedSeverity ( row ) } > Degraded: { value } </ Label > : '-' ,
158+ render : ( { row} ) =>
159+ row . Missing ? (
160+ < Label theme = { getDegradedSeverity ( row ) } > Degraded: { row . Missing } </ Label >
161+ ) : (
162+ '-'
163+ ) ,
162164 align : DataTable . LEFT ,
163165 defaultOrder : DataTable . DESCENDING ,
164166 } ,
@@ -189,42 +191,44 @@ function StorageGroups({
189191 name : TableColumnsIds . GroupID ,
190192 header : tableColumnsNames [ TableColumnsIds . GroupID ] ,
191193 width : 130 ,
192- render : ( { value } ) => {
193- return < span className = { b ( 'group-id' ) } > { value as number } </ span > ;
194+ render : ( { row } ) => {
195+ return < span className = { b ( 'group-id' ) } > { row . GroupID } </ span > ;
194196 } ,
195197 align : DataTable . RIGHT ,
196198 } ,
197199 {
198200 name : TableColumnsIds . Used ,
199201 header : tableColumnsNames [ TableColumnsIds . Used ] ,
200202 width : 100 ,
201- render : ( { value } ) => {
202- return bytesToGB ( value , true ) ;
203+ render : ( { row } ) => {
204+ return bytesToGB ( row . Used , true ) ;
203205 } ,
204206 align : DataTable . RIGHT ,
205207 } ,
206208 {
207209 name : TableColumnsIds . Limit ,
208210 header : tableColumnsNames [ TableColumnsIds . Limit ] ,
209211 width : 100 ,
210- render : ( { value } ) => {
211- return bytesToGB ( value ) ;
212+ render : ( { row } ) => {
213+ return bytesToGB ( row . Limit ) ;
212214 } ,
213215 align : DataTable . RIGHT ,
214216 } ,
215217 {
216218 name : TableColumnsIds . UsedSpaceFlag ,
217219 header : tableColumnsNames [ TableColumnsIds . UsedSpaceFlag ] ,
218220 width : 110 ,
219- render : ( { value} ) => {
220- const val = value as number ;
221+ render : ( { row} ) => {
222+ const value = row . UsedSpaceFlag ;
223+
221224 let color = 'Red' ;
222- if ( val < 100 ) {
225+
226+ if ( value < 100 ) {
223227 color = 'Green' ;
224- } else if ( val < 10000 ) {
228+ } else if ( value < 10000 ) {
225229 color = 'Yellow' ;
226- } else if ( val < 1000000 ) {
227- value = 'Orange' ;
230+ } else if ( value < 1000000 ) {
231+ color = 'Orange' ;
228232 }
229233 return < EntityStatus status = { color } /> ;
230234 } ,
@@ -235,32 +239,35 @@ function StorageGroups({
235239 name : TableColumnsIds . Read ,
236240 header : tableColumnsNames [ TableColumnsIds . Read ] ,
237241 width : 100 ,
238- render : ( { value } ) => {
239- return value ? bytesToSpeed ( value ) : '-' ;
242+ render : ( { row } ) => {
243+ return row . Read ? bytesToSpeed ( row . Read ) : '-' ;
240244 } ,
241245 align : DataTable . RIGHT ,
242246 } ,
243247 {
244248 name : TableColumnsIds . Write ,
245249 header : tableColumnsNames [ TableColumnsIds . Write ] ,
246250 width : 100 ,
247- render : ( { value } ) => {
248- return value ? bytesToSpeed ( value ) : '-' ;
251+ render : ( { row } ) => {
252+ return row . Write ? bytesToSpeed ( row . Write ) : '-' ;
249253 } ,
250254 align : DataTable . RIGHT ,
251255 } ,
252256 {
253257 name : TableColumnsIds . VDisks ,
254258 className : b ( 'vdisks-column' ) ,
255259 header : tableColumnsNames [ TableColumnsIds . VDisks ] ,
256- render : ( { value } ) => (
260+ render : ( { row } ) => (
257261 < div className = { b ( 'vdisks-wrapper' ) } >
258- { _ . map ( value as TVDiskStateInfo [ ] , ( el ) => {
259- const donors = el . Donors ;
262+ { row . VDisks ?. map ( ( vDisk ) => {
263+ const donors = vDisk . Donors ;
260264
261265 return donors && donors . length > 0 ? (
262- < Stack className = { b ( 'vdisks-item' ) } key = { stringifyVdiskId ( el . VDiskId ) } >
263- < VDisk data = { el } nodes = { nodes } />
266+ < Stack
267+ className = { b ( 'vdisks-item' ) }
268+ key = { stringifyVdiskId ( vDisk . VDiskId ) }
269+ >
270+ < VDisk data = { vDisk } nodes = { nodes } />
264271 { donors . map ( ( donor ) => {
265272 const isFullData = isFullVDiskData ( donor ) ;
266273
@@ -277,8 +284,8 @@ function StorageGroups({
277284 } ) }
278285 </ Stack >
279286 ) : (
280- < div className = { b ( 'vdisks-item' ) } key = { stringifyVdiskId ( el . VDiskId ) } >
281- < VDisk data = { el } nodes = { nodes } />
287+ < div className = { b ( 'vdisks-item' ) } key = { stringifyVdiskId ( vDisk . VDiskId ) } >
288+ < VDisk data = { vDisk } nodes = { nodes } />
282289 </ div >
283290 ) ;
284291 } ) }
@@ -330,7 +337,7 @@ function StorageGroups({
330337
331338 return data ? (
332339 < DataTable
333- key = { visibleEntities as string }
340+ key = { visibleEntities }
334341 theme = "yandex-cloud"
335342 data = { data }
336343 columns = { columns }
@@ -340,5 +347,3 @@ function StorageGroups({
340347 />
341348 ) : null ;
342349}
343-
344- export default StorageGroups ;
0 commit comments