Skip to content

Commit 89357c4

Browse files
refactor(Node): useTypedSelector (#424)
1 parent d916fa0 commit 89357c4

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/containers/Node/Node.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import {useRouteMatch} from 'react-router';
33
import cn from 'bem-cn-lite';
4-
import {useDispatch, useSelector} from 'react-redux';
4+
import {useDispatch} from 'react-redux';
55
import _ from 'lodash';
66

77
import {Tabs} from '@gravity-ui/uikit';
@@ -19,6 +19,7 @@ import {getNodeInfo, resetNode} from '../../store/reducers/node/node';
1919
import routes, {createHref} from '../../routes';
2020
import {HeaderItemType, setHeader} from '../../store/reducers/header';
2121
import {AutoFetcher} from '../../utils/autofetcher';
22+
import {useTypedSelector} from '../../utils/hooks';
2223
import {clusterTabsIds, getClusterPath} from '../Cluster/utils';
2324

2425
import './Node.scss';
@@ -37,12 +38,8 @@ interface NodeProps {
3738
function Node(props: NodeProps) {
3839
const dispatch = useDispatch();
3940

40-
const wasLoaded = useSelector((state: any) => state.node.wasLoaded);
41-
const loading = useSelector((state: any) => state.node.loading);
42-
const error = useSelector((state: any) => state.node.error);
43-
44-
const node = useSelector((state: any) => state.node?.data?.SystemStateInfo?.[0]);
45-
41+
const {loading, wasLoaded, error, data} = useTypedSelector((state) => state.node);
42+
const node = data?.SystemStateInfo?.[0];
4643
const nodeHost = node?.Host;
4744

4845
const match =

src/containers/Node/NodePages.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import routes, {createHref} from '../../routes';
1+
import routes, {Query, createHref} from '../../routes';
22

33
export const STORAGE = 'storage';
44
export const TABLETS = 'tablets';
@@ -21,9 +21,13 @@ export const NODE_PAGES = [
2121
},
2222
];
2323

24-
export function getDefaultNodePath(nodeId: string | number) {
25-
return createHref(routes.node, {
26-
id: nodeId,
27-
activeTab: OVERVIEW,
28-
});
24+
export function getDefaultNodePath(nodeId: string | number, query: Query = {}) {
25+
return createHref(
26+
routes.node,
27+
{
28+
id: nodeId,
29+
activeTab: OVERVIEW,
30+
},
31+
query,
32+
);
2933
}

src/routes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const routes = {
1313
auth: '/auth',
1414
};
1515

16+
export type Query = Record<string | number, string | number | string[] | number[] | undefined>;
17+
1618
export function createHref(
1719
route: string,
1820
params?: Record<string, string | number>,
19-
query: Record<string | number, string | number | string[] | number[] | undefined> = {},
21+
query: Query = {},
2022
) {
2123
let extendedQuery = query;
2224

src/store/reducers/node/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ export interface NodeState {
2828
data: TEvSystemStateResponse;
2929
loading: boolean;
3030
wasLoaded: boolean;
31+
error?: IResponseError;
3132

3233
nodeStructure: TStorageInfo;
3334
loadingStructure: boolean;
3435
wasLoadedStructure: boolean;
36+
errorStructure?: IResponseError;
3537
}
3638

3739
export type NodeAction =

0 commit comments

Comments
 (0)