mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
Hide empty topo's that set hidden_if_empty=true.
This commit is contained in:
@@ -6,7 +6,8 @@ import { Store } from 'flux/utils';
|
||||
import AppDispatcher from '../dispatcher/app-dispatcher';
|
||||
import ActionTypes from '../constants/action-types';
|
||||
import { EDGE_ID_SEPARATOR } from '../constants/naming';
|
||||
import { findTopologyById, setTopologyUrlsById, updateTopologyIds } from '../utils/topology-utils';
|
||||
import { findTopologyById, setTopologyUrlsById, updateTopologyIds,
|
||||
filterHiddenTopologies } from '../utils/topology-utils';
|
||||
|
||||
const makeList = List;
|
||||
const makeMap = Map;
|
||||
@@ -62,8 +63,11 @@ const topologySorter = topology => topology.get('rank');
|
||||
// adds ID field to topology (based on last part of URL path) and save urls in
|
||||
// map for easy lookup
|
||||
function processTopologies(nextTopologies) {
|
||||
// filter out hidden topos
|
||||
const visibleTopologies = filterHiddenTopologies(nextTopologies);
|
||||
|
||||
// add IDs to topology objects in-place
|
||||
const topologiesWithId = updateTopologyIds(nextTopologies);
|
||||
const topologiesWithId = updateTopologyIds(visibleTopologies);
|
||||
|
||||
// cache URLs by ID
|
||||
topologyUrlsById = setTopologyUrlsById(topologyUrlsById, topologiesWithId);
|
||||
|
||||
@@ -106,4 +106,18 @@ describe('TopologyUtils', () => {
|
||||
expect(nodes.n2.degree).toEqual(0);
|
||||
expect(nodes.n3.degree).toEqual(0);
|
||||
});
|
||||
|
||||
describe('filterHiddenTopologies', () => {
|
||||
it('should filter out empty topos that set hidden_if_empty=true', () => {
|
||||
const topos = [
|
||||
{id: 'a', hidden_if_empty: true, stats: {node_count: 0, filtered_nodes:0}},
|
||||
{id: 'b', hidden_if_empty: true, stats: {node_count: 1, filtered_nodes:0}},
|
||||
{id: 'c', hidden_if_empty: true, stats: {node_count: 0, filtered_nodes:1}},
|
||||
{id: 'd', hidden_if_empty: false, stats: {node_count: 0, filtered_nodes:0}}
|
||||
];
|
||||
|
||||
const res = TopologyUtils.filterHiddenTopologies(topos);
|
||||
expect(res.map(t => t.id)).toEqual(['b', 'c', 'd']);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
@@ -50,3 +50,8 @@ export function setTopologyUrlsById(topologyUrlsById, topologies) {
|
||||
});
|
||||
return urlMap;
|
||||
}
|
||||
|
||||
export function filterHiddenTopologies(topologies) {
|
||||
return topologies.filter(t => (!t.hidden_if_empty || t.stats.node_count > 0 ||
|
||||
t.stats.filtered_nodes > 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user