@@ -3,14 +3,12 @@ import React from 'react';
33import { ResponseError } from '../../components/Errors/ResponseError' ;
44import { LoaderWrapper } from '../../components/LoaderWrapper/LoaderWrapper' ;
55import type { RenderControls } from '../../components/PaginatedTable' ;
6- import type { PaginatedTableData } from '../../components/PaginatedTable/types' ;
76import { TableWithControlsLayout } from '../../components/TableWithControlsLayout/TableWithControlsLayout' ;
87import {
98 useCapabilitiesLoaded ,
109 useViewerNodesHandlerHasGrouping ,
1110} from '../../store/reducers/capabilities/hooks' ;
1211import { storageApi } from '../../store/reducers/storage/storage' ;
13- import type { PreparedStorageNode } from '../../store/reducers/storage/types' ;
1412import type { NodesGroupByField } from '../../types/api/nodes' ;
1513import { useAutoRefreshInterval } from '../../utils/hooks' ;
1614import { useAdditionalNodesProps } from '../../utils/hooks/useAdditionalNodesProps' ;
@@ -27,6 +25,7 @@ import i18n from './i18n';
2725import { b , renderPaginatedTableErrorMessage } from './shared' ;
2826import type { StorageViewContext } from './types' ;
2927import { useStorageQueryParams } from './useStorageQueryParams' ;
28+ import { useTableCSSVariables } from './utils' ;
3029
3130import './Storage.scss' ;
3231
@@ -59,9 +58,6 @@ export const PaginatedStorageNodes = (props: PaginatedStorageProps) => {
5958 return < LoaderWrapper loading = { ! capabilitiesLoaded } > { renderContent ( ) } </ LoaderWrapper > ;
6059} ;
6160
62- const MAX_SLOTS_CSS_VAR = '--maximum-slots' ;
63- const MAX_DISKS_CSS_VAR = '--maximum-disks' ;
64-
6561function StorageNodesComponent ( {
6662 database,
6763 nodeId,
@@ -80,20 +76,7 @@ function StorageNodesComponent({
8076 viewContext,
8177 } ) ;
8278
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 ( ) ;
9780
9881 const renderControls : RenderControls = ( { totalEntities, foundEntities, inited} ) => {
9982 return (
@@ -124,7 +107,7 @@ function StorageNodesComponent({
124107 columns = { columnsToShow }
125108 initialEntitiesCount = { initialEntitiesCount }
126109 tableStyle = { tableStyle }
127- onDataFetched = { handleDataFetched }
110+ onDataFetched = { tableStyle ? undefined : handleDataFetched }
128111 />
129112 ) ;
130113}
@@ -252,20 +235,7 @@ function StorageNodesTableGroupContent({
252235 columns,
253236 initialEntitiesCount,
254237} : StorageNodesTableGroupContentProps ) {
255- const [ tableStyle , setTableStyle ] = React . useState < React . CSSProperties | undefined > ( undefined ) ;
256-
257- const handleDataFetched = React . useCallback (
258- ( data : PaginatedTableData < PreparedStorageNode > ) => {
259- if ( data ?. columnSettings && ! tableStyle ) {
260- const { maxSlotsPerDisk, maxDisksPerNode} = data . columnSettings ;
261- setTableStyle ( {
262- [ MAX_SLOTS_CSS_VAR ] : maxSlotsPerDisk ,
263- [ MAX_DISKS_CSS_VAR ] : maxDisksPerNode ,
264- } as React . CSSProperties ) ;
265- }
266- } ,
267- [ tableStyle ] ,
268- ) ;
238+ const { tableStyle, handleDataFetched} = useTableCSSVariables ( ) ;
269239
270240 return (
271241 < PaginatedStorageNodesTable
@@ -283,7 +253,7 @@ function StorageNodesTableGroupContent({
283253 columns = { columns }
284254 initialEntitiesCount = { initialEntitiesCount }
285255 tableStyle = { tableStyle }
286- onDataFetched = { handleDataFetched }
256+ onDataFetched = { tableStyle ? undefined : handleDataFetched }
287257 />
288258 ) ;
289259}
0 commit comments