From e95f46bfd8f510dc185e2f9e0fc9c3858225ff79 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Tue, 24 May 2016 16:59:03 +0200 Subject: [PATCH] Extract networks from metadata (should be toplevel field) --- client/app/scripts/reducers/root.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index de6abea2a..8ab87ff16 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -518,14 +518,26 @@ export function rootReducer(state = initialState, action) { // apply pinned searches, filters nodes that dont match state = applyPinnedSearches(state); + // TODO move this setting of networks as toplevel node field to backend, + // to not rely on field IDs here. should be determined by topology implementer + state = state.update('nodes', nodes => nodes.map(node => { + if (node.has('metadata')) { + const networks = node.get('metadata') + .find(field => field.get('id') === 'docker_container_networks'); + if (networks) { + return node.set('networks', fromJS(networks.get('value').split(', '))); + } + } + return node; + })); + state = state.set('availableNetworks', state.get('nodes') - .valueSeq() - .flatMap(node => (node.get('networks') || makeList()).map(n => ( - makeMap({id: n, label: n}) - ))) - .toSet() - .toList() - .sort()); + .valueSeq() + .flatMap(node => node.get('networks') || makeList()) + .toSet() + .toList() + .sort() + .map(n => makeMap({id: n, label: n}))); state = state.set('availableCanvasMetrics', state.get('nodes') .valueSeq()