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

Apply topology options also to sub-topologies #1237

Merged
merged 1 commit into from
Apr 7, 2016
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
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