Makes services the initial topology if available

- Otherwise reverts to containers
This commit is contained in:
Simon Howe
2016-08-23 13:50:18 +02:00
parent fd82651f96
commit eeeb1385c5
2 changed files with 25 additions and 4 deletions

View File

@@ -7,8 +7,8 @@ import ActionTypes from '../constants/action-types';
import { EDGE_ID_SEPARATOR } from '../constants/naming';
import { applyPinnedSearches, updateNodeMatches } from '../utils/search-utils';
import { getNetworkNodes, getAvailableNetworks } from '../utils/network-view-utils';
import { findTopologyById, getAdjacentNodes, setTopologyUrlsById,
updateTopologyIds, filterHiddenTopologies, addTopologyFullname } from '../utils/topology-utils';
import { findTopologyById, getAdjacentNodes, setTopologyUrlsById, updateTopologyIds,
filterHiddenTopologies, addTopologyFullname, getDefaultTopology } from '../utils/topology-utils';
const log = debug('scope:app-store');
const error = debug('scope:error');
@@ -25,7 +25,7 @@ export const initialState = makeMap({
controlPipes: makeOrderedMap(), // pipeId -> controlPipe
controlStatus: makeMap(),
currentTopology: null,
currentTopologyId: 'containers',
currentTopologyId: null,
errorUrl: null,
forceRelayout: false,
gridMode: false,
@@ -606,6 +606,10 @@ export function rootReducer(state = initialState, action) {
state = state.set('errorUrl', null);
state = state.update('topologyUrlsById', topologyUrlsById => topologyUrlsById.clear());
state = processTopologies(state, action.topologies);
if (!state.get('currentTopologyId')) {
state = state.set('currentTopologyId', getDefaultTopology(state.get('topologies')));
log(`Set currentTopologyId to ${state.get('currentTopologyId')}`);
}
state = setTopology(state, state.get('currentTopologyId'));
// only set on first load, if options are not already set via route
if (!state.get('topologiesLoaded') && state.get('topologyOptions').size === 0) {

View File

@@ -1,5 +1,22 @@
import _ from 'lodash';
import { is as isDeepEqual, Map as makeMap, Set as makeSet } from 'immutable';
import { is as isDeepEqual, Map as makeMap, Set as makeSet, List as makeList } from 'immutable';
const TOPOLOGY_DISPLAY_PRIORITY = {
services: 1,
containers: 2,
};
export function getDefaultTopology(topologies) {
const flatTopologies = topologies
.flatMap(t => makeList([t]).concat(t.get('sub_topologies', makeList())));
return flatTopologies
.sortBy(t => TOPOLOGY_DISPLAY_PRIORITY[t.get('id')] || Infinity)
.getIn([0, 'id']);
}
/**
* Returns a cache ID based on the topologyId and optionsQuery