Skip to content

Commit b2c55af

Browse files
refactor: migrate storage reducer to ts (#450)
1 parent 7f98e44 commit b2c55af

File tree

8 files changed

+585
-429
lines changed

8 files changed

+585
-429
lines changed

src/containers/Storage/PDisk/PDisk.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import {InternalLink} from '../../../components/InternalLink';
55
import {Stack} from '../../../components/Stack/Stack';
66

77
import routes, {createHref} from '../../../routes';
8-
import {getVDisksForPDisk} from '../../../store/reducers/storage/storage';
8+
import {selectVDisksForPDisk} from '../../../store/reducers/storage/selectors';
99
import {TPDiskStateInfo, TPDiskState} from '../../../types/api/pdisk';
10-
import {TVDiskStateInfo} from '../../../types/api/vdisk';
1110
import {stringifyVdiskId} from '../../../utils';
1211
import {useTypedSelector} from '../../../utils/hooks';
1312
import {getPDiskType} from '../../../utils/pdisk';
@@ -58,11 +57,7 @@ export const PDisk = ({nodeId, data: rawData = {}}: PDiskProps) => {
5857
// NodeId in data is required for the popup
5958
const data = useMemo(() => ({...rawData, NodeId: nodeId}), [rawData, nodeId]);
6059

61-
const vdisks: TVDiskStateInfo[] | undefined = useTypedSelector((state) =>
62-
// @ts-expect-error selector is correct, but js infers broken type
63-
// unignore after rewriting reducer in ts
64-
getVDisksForPDisk(state, nodeId, data.PDiskId),
65-
);
60+
const vdisks = useTypedSelector((state) => selectVDisksForPDisk(state, nodeId, data.PDiskId));
6661

6762
const [severity, setSeverity] = useState(getStateSeverity(data.State));
6863
const [isPopupVisible, setIsPopupVisible] = useState(false);

src/containers/Storage/Storage.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ import {EntitiesCount} from '../../components/EntitiesCount';
1616
import {
1717
getStorageInfo,
1818
setInitialState,
19-
getFilteredEntities,
2019
setVisibleEntities,
2120
setStorageFilter,
2221
setUsageFilter,
2322
setStorageType,
2423
setNodesUptimeFilter,
2524
setDataWasNotLoaded,
26-
getStoragePoolsGroupsCount,
27-
getStorageNodesCount,
28-
getUsageFilterOptions,
2925
} from '../../store/reducers/storage/storage';
26+
import {
27+
selectFilteredGroups,
28+
selectFilteredNodes,
29+
selectStorageNodesCount,
30+
selectStorageGroupsCount,
31+
selectUsageFilterOptions,
32+
} from '../../store/reducers/storage/selectors';
3033
import {VISIBLE_ENTITIES, STORAGE_TYPES} from '../../store/reducers/storage/constants';
3134
import {getNodesList, selectNodesMap} from '../../store/reducers/nodesList';
3235
import StorageGroups from './StorageGroups/StorageGroups';
@@ -54,7 +57,8 @@ class Storage extends React.Component {
5457
database: PropTypes.bool,
5558
getStorageInfo: PropTypes.func,
5659
setInitialState: PropTypes.func,
57-
flatListStorageEntities: PropTypes.array,
60+
storageNodes: PropTypes.array,
61+
storageGroups: PropTypes.array,
5862
groupsCount: PropTypes.object,
5963
nodesCount: PropTypes.object,
6064
setStorageFilter: PropTypes.func,
@@ -166,7 +170,8 @@ class Storage extends React.Component {
166170

167171
renderDataTable() {
168172
const {
169-
flatListStorageEntities,
173+
storageNodes,
174+
storageGroups,
170175
visibleEntities,
171176
nodesUptimeFilter,
172177
nodes,
@@ -179,7 +184,7 @@ class Storage extends React.Component {
179184
{storageType === STORAGE_TYPES.groups && (
180185
<StorageGroups
181186
visibleEntities={visibleEntities}
182-
data={flatListStorageEntities}
187+
data={storageGroups}
183188
tableSettings={tableSettings}
184189
nodes={nodes}
185190
onShowAll={() => this.onGroupVisibilityChange(VISIBLE_ENTITIES.all)}
@@ -189,7 +194,7 @@ class Storage extends React.Component {
189194
<StorageNodes
190195
visibleEntities={visibleEntities}
191196
nodesUptimeFilter={nodesUptimeFilter}
192-
data={flatListStorageEntities}
197+
data={storageNodes}
193198
tableSettings={tableSettings}
194199
onShowAll={this.onShowAllNodes}
195200
additionalNodesInfo={additionalNodesInfo}
@@ -219,18 +224,27 @@ class Storage extends React.Component {
219224
};
220225

221226
renderEntitiesCount() {
222-
const {storageType, groupsCount, nodesCount, flatListStorageEntities, loading, wasLoaded} =
223-
this.props;
227+
const {
228+
storageType,
229+
groupsCount,
230+
nodesCount,
231+
storageGroups,
232+
storageNodes,
233+
loading,
234+
wasLoaded,
235+
} = this.props;
224236

225237
const entityName = storageType === STORAGE_TYPES.groups ? 'Groups' : 'Nodes';
226238
const count = storageType === STORAGE_TYPES.groups ? groupsCount : nodesCount;
239+
const current =
240+
storageType === STORAGE_TYPES.groups ? storageGroups.length : storageNodes.length;
227241

228242
return (
229243
<EntitiesCount
230244
label={entityName}
231245
loading={loading && !wasLoaded}
232246
total={count.total}
233-
current={flatListStorageEntities.length}
247+
current={current}
234248
/>
235249
);
236250
}
@@ -318,11 +332,12 @@ function mapStateToProps(state) {
318332
} = state.storage;
319333

320334
return {
321-
flatListStorageEntities: getFilteredEntities(state),
322-
groupsCount: getStoragePoolsGroupsCount(state),
335+
storageNodes: selectFilteredNodes(state),
336+
storageGroups: selectFilteredGroups(state),
337+
nodesCount: selectStorageNodesCount(state),
338+
groupsCount: selectStorageGroupsCount(state),
323339
autorefresh: state.schema.autorefresh,
324340
nodes: selectNodesMap(state),
325-
nodesCount: getStorageNodesCount(state),
326341
loading,
327342
wasLoaded,
328343
error,
@@ -331,7 +346,7 @@ function mapStateToProps(state) {
331346
filter,
332347
usageFilter,
333348
nodesUptimeFilter,
334-
usageFilterOptions: getUsageFilterOptions(state),
349+
usageFilterOptions: selectUsageFilterOptions(state),
335350
};
336351
}
337352

src/store/reducers/nodes/nodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ const filterNodesByProblemsStatus = (
192192
});
193193
};
194194

195-
export const filterNodesByUptime = (
196-
nodesList: NodesPreparedEntity[] = [],
195+
export const filterNodesByUptime = <T extends {StartTime?: string}>(
196+
nodesList: T[] = [],
197197
nodesUptimeFilter: NodesUptimeFilterValues,
198198
) => {
199199
if (nodesUptimeFilter === NodesUptimeFilterValues.All) {

0 commit comments

Comments
 (0)