mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Added graph complexity check on page load
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
const is = require('immutable').is;
|
||||
|
||||
import {is, fromJS} from 'immutable';
|
||||
// Root reducer test suite using Jasmine matchers
|
||||
|
||||
describe('RootReducer', () => {
|
||||
@@ -44,6 +43,34 @@ describe('RootReducer', () => {
|
||||
}
|
||||
};
|
||||
|
||||
const topologies = [{
|
||||
hide_if_empty: true,
|
||||
name: 'Processes',
|
||||
rank: 1,
|
||||
sub_topologies: [],
|
||||
url: '/api/topology/processes',
|
||||
fullName: 'Processes',
|
||||
id: 'processes',
|
||||
options: [
|
||||
{
|
||||
defaultValue: 'hide',
|
||||
id: 'unconnected',
|
||||
options: [
|
||||
{
|
||||
label: 'Unconnected nodes hidden',
|
||||
value: 'hide'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
stats: {
|
||||
edge_count: 319,
|
||||
filtered_nodes: 214,
|
||||
node_count: 320,
|
||||
nonpseudo_node_count: 320
|
||||
}
|
||||
}];
|
||||
|
||||
// actions
|
||||
|
||||
const ChangeTopologyOptionAction = {
|
||||
@@ -468,4 +495,9 @@ describe('RootReducer', () => {
|
||||
nextState = reducer(nextState, { type: ActionTypes.CLICK_BACKGROUND });
|
||||
expect(nextState.get('showingHelp')).toBe(false);
|
||||
});
|
||||
it('switches to grid mode when complexity is high', () => {
|
||||
let nextState = initialState.set('currentTopology', fromJS(topologies[0]));
|
||||
nextState = reducer(nextState, {type: ActionTypes.SET_RECEIVED_NODES_DELTA});
|
||||
expect(nextState.get('gridMode')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,8 @@ import { EDGE_ID_SEPARATOR } from '../constants/naming';
|
||||
import { applyPinnedSearches, updateNodeMatches } from '../utils/search-utils';
|
||||
import { getNetworkNodes, getAvailableNetworks } from '../utils/network-view-utils';
|
||||
import { findTopologyById, getAdjacentNodes, setTopologyUrlsById, updateTopologyIds,
|
||||
filterHiddenTopologies, addTopologyFullname, getDefaultTopology } from '../utils/topology-utils';
|
||||
filterHiddenTopologies, addTopologyFullname, getDefaultTopology, graphExceedsComplexityThresh
|
||||
} from '../utils/topology-utils';
|
||||
|
||||
const log = debug('scope:app-store');
|
||||
const error = debug('scope:error');
|
||||
@@ -501,6 +502,13 @@ 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')) {
|
||||
const topoStats = state.get('currentTopology').get('stats');
|
||||
state = graphExceedsComplexityThresh(topoStats)
|
||||
? state.set('gridMode', true)
|
||||
: state;
|
||||
}
|
||||
return state.set('nodesLoaded', true);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,3 +175,8 @@ export function getCurrentTopologyUrl(state) {
|
||||
export function isNodeMatchingQuery(node, query) {
|
||||
return node.get('label').includes(query) || node.get('subLabel').includes(query);
|
||||
}
|
||||
|
||||
export function graphExceedsComplexityThresh(stats) {
|
||||
// Check to see if complexity is high. Used to trigger table view on page load.
|
||||
return (stats.get('node_count') + (2 * stats.get('edge_count'))) > 500;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user