Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep topology nav visible if selected #2709

Merged
merged 1 commit into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions client/app/scripts/reducers/__tests__/root-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@ describe('RootReducer', () => {
}]
};

const ReceiveTopologiesHiddenAction = {
type: ActionTypes.RECEIVE_TOPOLOGIES,
topologies: [{
url: '/topo1',
name: 'Topo1',
stats: {
node_count: 1
}
}, {
hide_if_empty: true,
url: '/topo2',
name: 'Topo2',
stats: {
node_count: 0,
filtered_nodes: 0
}
}]
};

const RouteAction = {
type: ActionTypes.ROUTE_TOPOLOGY,
state: {}
Expand Down Expand Up @@ -567,6 +586,21 @@ describe('RootReducer', () => {
expect(isTopologyNodeCountZero(nextState)).toBeFalsy();
});

it('keeps hidden topology visible if selected', () => {
let nextState = initialState;
nextState = reducer(nextState, ClickTopology2Action);
nextState = reducer(nextState, ReceiveTopologiesHiddenAction);
expect(nextState.get('currentTopologyId')).toEqual('topo2');
expect(nextState.get('topologies').toJS().length).toEqual(2);
});

it('keeps hidden topology hidden if not selected', () => {
let nextState = initialState;
nextState = reducer(nextState, ClickTopologyAction);
nextState = reducer(nextState, ReceiveTopologiesHiddenAction);
expect(nextState.get('topologies').toJS().length).toEqual(1);
});

// selection of relatives

it('keeps relatives as a stack', () => {
Expand Down
10 changes: 5 additions & 5 deletions client/app/scripts/reducers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ function calcSelectType(topology) {
// adds ID field to topology (based on last part of URL path) and save urls in
// map for easy lookup
function processTopologies(state, nextTopologies) {
// add IDs to topology objects in-place
const topologiesWithId = updateTopologyIds(nextTopologies);
// filter out hidden topos
const visibleTopologies = filterHiddenTopologies(nextTopologies);
const visibleTopologies = filterHiddenTopologies(topologiesWithId, state.get('currentTopologyId'));
// set `selectType` field for topology and sub_topologies options (recursive).
const topologiesWithSelectType = visibleTopologies.map(calcSelectType);
// add IDs to topology objects in-place
const topologiesWithId = updateTopologyIds(topologiesWithSelectType);
// cache URLs by ID
state = state.set('topologyUrlsById',
setTopologyUrlsById(state.get('topologyUrlsById'), topologiesWithId));
setTopologyUrlsById(state.get('topologyUrlsById'), topologiesWithSelectType));

const topologiesWithFullnames = addTopologyFullname(topologiesWithId);
const topologiesWithFullnames = addTopologyFullname(topologiesWithSelectType);
const immNextTopologies = fromJS(topologiesWithFullnames).sortBy(topologySorter);
return state.set('topologies', immNextTopologies);
}
Expand Down
4 changes: 2 additions & 2 deletions client/app/scripts/utils/topology-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export function setTopologyUrlsById(topologyUrlsById, topologies) {
return urlMap;
}

export function filterHiddenTopologies(topologies) {
export function filterHiddenTopologies(topologies, currentTopologyId) {
return topologies.filter(t => (!t.hide_if_empty || t.stats.node_count > 0 ||
t.stats.filtered_nodes > 0));
t.stats.filtered_nodes > 0 || t.id === currentTopologyId));
}

export function getCurrentTopologyOptions(state) {
Expand Down