diff --git a/client/app/scripts/actions/app-actions.js b/client/app/scripts/actions/app-actions.js index 300c4bbfe..d566f1acd 100644 --- a/client/app/scripts/actions/app-actions.js +++ b/client/app/scripts/actions/app-actions.js @@ -684,6 +684,8 @@ export function toggleTroubleshootingMenu(ev) { export function changeInstance() { return (dispatch, getState) => { + dispatch({ type: ActionTypes.CHANGE_INSTANCE }); + updateRoute(getState); const state = getState(); getNodesDelta( getCurrentTopologyUrl(state), diff --git a/client/app/scripts/constants/action-types.js b/client/app/scripts/constants/action-types.js index c56f06286..b20601096 100644 --- a/client/app/scripts/constants/action-types.js +++ b/client/app/scripts/constants/action-types.js @@ -58,6 +58,7 @@ const ACTION_TYPES = [ 'SET_RECEIVED_NODES_DELTA', 'SORT_ORDER_CHANGED', 'SET_GRID_MODE', + 'CHANGE_INSTANCE' ]; export default zipObject(ACTION_TYPES, ACTION_TYPES); diff --git a/client/app/scripts/reducers/__tests__/root-test.js b/client/app/scripts/reducers/__tests__/root-test.js index f4e80a6c8..b46d8a150 100644 --- a/client/app/scripts/reducers/__tests__/root-test.js +++ b/client/app/scripts/reducers/__tests__/root-test.js @@ -192,6 +192,10 @@ describe('RootReducer', () => { state: {} }; + const ChangeInstanceAction = { + type: ActionTypes.CHANGE_INSTANCE + }; + // Basic tests it('returns initial state', () => { @@ -525,4 +529,13 @@ describe('RootReducer', () => { nextState = reducer(nextState, action3); expect(nextState.getIn(['nodes', 'n1', 'adjacency'])).toBeFalsy(); }); + it('removes non-transferrable state values when changing instances', () => { + let nextState = initialState; + nextState = reducer(nextState, ClickNodeAction); + expect(nextState.get('selectedNodeId')).toEqual('n1'); + expect(nextState.getIn(['nodeDetails', 'n1'])).toBeTruthy(); + nextState = reducer(nextState, ChangeInstanceAction); + expect(nextState.get('selectedNodeId')).toBeFalsy(); + expect(nextState.getIn(['nodeDetails', 'n1'])).toBeFalsy(); + }); }); diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 81d686b8b..af83e24d6 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -721,6 +721,11 @@ export function rootReducer(state = initialState, action) { return state.set('showingTroubleshootingMenu', !state.get('showingTroubleshootingMenu')); } + case ActionTypes.CHANGE_INSTANCE: { + state = closeAllNodeDetails(state); + return state; + } + default: { return state; } diff --git a/client/package.json b/client/package.json index dff7cfaf1..51c003ff5 100644 --- a/client/package.json +++ b/client/package.json @@ -61,6 +61,7 @@ "eslint-plugin-import": "2.2.0", "eslint-plugin-jsx-a11y": "2.2.3", "eslint-plugin-react": "6.8.0", + "expect": "^1.20.2", "extract-text-webpack-plugin": "1.0.1", "file-loader": "0.9.0", "html-webpack-plugin": "2.24.1",