Skip to content

Commit

Permalink
Merge pull request #2232 from weaveworks/1804-loading-topologies
Browse files Browse the repository at this point in the history
Show loading indicator on topology changes
  • Loading branch information
jpellizzari authored Feb 20, 2017
2 parents 037fc67 + 58fa1c9 commit a07d01b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions client/app/scripts/reducers/__tests__/root-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions client/app/scripts/reducers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -278,9 +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());

return state;
}

Expand All @@ -290,8 +298,9 @@ 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());
return state;
}
Expand Down Expand Up @@ -515,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);
}
Expand Down

0 comments on commit a07d01b

Please sign in to comment.