Hide empty topo's that set hidden_if_empty=true.

This commit is contained in:
Simon Howe
2016-03-23 15:36:55 +01:00
parent 4f6066f0ff
commit 1e4d6e829d
3 changed files with 25 additions and 2 deletions

View File

@@ -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);

View File

@@ -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']);
});
})
});

View File

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