Merge pull request #1823 from weaveworks/1809-make-services-initial-topo

Makes services the initial topology if available
This commit is contained in:
Simon
2016-09-01 17:21:54 +02:00
committed by GitHub
2 changed files with 34 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,31 @@
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';
//
// top priority first
//
const TOPOLOGY_DISPLAY_PRIORITY = [
'services',
'deployments',
'replica-sets',
'pods',
'containers',
];
export function getDefaultTopology(topologies) {
const flatTopologies = topologies
.flatMap(t => makeList([t]).concat(t.get('sub_topologies', makeList())));
return flatTopologies
.sortBy(t => {
const index = TOPOLOGY_DISPLAY_PRIORITY.indexOf(t.get('id'));
return index === -1 ? Infinity : index;
})
.getIn([0, 'id']);
}
/**
* Returns a cache ID based on the topologyId and optionsQuery