diff --git a/client/app/scripts/reducers/__tests__/root-test.js b/client/app/scripts/reducers/__tests__/root-test.js index cfde7428e..0121da97d 100644 --- a/client/app/scripts/reducers/__tests__/root-test.js +++ b/client/app/scripts/reducers/__tests__/root-test.js @@ -2,6 +2,7 @@ jest.dontMock('../../utils/router-utils'); jest.dontMock('../../utils/search-utils'); jest.dontMock('../../utils/string-utils'); jest.dontMock('../../utils/topology-utils'); +jest.dontMock('../../utils/network-view-utils'); jest.dontMock('../../constants/action-types'); jest.dontMock('../root'); diff --git a/client/app/scripts/utils/network-view-utils.js b/client/app/scripts/utils/network-view-utils.js new file mode 100644 index 000000000..8565fc8e6 --- /dev/null +++ b/client/app/scripts/utils/network-view-utils.js @@ -0,0 +1,20 @@ +import { fromJS, List as makeList } from 'immutable'; + +export function getNetworkNodes(nodes) { + const networks = {}; + nodes.forEach(node => (node.get('networks') || makeList()).forEach(n => { + const networkId = n.get('id'); + networks[networkId] = (networks[networkId] || []).concat([node.get('id')]); + })); + return fromJS(networks); +} + + +export function getAvailableNetworks(nodes) { + return nodes + .valueSeq() + .flatMap(node => node.get('networks') || makeList()) + .toSet() + .toList() + .sortBy(m => m.get('label')); +}