Skip to content

Commit 588c53f

Browse files
fix(Network): update data on path change
1 parent f5486bc commit 588c53f

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

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

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

15-
import {getNetworkInfo} from '../../../../store/reducers/network';
15+
import {getNetworkInfo, setDataWasNotLoaded} from '../../../../store/reducers/network';
1616
import {hideTooltip, showTooltip} from '../../../../store/reducers/tooltip';
1717
import {ALL, PROBLEMS} from '../../../../utils/constants';
1818
import {changeFilter} from '../../../../store/reducers/settings';
@@ -26,6 +26,7 @@ const b = cn('network');
2626
class Network extends React.Component {
2727
static propTypes = {
2828
getNetworkInfo: PropTypes.func,
29+
setDataWasNotLoaded: PropTypes.func,
2930
netWorkInfo: PropTypes.object,
3031
hideTooltip: PropTypes.func,
3132
showTooltip: PropTypes.func,
@@ -75,16 +76,27 @@ class Network extends React.Component {
7576
}
7677

7778
componentDidUpdate(prevProps) {
78-
const {autorefresh, path} = this.props;
79+
const {autorefresh, path, setDataWasNotLoaded, getNetworkInfo} = this.props;
7980

80-
if (autorefresh && !prevProps.autorefresh) {
81-
getNetworkInfo(path);
81+
const restartAutorefresh = () => {
82+
this.autofetcher.stop();
8283
this.autofetcher.start();
8384
this.autofetcher.fetch(() => getNetworkInfo(path));
85+
};
86+
87+
if (autorefresh && !prevProps.autorefresh) {
88+
getNetworkInfo(path);
89+
restartAutorefresh();
8490
}
8591
if (!autorefresh && prevProps.autorefresh) {
8692
this.autofetcher.stop();
8793
}
94+
95+
if (path !== prevProps.path) {
96+
setDataWasNotLoaded();
97+
getNetworkInfo(path);
98+
restartAutorefresh();
99+
}
88100
}
89101

90102
componentWillUnmount() {
@@ -364,6 +376,7 @@ const mapDispatchToProps = {
364376
hideTooltip,
365377
showTooltip,
366378
changeFilter,
379+
setDataWasNotLoaded,
367380
};
368381

369382
export default connect(mapStateToProps, mapDispatchToProps)(Network);

src/store/reducers/network.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ const FETCH_ALL_NODES_NETWORK = createRequestActionTypes(
66
'FETCH_ALL_NODES_NETWORK',
77
);
88

9-
const network = (state = {data: {}, loading: true, wasLoaded: false}, action) => {
9+
const SET_DATA_WAS_NOT_LOADED = 'network/SET_DATA_WAS_NOT_LOADED';
10+
11+
const initialState = {
12+
data: {},
13+
loading: false,
14+
wasLoaded: false,
15+
};
16+
17+
const network = (state = initialState, action) => {
1018
switch (action.type) {
1119
case FETCH_ALL_NODES_NETWORK.REQUEST: {
1220
return {
@@ -30,11 +38,24 @@ const network = (state = {data: {}, loading: true, wasLoaded: false}, action) =>
3038
loading: false,
3139
};
3240
}
41+
42+
case SET_DATA_WAS_NOT_LOADED: {
43+
return {
44+
...state,
45+
wasLoaded: false,
46+
};
47+
}
3348
default:
3449
return state;
3550
}
3651
};
3752

53+
export const setDataWasNotLoaded = () => {
54+
return {
55+
type: SET_DATA_WAS_NOT_LOADED,
56+
};
57+
};
58+
3859
export const getNetworkInfo = (tenant) => {
3960
return createApiRequest({
4061
request: window.api.getNetwork(tenant),

0 commit comments

Comments
 (0)