@@ -11,7 +11,7 @@ import {
11
11
useStorageGroupsHandlerAvailable ,
12
12
} from '../../store/reducers/capabilities/hooks' ;
13
13
import 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' ;
15
15
import {
16
16
filterGroups ,
17
17
filterNodes ,
@@ -31,7 +31,9 @@ import {NodesUptimeFilterValues, nodesUptimeFilterValuesSchema} from '../../util
31
31
32
32
import { StorageControls } from './StorageControls/StorageControls' ;
33
33
import { StorageGroups } from './StorageGroups/StorageGroups' ;
34
+ import { useStorageGroupsSelectedColumns } from './StorageGroups/columns/hooks' ;
34
35
import { StorageNodes } from './StorageNodes/StorageNodes' ;
36
+ import { useStorageNodesSelectedColumns } from './StorageNodes/columns/hooks' ;
35
37
import { b } from './shared' ;
36
38
import { defaultSortNode , getDefaultSortGroup } from './utils' ;
37
39
@@ -73,6 +75,9 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
73
75
usageFilter : UsageFilterParam ,
74
76
} ) ;
75
77
const storageType = storageTypeSchema . parse ( queryParams . type ) ;
78
+ const isGroups = storageType === 'groups' ;
79
+ const isNodes = storageType === 'nodes' ;
80
+
76
81
const visibleEntities = visibleEntitiesSchema . parse ( queryParams . visible ) ;
77
82
const filter = queryParams . search ?? '' ;
78
83
const uptimeFilter = nodesUptimeFilterValuesSchema . parse ( queryParams . uptimeFilter ) ;
@@ -90,23 +95,38 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
90
95
} ) ;
91
96
const groupsSortParams = groupSort . sortOrder ? groupSort : getDefaultSortGroup ( visibleEntities ) ;
92
97
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
+
93
114
const nodesQuery = storageApi . useGetStorageNodesInfoQuery (
94
115
{ database, with : visibleEntities , node_id : nodeId } ,
95
116
{
96
- skip : storageType !== STORAGE_TYPES . nodes ,
117
+ skip : ! isNodes ,
97
118
pollingInterval : autoRefreshInterval ,
98
119
} ,
99
120
) ;
100
121
const groupsQuery = storageApi . useGetStorageGroupsInfoQuery (
101
122
{ database, with : visibleEntities , nodeId, shouldUseGroupsHandler : groupsHandlerAvailable } ,
102
123
{
103
- skip : storageType !== STORAGE_TYPES . groups || ! capabilitiesLoaded ,
124
+ skip : ! isGroups || ! capabilitiesLoaded ,
104
125
pollingInterval : autoRefreshInterval ,
105
126
} ,
106
127
) ;
107
128
108
- const { currentData, isFetching, error} =
109
- storageType === STORAGE_TYPES . nodes ? nodesQuery : groupsQuery ;
129
+ const { currentData, isFetching, error} = isNodes ? nodesQuery : groupsQuery ;
110
130
111
131
const { currentData : { nodes = [ ] } = { } } = nodesQuery ;
112
132
const { currentData : { groups = [ ] } = { } } = groupsQuery ;
@@ -160,7 +180,7 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
160
180
const renderDataTable = ( ) => {
161
181
return (
162
182
< React . Fragment >
163
- { storageType === STORAGE_TYPES . groups && (
183
+ { isGroups ? (
164
184
< StorageGroups
165
185
key = "groups"
166
186
visibleEntities = { visibleEntities }
@@ -169,27 +189,37 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
169
189
onShowAll = { ( ) => handleGroupVisibilityChange ( VISIBLE_ENTITIES . all ) }
170
190
sort = { groupsSort }
171
191
handleSort = { handleGroupsSort }
192
+ columns = { storageGroupsColumnsToShow }
172
193
/>
173
- ) }
174
- { storageType === STORAGE_TYPES . nodes && (
194
+ ) : null }
195
+ { isNodes ? (
175
196
< StorageNodes
176
197
key = "nodes"
177
198
visibleEntities = { visibleEntities }
178
199
nodesUptimeFilter = { uptimeFilter }
179
200
data = { storageNodes }
180
201
tableSettings = { DEFAULT_TABLE_SETTINGS }
181
202
onShowAll = { handleShowAllNodes }
182
- additionalNodesProps = { additionalNodesProps }
183
203
sort = { nodesSort }
184
204
handleSort = { handleNodesSort }
185
- database = { database }
205
+ columns = { storageNodesColumnsToShow }
186
206
/>
187
- ) }
207
+ ) : null }
188
208
</ React . Fragment >
189
209
) ;
190
210
} ;
191
211
192
212
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
+
193
223
return (
194
224
< StorageControls
195
225
searchValue = { filter }
@@ -204,13 +234,11 @@ export const Storage = ({additionalNodesProps, database, nodeId}: StorageProps)
204
234
groupsUsageFilter = { usageFilter }
205
235
groupsUsageFilterOptions = { usageFilterOptions }
206
236
handleGroupsUsageFilterChange = { handleUsageFilterChange }
207
- entitiesCountCurrent = {
208
- storageType === STORAGE_TYPES . groups
209
- ? storageGroups . length
210
- : storageNodes . length
211
- }
237
+ entitiesCountCurrent = { entitiesCountCurrent }
212
238
entitiesCountTotal = { entitiesCount . total }
213
239
entitiesLoading = { isLoading }
240
+ columnsToSelect = { columnsToSelect }
241
+ handleSelectedColumnsUpdate = { handleSelectedColumnsUpdate }
214
242
/>
215
243
) ;
216
244
} ;
0 commit comments