From eeeb1385c51e920d6f400fd46e71da17c9885e9b Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Tue, 23 Aug 2016 13:50:18 +0200 Subject: [PATCH] Makes services the initial topology if available - Otherwise reverts to containers --- client/app/scripts/reducers/root.js | 10 +++++++--- client/app/scripts/utils/topology-utils.js | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index ba9ef0dce..3ad310b1e 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -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) { diff --git a/client/app/scripts/utils/topology-utils.js b/client/app/scripts/utils/topology-utils.js index 14c365558..c2955bbb1 100644 --- a/client/app/scripts/utils/topology-utils.js +++ b/client/app/scripts/utils/topology-utils.js @@ -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