diff --git a/client/app/scripts/actions/app-actions.js b/client/app/scripts/actions/app-actions.js index 78a972f13..e88bbf7bd 100644 --- a/client/app/scripts/actions/app-actions.js +++ b/client/app/scripts/actions/app-actions.js @@ -688,6 +688,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 250304c29..6813f1700 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', () => { @@ -526,4 +530,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 0f499c394..34171df0e 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -710,6 +710,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 db2b8096d..cf60cf3a6 100644 --- a/client/package.json +++ b/client/package.json @@ -62,6 +62,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",