Skip to content

Commit ae95ecf

Browse files
refactor: migrate network reducer to ts (#413)
1 parent 95ef486 commit ae95ecf

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/containers/Tenant/Diagnostics/Network/Network.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Icon} from '../../../../components/Icon';
1212
import {ProblemFilter} from '../../../../components/ProblemFilter';
1313
import {Illustration} from '../../../../components/Illustration';
1414

15-
import {getNetworkInfo, setDataWasNotLoaded} from '../../../../store/reducers/network';
15+
import {getNetworkInfo, setDataWasNotLoaded} from '../../../../store/reducers/network/network';
1616
import {hideTooltip, showTooltip} from '../../../../store/reducers/tooltip';
1717
import {changeFilter, ProblemFilterValues} from '../../../../store/reducers/settings/settings';
1818
import {AutoFetcher} from '../../../../utils/autofetcher';
@@ -361,7 +361,7 @@ class Network extends React.Component {
361361
}
362362

363363
const mapStateToProps = (state) => {
364-
const {wasLoaded, loading, data: netWorkInfo} = state.network;
364+
const {wasLoaded, loading, data: netWorkInfo = {}} = state.network;
365365
const {autorefresh} = state.schema;
366366
return {
367367
netWorkInfo,

src/store/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import tablets from './tablets';
1111
import heatmap from './heatmap';
1212
import schema from './schema';
1313
import host from './host';
14-
import network from './network';
14+
import network from './network/network';
1515
import tenants from './tenants/tenants';
1616
import tablet from './tablet';
1717
import topic from './topic';

src/store/reducers/network.js renamed to src/store/reducers/network/network.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import {createRequestActionTypes, createApiRequest} from '../utils';
2-
import '../../services/api';
1+
import {Reducer} from 'redux';
32

4-
const FETCH_ALL_NODES_NETWORK = createRequestActionTypes(
5-
'ALL_NODES_NETWORK',
3+
import '../../../services/api';
4+
import {createRequestActionTypes, createApiRequest} from '../../utils';
5+
6+
import type {NetworkAction, NetworkState} from './types';
7+
8+
export const FETCH_ALL_NODES_NETWORK = createRequestActionTypes(
9+
'network',
610
'FETCH_ALL_NODES_NETWORK',
711
);
812

913
const SET_DATA_WAS_NOT_LOADED = 'network/SET_DATA_WAS_NOT_LOADED';
1014

1115
const initialState = {
12-
data: {},
1316
loading: false,
1417
wasLoaded: false,
1518
};
1619

17-
const network = (state = initialState, action) => {
20+
const network: Reducer<NetworkState, NetworkAction> = (state = initialState, action) => {
1821
switch (action.type) {
1922
case FETCH_ALL_NODES_NETWORK.REQUEST: {
2023
return {
@@ -53,10 +56,10 @@ const network = (state = initialState, action) => {
5356
export const setDataWasNotLoaded = () => {
5457
return {
5558
type: SET_DATA_WAS_NOT_LOADED,
56-
};
59+
} as const;
5760
};
5861

59-
export const getNetworkInfo = (tenant) => {
62+
export const getNetworkInfo = (tenant: string) => {
6063
return createApiRequest({
6164
request: window.api.getNetwork(tenant),
6265
actions: FETCH_ALL_NODES_NETWORK,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type {IResponseError} from '../../../types/api/error';
2+
import type {TNetInfo} from '../../../types/api/netInfo';
3+
import type {ApiRequestAction} from '../../utils';
4+
5+
import {FETCH_ALL_NODES_NETWORK, setDataWasNotLoaded} from './network';
6+
7+
export interface NetworkState {
8+
loading: boolean;
9+
wasLoaded: boolean;
10+
data?: TNetInfo;
11+
error?: IResponseError;
12+
}
13+
14+
export type NetworkAction =
15+
| ApiRequestAction<typeof FETCH_ALL_NODES_NETWORK, TNetInfo, IResponseError>
16+
| ReturnType<typeof setDataWasNotLoaded>;

0 commit comments

Comments
 (0)