Skip to content

Commit

Permalink
Added clearNodes helper; Added initialNodes loaded to graph complexit…
Browse files Browse the repository at this point in the history
…y check
  • Loading branch information
jpellizzari committed Feb 15, 2017
1 parent 404f0fc commit 58fa1c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 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
23 changes: 16 additions & 7 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,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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 58fa1c9

Please sign in to comment.