diff --git a/client/app/scripts/stores/__tests__/app-store-test.js b/client/app/scripts/stores/__tests__/app-store-test.js index 379e878e9..80b54059e 100644 --- a/client/app/scripts/stores/__tests__/app-store-test.js +++ b/client/app/scripts/stores/__tests__/app-store-test.js @@ -206,8 +206,13 @@ describe('AppStore', () => { expect(AppStore.getActiveTopologyOptions().get('option1')).toBe('off'); expect(AppStore.getAppState().topologyOptions.topo1.option1).toBe('off'); - // other topology w/o options dont return options, but keep in app state + // sub-topology should retain main topo options registeredCallback(ClickSubTopologyAction); + expect(AppStore.getActiveTopologyOptions().get('option1')).toBe('off'); + expect(AppStore.getAppState().topologyOptions.topo1.option1).toBe('off'); + + // other topology w/o options dont return options, but keep in app state + registeredCallback(ClickTopology2Action); expect(AppStore.getActiveTopologyOptions()).toBeUndefined(); expect(AppStore.getAppState().topologyOptions.topo1.option1).toBe('off'); }); diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index 40690b065..9f11ac536 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -86,8 +86,8 @@ function processTopologies(nextTopologies) { } function setTopology(topologyId) { - currentTopologyId = topologyId; currentTopology = findTopologyById(topologies, topologyId); + currentTopologyId = topologyId; } function setDefaultTopologyOptions(topologyList) { @@ -107,10 +107,6 @@ function setDefaultTopologyOptions(topologyList) { defaultOptions ); } - - if (topology.has('sub_topologies')) { - setDefaultTopologyOptions(topology.get('sub_topologies')); - } }); } @@ -154,7 +150,10 @@ export class AppStore extends Store { } getActiveTopologyOptions() { - // options for current topology + // options for current topology, sub-topologies share options with parent + if (currentTopology && currentTopology.get('parentId')) { + return topologyOptions.get(currentTopology.get('parentId')); + } return topologyOptions.get(currentTopologyId); } @@ -304,15 +303,19 @@ export class AppStore extends Store { switch (payload.type) { case ActionTypes.CHANGE_TOPOLOGY_OPTION: { resumeUpdate(); - if (topologyOptions.getIn([payload.topologyId, payload.option]) - !== payload.value) { - nodes = nodes.clear(); + // set option on parent topology + const topology = findTopologyById(topologies, payload.topologyId); + if (topology) { + const topologyId = topology.get('parentId') || topology.get('id'); + if (topologyOptions.getIn([topologyId, payload.option]) !== payload.value) { + nodes = nodes.clear(); + } + topologyOptions = topologyOptions.setIn( + [topologyId, payload.option], + payload.value + ); + this.__emitChange(); } - topologyOptions = topologyOptions.setIn( - [payload.topologyId, payload.option], - payload.value - ); - this.__emitChange(); break; } case ActionTypes.CLEAR_CONTROL_ERROR: { diff --git a/client/app/scripts/utils/topology-utils.js b/client/app/scripts/utils/topology-utils.js index 5d0e5dd23..5987af9bc 100644 --- a/client/app/scripts/utils/topology-utils.js +++ b/client/app/scripts/utils/topology-utils.js @@ -24,13 +24,16 @@ export function updateNodeDegrees(nodes, edges) { }); } -/* set topology.id in place on each topology */ -export function updateTopologyIds(topologies) { +/* set topology.id and parentId for sub-topologies in place */ +export function updateTopologyIds(topologies, parentId) { return topologies.map(topology => { const result = Object.assign({}, topology); result.id = topology.url.split('/').pop(); + if (parentId) { + result.parentId = parentId; + } if (topology.sub_topologies) { - result.sub_topologies = updateTopologyIds(topology.sub_topologies); + result.sub_topologies = updateTopologyIds(topology.sub_topologies, result.id); } return result; });