From 404f0fc7b19b7b2091a6e6803cc5e2d272368ef8 Mon Sep 17 00:00:00 2001 From: jpellizzari Date: Fri, 10 Feb 2017 14:25:45 -0800 Subject: [PATCH 1/2] Show loading indicator on topology changes --- client/app/scripts/reducers/root.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 81d686b8bb..2c866b83d5 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -281,6 +281,7 @@ export function rootReducer(state = initialState, action) { state = state.update('nodes', nodes => nodes.clear()); } state = state.set('availableCanvasMetrics', makeList()); + state = state.set('nodesLoaded', false); return state; } @@ -293,6 +294,7 @@ export function rootReducer(state = initialState, action) { state = state.update('nodes', nodes => nodes.clear()); } state = state.set('availableCanvasMetrics', makeList()); + state = state.set('nodesLoaded', false); return state; } From 58fa1c92eef060468fa39ea5178bd6ce9aaa4384 Mon Sep 17 00:00:00 2001 From: Jordan Pellizzari Date: Tue, 14 Feb 2017 21:29:52 -0800 Subject: [PATCH 2/2] Added clearNodes helper; Added initialNodes loaded to graph complexity check --- .../scripts/reducers/__tests__/root-test.js | 1 + client/app/scripts/reducers/root.js | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/client/app/scripts/reducers/__tests__/root-test.js b/client/app/scripts/reducers/__tests__/root-test.js index f4e80a6c84..a7dfbf8608 100644 --- a/client/app/scripts/reducers/__tests__/root-test.js +++ b/client/app/scripts/reducers/__tests__/root-test.js @@ -499,6 +499,7 @@ describe('RootReducer', () => { let nextState = initialState.set('currentTopology', fromJS(topologies[0])); nextState = reducer(nextState, {type: ActionTypes.SET_RECEIVED_NODES_DELTA}); expect(nextState.get('gridMode')).toBe(true); + expect(nextState.get('initialNodesLoaded')).toBe(true); }); it('cleans up old adjacencies', () => { // Add some nodes diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 2c866b83d5..20f2a70af1 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -75,7 +75,8 @@ export const initialState = makeMap({ version: '...', versionUpdate: null, websocketClosed: false, - exportingGraph: false + exportingGraph: false, + initialNodesLoaded: false }); // adds ID field to topology (based on last part of URL path) and save urls in @@ -148,6 +149,12 @@ function resumeUpdate(state) { return state.set('updatePausedAt', null); } +function clearNodes(state) { + return state + .update('nodes', nodes => nodes.clear()) + .set('nodesLoaded', false); +} + export function rootReducer(state = initialState, action) { if (!action.type) { error('Payload missing a type!', action); @@ -278,10 +285,10 @@ export function rootReducer(state = initialState, action) { if (action.topologyId !== state.get('currentTopologyId')) { state = setTopology(state, action.topologyId); - state = state.update('nodes', nodes => nodes.clear()); + state = clearNodes(state); } state = state.set('availableCanvasMetrics', makeList()); - state = state.set('nodesLoaded', false); + return state; } @@ -291,10 +298,10 @@ export function rootReducer(state = initialState, action) { if (action.topologyId !== state.get('currentTopologyId')) { state = setTopology(state, action.topologyId); - state = state.update('nodes', nodes => nodes.clear()); + state = clearNodes(state); } + state = state.set('availableCanvasMetrics', makeList()); - state = state.set('nodesLoaded', false); return state; } @@ -517,12 +524,14 @@ export function rootReducer(state = initialState, action) { } case ActionTypes.SET_RECEIVED_NODES_DELTA: { - // Turn on the table view if the graph is too complex - if (!state.get('nodesLoaded')) { + // Turn on the table view if the graph is too complex, but skip this block if + // the user has already loaded topologies once. + if (!state.get('initialNodesLoaded') && !state.get('nodesLoaded')) { const topoStats = state.get('currentTopology').get('stats'); state = graphExceedsComplexityThresh(topoStats) ? state.set('gridMode', true) : state; + state = state.set('initialNodesLoaded', true); } return state.set('nodesLoaded', true); }