Skip to content

Commit

Permalink
Merge pull request #1237 from weaveworks/1221-no-subtopo-options
Browse files Browse the repository at this point in the history
Apply topology options also to sub-topologies
  • Loading branch information
davkal committed Apr 7, 2016
2 parents c04ae22 + 9586c23 commit 5fba5d8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
7 changes: 6 additions & 1 deletion client/app/scripts/stores/__tests__/app-store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
31 changes: 17 additions & 14 deletions client/app/scripts/stores/app-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function processTopologies(nextTopologies) {
}

function setTopology(topologyId) {
currentTopologyId = topologyId;
currentTopology = findTopologyById(topologies, topologyId);
currentTopologyId = topologyId;
}

function setDefaultTopologyOptions(topologyList) {
Expand All @@ -107,10 +107,6 @@ function setDefaultTopologyOptions(topologyList) {
defaultOptions
);
}

if (topology.has('sub_topologies')) {
setDefaultTopologyOptions(topology.get('sub_topologies'));
}
});
}

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

Expand Down Expand Up @@ -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: {
Expand Down
9 changes: 6 additions & 3 deletions client/app/scripts/utils/topology-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit 5fba5d8

Please sign in to comment.