Skip to content

Commit 2a5fd1b

Browse files
committed
fix: storage groups
1 parent 4d0eb9f commit 2a5fd1b

File tree

1 file changed

+84
-49
lines changed

1 file changed

+84
-49
lines changed

src/containers/Storage/PaginatedStorageGroups.tsx

Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import React from 'react';
22

33
import {ResponseError} from '../../components/Errors/ResponseError/ResponseError';
44
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
5-
import type {RenderControls} from '../../components/PaginatedTable';
5+
import {
6+
PaginatedTableProvider,
7+
usePaginatedTableState,
8+
} from '../../components/PaginatedTable/PaginatedTableContext';
69
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
710
import {
811
useCapabilitiesLoaded,
@@ -24,6 +27,33 @@ import {useStorageQueryParams} from './useStorageQueryParams';
2427

2528
import './Storage.scss';
2629

30+
// Wrapper component to connect StorageGroupsControls with the PaginatedTable state
31+
function StorageGroupsControlsWithTableState({
32+
withTypeSelector,
33+
withGroupBySelect,
34+
columnsToSelect,
35+
handleSelectedColumnsUpdate,
36+
}: {
37+
withTypeSelector?: boolean;
38+
withGroupBySelect?: boolean;
39+
columnsToSelect: any[];
40+
handleSelectedColumnsUpdate: (updated: any[]) => void;
41+
}) {
42+
const {tableState} = usePaginatedTableState();
43+
44+
return (
45+
<StorageGroupsControls
46+
withTypeSelector={withTypeSelector}
47+
withGroupBySelect={withGroupBySelect}
48+
entitiesCountCurrent={tableState.foundEntities}
49+
entitiesCountTotal={tableState.totalEntities}
50+
entitiesLoading={tableState.isInitialLoad}
51+
columnsToSelect={columnsToSelect}
52+
handleSelectedColumnsUpdate={handleSelectedColumnsUpdate}
53+
/>
54+
);
55+
}
56+
2757
export function PaginatedStorageGroups(props: PaginatedStorageProps) {
2858
const {storageGroupsGroupByParam, visibleEntities, handleShowAllGroups} =
2959
useStorageQueryParams();
@@ -68,35 +98,34 @@ function StorageGroupsComponent({
6898
viewContext,
6999
});
70100

71-
const renderControls: RenderControls = ({totalEntities, foundEntities, inited}) => {
72-
return (
73-
<StorageGroupsControls
74-
withTypeSelector
75-
withGroupBySelect={storageGroupsHandlerHasGroupping}
76-
entitiesCountCurrent={foundEntities}
77-
entitiesCountTotal={totalEntities}
78-
entitiesLoading={!inited}
79-
columnsToSelect={columnsToSelect}
80-
handleSelectedColumnsUpdate={setColumns}
81-
/>
82-
);
83-
};
84-
85101
return (
86-
<PaginatedStorageGroupsTable
87-
database={database}
88-
nodeId={nodeId}
89-
groupId={groupId}
90-
pDiskId={pDiskId}
91-
searchValue={searchValue}
92-
visibleEntities={visibleEntities}
93-
onShowAll={handleShowAllGroups}
94-
parentRef={parentRef}
95-
renderControls={renderControls}
96-
renderErrorMessage={renderPaginatedTableErrorMessage}
97-
columns={columnsToShow}
98-
initialEntitiesCount={initialEntitiesCount}
99-
/>
102+
<PaginatedTableProvider>
103+
<TableWithControlsLayout>
104+
<TableWithControlsLayout.Controls>
105+
<StorageGroupsControlsWithTableState
106+
withTypeSelector
107+
withGroupBySelect={storageGroupsHandlerHasGroupping}
108+
columnsToSelect={columnsToSelect}
109+
handleSelectedColumnsUpdate={setColumns}
110+
/>
111+
</TableWithControlsLayout.Controls>
112+
<TableWithControlsLayout.Table>
113+
<PaginatedStorageGroupsTable
114+
database={database}
115+
nodeId={nodeId}
116+
groupId={groupId}
117+
pDiskId={pDiskId}
118+
searchValue={searchValue}
119+
visibleEntities={visibleEntities}
120+
onShowAll={handleShowAllGroups}
121+
parentRef={parentRef}
122+
renderErrorMessage={renderPaginatedTableErrorMessage}
123+
columns={columnsToShow}
124+
initialEntitiesCount={initialEntitiesCount}
125+
/>
126+
</TableWithControlsLayout.Table>
127+
</TableWithControlsLayout>
128+
</PaginatedTableProvider>
100129
);
101130
}
102131

@@ -138,19 +167,16 @@ function GroupedStorageGroupsComponent({
138167

139168
const {expandedGroups, setIsGroupExpanded} = useExpandedGroups(tableGroups);
140169

141-
const renderControls = () => {
142-
return (
143-
<StorageGroupsControls
144-
withTypeSelector
145-
withGroupBySelect
146-
entitiesCountCurrent={found}
147-
entitiesCountTotal={total}
148-
entitiesLoading={isLoading}
149-
columnsToSelect={columnsToSelect}
150-
handleSelectedColumnsUpdate={setColumns}
151-
/>
152-
);
153-
};
170+
// Initialize the table state with the API data
171+
const initialState = React.useMemo(
172+
() => ({
173+
foundEntities: found,
174+
totalEntities: total,
175+
isInitialLoad: isLoading,
176+
sortParams: undefined,
177+
}),
178+
[found, total, isLoading],
179+
);
154180

155181
const renderGroups = () => {
156182
if (tableGroups?.length) {
@@ -190,12 +216,21 @@ function GroupedStorageGroupsComponent({
190216
};
191217

192218
return (
193-
<TableWithControlsLayout>
194-
<TableWithControlsLayout.Controls>{renderControls()}</TableWithControlsLayout.Controls>
195-
{error ? <ResponseError error={error} /> : null}
196-
<TableWithControlsLayout.Table loading={isLoading} className={b('groups-wrapper')}>
197-
{renderGroups()}
198-
</TableWithControlsLayout.Table>
199-
</TableWithControlsLayout>
219+
<PaginatedTableProvider initialState={initialState}>
220+
<TableWithControlsLayout>
221+
<TableWithControlsLayout.Controls>
222+
<StorageGroupsControlsWithTableState
223+
withTypeSelector
224+
withGroupBySelect
225+
columnsToSelect={columnsToSelect}
226+
handleSelectedColumnsUpdate={setColumns}
227+
/>
228+
</TableWithControlsLayout.Controls>
229+
{error ? <ResponseError error={error} /> : null}
230+
<TableWithControlsLayout.Table loading={isLoading} className={b('groups-wrapper')}>
231+
{renderGroups()}
232+
</TableWithControlsLayout.Table>
233+
</TableWithControlsLayout>
234+
</PaginatedTableProvider>
200235
);
201236
}

0 commit comments

Comments
 (0)