@@ -3,14 +3,12 @@ import React from 'react';
3
3
import { ResponseError } from '../../components/Errors/ResponseError' ;
4
4
import { LoaderWrapper } from '../../components/LoaderWrapper/LoaderWrapper' ;
5
5
import type { RenderControls } from '../../components/PaginatedTable' ;
6
- import type { PaginatedTableData } from '../../components/PaginatedTable/types' ;
7
6
import { TableWithControlsLayout } from '../../components/TableWithControlsLayout/TableWithControlsLayout' ;
8
7
import {
9
8
useCapabilitiesLoaded ,
10
9
useViewerNodesHandlerHasGrouping ,
11
10
} from '../../store/reducers/capabilities/hooks' ;
12
11
import { storageApi } from '../../store/reducers/storage/storage' ;
13
- import type { PreparedStorageNode } from '../../store/reducers/storage/types' ;
14
12
import type { NodesGroupByField } from '../../types/api/nodes' ;
15
13
import { useAutoRefreshInterval } from '../../utils/hooks' ;
16
14
import { useAdditionalNodesProps } from '../../utils/hooks/useAdditionalNodesProps' ;
@@ -27,6 +25,7 @@ import i18n from './i18n';
27
25
import { b , renderPaginatedTableErrorMessage } from './shared' ;
28
26
import type { StorageViewContext } from './types' ;
29
27
import { useStorageQueryParams } from './useStorageQueryParams' ;
28
+ import { useTableCSSVariables } from './utils' ;
30
29
31
30
import './Storage.scss' ;
32
31
@@ -59,9 +58,6 @@ export const PaginatedStorageNodes = (props: PaginatedStorageProps) => {
59
58
return < LoaderWrapper loading = { ! capabilitiesLoaded } > { renderContent ( ) } </ LoaderWrapper > ;
60
59
} ;
61
60
62
- const MAX_SLOTS_CSS_VAR = '--maximum-slots' ;
63
- const MAX_DISKS_CSS_VAR = '--maximum-disks' ;
64
-
65
61
function StorageNodesComponent ( {
66
62
database,
67
63
nodeId,
@@ -80,20 +76,7 @@ function StorageNodesComponent({
80
76
viewContext,
81
77
} ) ;
82
78
83
- const [ tableStyle , setTableStyle ] = React . useState < React . CSSProperties | undefined > ( undefined ) ;
84
-
85
- const handleDataFetched = React . useCallback (
86
- ( data : PaginatedTableData < PreparedStorageNode > ) => {
87
- if ( data ?. columnSettings && ! tableStyle ) {
88
- const { maxSlotsPerDisk, maxDisksPerNode} = data . columnSettings ;
89
- setTableStyle ( {
90
- [ MAX_SLOTS_CSS_VAR ] : maxSlotsPerDisk ,
91
- [ MAX_DISKS_CSS_VAR ] : maxDisksPerNode ,
92
- } as React . CSSProperties ) ;
93
- }
94
- } ,
95
- [ tableStyle ] ,
96
- ) ;
79
+ const { tableStyle, handleDataFetched} = useTableCSSVariables ( ) ;
97
80
98
81
const renderControls : RenderControls = ( { totalEntities, foundEntities, inited} ) => {
99
82
return (
@@ -124,7 +107,7 @@ function StorageNodesComponent({
124
107
columns = { columnsToShow }
125
108
initialEntitiesCount = { initialEntitiesCount }
126
109
tableStyle = { tableStyle }
127
- onDataFetched = { handleDataFetched }
110
+ onDataFetched = { tableStyle ? undefined : handleDataFetched }
128
111
/>
129
112
) ;
130
113
}
@@ -248,20 +231,7 @@ function StorageNodesTableGroupContent({
248
231
columns,
249
232
initialEntitiesCount,
250
233
} : StorageNodesTableGroupContentProps ) {
251
- const [ tableStyle , setTableStyle ] = React . useState < React . CSSProperties | undefined > ( undefined ) ;
252
-
253
- const handleDataFetched = React . useCallback (
254
- ( data : PaginatedTableData < PreparedStorageNode > ) => {
255
- if ( data ?. columnSettings && ! tableStyle ) {
256
- const { maxSlotsPerDisk, maxDisksPerNode} = data . columnSettings ;
257
- setTableStyle ( {
258
- [ MAX_SLOTS_CSS_VAR ] : maxSlotsPerDisk ,
259
- [ MAX_DISKS_CSS_VAR ] : maxDisksPerNode ,
260
- } as React . CSSProperties ) ;
261
- }
262
- } ,
263
- [ tableStyle ] ,
264
- ) ;
234
+ const { tableStyle, handleDataFetched} = useTableCSSVariables ( ) ;
265
235
266
236
return (
267
237
< PaginatedStorageNodesTable
@@ -279,7 +249,7 @@ function StorageNodesTableGroupContent({
279
249
columns = { columns }
280
250
initialEntitiesCount = { initialEntitiesCount }
281
251
tableStyle = { tableStyle }
282
- onDataFetched = { handleDataFetched }
252
+ onDataFetched = { tableStyle ? undefined : handleDataFetched }
283
253
/>
284
254
) ;
285
255
}
0 commit comments