@@ -11,7 +11,7 @@ import {
1111 useStorageGroupsHandlerAvailable ,
1212} from '../../store/reducers/capabilities/hooks' ;
1313import type { NodesSortParams } from '../../store/reducers/nodes/types' ;
14- import { STORAGE_TYPES , VISIBLE_ENTITIES } from '../../store/reducers/storage/constants' ;
14+ import { VISIBLE_ENTITIES } from '../../store/reducers/storage/constants' ;
1515import {
1616 filterGroups ,
1717 filterNodes ,
@@ -31,7 +31,9 @@ import {NodesUptimeFilterValues, nodesUptimeFilterValuesSchema} from '../../util
3131
3232import { StorageControls } from './StorageControls/StorageControls' ;
3333import { StorageGroups } from './StorageGroups/StorageGroups' ;
34+ import { useStorageGroupsSelectedColumns } from './StorageGroups/columns/hooks' ;
3435import { StorageNodes } from './StorageNodes/StorageNodes' ;
36+ import { useStorageNodesSelectedColumns } from './StorageNodes/columns/hooks' ;
3537import { b } from './shared' ;
3638import { defaultSortNode , getDefaultSortGroup } from './utils' ;
3739
@@ -73,6 +75,9 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
7375 usageFilter : UsageFilterParam ,
7476 } ) ;
7577 const storageType = storageTypeSchema . parse ( queryParams . type ) ;
78+ const isGroups = storageType === 'groups' ;
79+ const isNodes = storageType === 'nodes' ;
80+
7681 const visibleEntities = visibleEntitiesSchema . parse ( queryParams . visible ) ;
7782 const filter = queryParams . search ?? '' ;
7883 const uptimeFilter = nodesUptimeFilterValuesSchema . parse ( queryParams . uptimeFilter ) ;
@@ -90,23 +95,38 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
9095 } ) ;
9196 const groupsSortParams = groupSort . sortOrder ? groupSort : getDefaultSortGroup ( visibleEntities ) ;
9297
98+ const {
99+ columnsToShow : storageNodesColumnsToShow ,
100+ columnsToSelect : storageNodesColumnsToSelect ,
101+ setColumns : setStorageNodesSelectedColumns ,
102+ } = useStorageNodesSelectedColumns ( {
103+ additionalNodesProps,
104+ visibleEntities,
105+ database,
106+ } ) ;
107+
108+ const {
109+ columnsToShow : storageGroupsColumnsToShow ,
110+ columnsToSelect : storageGroupsColumnsToSelect ,
111+ setColumns : setStorageGroupsSelectedColumns ,
112+ } = useStorageGroupsSelectedColumns ( visibleEntities ) ;
113+
93114 const nodesQuery = storageApi . useGetStorageNodesInfoQuery (
94115 { database, with : visibleEntities , node_id : nodeId } ,
95116 {
96- skip : storageType !== STORAGE_TYPES . nodes ,
117+ skip : ! isNodes ,
97118 pollingInterval : autoRefreshInterval ,
98119 } ,
99120 ) ;
100121 const groupsQuery = storageApi . useGetStorageGroupsInfoQuery (
101122 { database, with : visibleEntities , nodeId, shouldUseGroupsHandler : groupsHandlerAvailable } ,
102123 {
103- skip : storageType !== STORAGE_TYPES . groups || ! capabilitiesLoaded ,
124+ skip : ! isGroups || ! capabilitiesLoaded ,
104125 pollingInterval : autoRefreshInterval ,
105126 } ,
106127 ) ;
107128
108- const { currentData, isFetching, error} =
109- storageType === STORAGE_TYPES . nodes ? nodesQuery : groupsQuery ;
129+ const { currentData, isFetching, error} = isNodes ? nodesQuery : groupsQuery ;
110130
111131 const { currentData : { nodes = [ ] } = { } } = nodesQuery ;
112132 const { currentData : { groups = [ ] } = { } } = groupsQuery ;
@@ -160,7 +180,7 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
160180 const renderDataTable = ( ) => {
161181 return (
162182 < React . Fragment >
163- { storageType === STORAGE_TYPES . groups && (
183+ { isGroups ? (
164184 < StorageGroups
165185 key = "groups"
166186 visibleEntities = { visibleEntities }
@@ -169,27 +189,37 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
169189 onShowAll = { ( ) => handleGroupVisibilityChange ( VISIBLE_ENTITIES . all ) }
170190 sort = { groupsSort }
171191 handleSort = { handleGroupsSort }
192+ columns = { storageGroupsColumnsToShow }
172193 />
173- ) }
174- { storageType === STORAGE_TYPES . nodes && (
194+ ) : null }
195+ { isNodes ? (
175196 < StorageNodes
176197 key = "nodes"
177198 visibleEntities = { visibleEntities }
178199 nodesUptimeFilter = { uptimeFilter }
179200 data = { storageNodes }
180201 tableSettings = { DEFAULT_TABLE_SETTINGS }
181202 onShowAll = { handleShowAllNodes }
182- additionalNodesProps = { additionalNodesProps }
183203 sort = { nodesSort }
184204 handleSort = { handleNodesSort }
185- database = { database }
205+ columns = { storageNodesColumnsToShow }
186206 />
187- ) }
207+ ) : null }
188208 </ React . Fragment >
189209 ) ;
190210 } ;
191211
192212 const renderControls = ( ) => {
213+ const entitiesCountCurrent = isGroups ? storageGroups . length : storageNodes . length ;
214+
215+ const columnsToSelect = isGroups
216+ ? storageGroupsColumnsToSelect
217+ : storageNodesColumnsToSelect ;
218+
219+ const handleSelectedColumnsUpdate = isGroups
220+ ? setStorageGroupsSelectedColumns
221+ : setStorageNodesSelectedColumns ;
222+
193223 return (
194224 < StorageControls
195225 searchValue = { filter }
@@ -204,13 +234,11 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
204234 groupsUsageFilter = { usageFilter }
205235 groupsUsageFilterOptions = { usageFilterOptions }
206236 handleGroupsUsageFilterChange = { handleUsageFilterChange }
207- entitiesCountCurrent = {
208- storageType === STORAGE_TYPES . groups
209- ? storageGroups . length
210- : storageNodes . length
211- }
237+ entitiesCountCurrent = { entitiesCountCurrent }
212238 entitiesCountTotal = { entitiesCount . total }
213239 entitiesLoading = { isLoading }
240+ columnsToSelect = { columnsToSelect }
241+ handleSelectedColumnsUpdate = { handleSelectedColumnsUpdate }
214242 />
215243 ) ;
216244 } ;
0 commit comments