Skip to content

Commit

Permalink
Merge pull request #2237 from weaveworks/change-instance
Browse files Browse the repository at this point in the history
Add logic to remove non-transferrable state when switching Cloud instances
  • Loading branch information
jpellizzari authored Feb 20, 2017
2 parents 3e810f7 + 3d13e91 commit 341446f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/app/scripts/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions client/app/scripts/constants/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
13 changes: 13 additions & 0 deletions client/app/scripts/reducers/__tests__/root-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ describe('RootReducer', () => {
state: {}
};

const ChangeInstanceAction = {
type: ActionTypes.CHANGE_INSTANCE
};

// Basic tests

it('returns initial state', () => {
Expand Down Expand Up @@ -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();
});
});
5 changes: 5 additions & 0 deletions client/app/scripts/reducers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 341446f

Please sign in to comment.