mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Merge pull request #1237 from weaveworks/1221-no-subtopo-options
Apply topology options also to sub-topologies
This commit is contained in:
@@ -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');
|
||||
});
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user