Skip to content

Commit 5e31cfe

Browse files
committed
feat(Storage): show total groups count
1 parent 693a100 commit 5e31cfe

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/containers/Storage/Storage.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
StorageTypes,
2121
setStorageType,
2222
VisibleEntitiesTitles,
23+
getStoragePoolsGroupsCount,
2324
} from '../../store/reducers/storage';
2425
import {getNodesList} from '../../store/reducers/clusterNodes';
2526
import StorageGroups from './StorageGroups/StorageGroups';
@@ -52,6 +53,7 @@ class Storage extends React.Component {
5253
getStorageInfo: PropTypes.func,
5354
setInitialState: PropTypes.func,
5455
flatListStorageEntities: PropTypes.array,
56+
groupsCount: PropTypes.object,
5557
setStorageFilter: PropTypes.func,
5658
setVisibleEntities: PropTypes.func,
5759
visibleEntities: PropTypes.string,
@@ -199,10 +201,44 @@ class Storage extends React.Component {
199201
setStorageType(value);
200202
};
201203

204+
renderEntitiesCount() {
205+
const {
206+
storageType,
207+
groupsCount,
208+
flatListStorageEntities,
209+
loading,
210+
wasLoaded,
211+
} = this.props;
212+
213+
let label = `${storageType === StorageTypes.groups ? 'Groups' : 'Nodes'}: `;
214+
215+
if (loading && !wasLoaded) {
216+
label += '...';
217+
return label;
218+
}
219+
220+
if (storageType === StorageTypes.nodes) {
221+
label += flatListStorageEntities.length;
222+
}
223+
224+
if (storageType === StorageTypes.groups) {
225+
if (groupsCount.total === groupsCount.found) {
226+
label += groupsCount.total;
227+
} else {
228+
label += `${groupsCount.found} out of ${groupsCount.total}`;
229+
}
230+
}
231+
232+
return label;
233+
}
234+
202235
renderControls() {
203-
const {setStorageFilter, visibleEntities, storageType, flatListStorageEntities, loading, wasLoaded} =
204-
this.props;
205-
const showLoader = loading && !wasLoaded;
236+
const {
237+
setStorageFilter,
238+
visibleEntities,
239+
storageType,
240+
} = this.props;
241+
206242
return (
207243
<div className={b('controls')}>
208244
<div className={b('search')}>
@@ -231,9 +267,9 @@ class Storage extends React.Component {
231267
{StorageTypes.nodes}
232268
</RadioButton.Option>
233269
</RadioButton>
234-
<Label theme="info" size="m">{`${
235-
storageType === StorageTypes.groups ? 'Groups' : 'Nodes'
236-
}: ${(showLoader) ? '...' : flatListStorageEntities.length}`}</Label>
270+
<Label theme="info" size="m">
271+
{this.renderEntitiesCount()}
272+
</Label>
237273
</div>
238274
);
239275
}
@@ -270,6 +306,7 @@ function mapStateToProps(state) {
270306

271307
return {
272308
flatListStorageEntities: getFilteredEntities(state),
309+
groupsCount: getStoragePoolsGroupsCount(state),
273310
autorefresh: state.schema.autorefresh,
274311
nodes: getNodesObject(state),
275312
loading,

src/store/reducers/storage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ export function setVisibleEntities(value) {
125125
}
126126

127127
export const getStoragePools = (state) => state.storage.data?.StoragePools;
128+
export const getStoragePoolsGroupsCount = (state) => ({
129+
total: state.storage.data?.TotalGroups || 0,
130+
found: state.storage.data?.FoundGroups || 0,
131+
});
128132
export const getStorageNodes = (state) => state.storage.data?.Nodes;
129133
export const getStorageFilter = (state) => state.storage.filter;
130134
export const getVisibleEntities = (state) => state.storage.visible;

0 commit comments

Comments
 (0)