From 0f42f8021b187af7b5b9d973730cf7372f831843 Mon Sep 17 00:00:00 2001 From: JUDIT GRESKOVITS Date: Wed, 1 Mar 2017 16:32:57 +0000 Subject: [PATCH] Selector to add primary and secondary to parent Remove console log Selector to add primary and secondary to parent --- frontend/src/mock-state.json | 2 +- frontend/src/state/selectors.js | 75 ++++++++++++++++-------- ui/src/components/topology/graph-link.js | 2 +- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/frontend/src/mock-state.json b/frontend/src/mock-state.json index 6c1b1adf..dc1ed974 100644 --- a/frontend/src/mock-state.json +++ b/frontend/src/mock-state.json @@ -667,7 +667,7 @@ "connections": [ "6a0eee76-c019-413b-9d5f-44712b55b993", "6d31aff4-de1e-4042-a983-fbd23d5c530c", - "9572d367-c4ae-4fb1-8ad5-f5e3830e7034" + "4ee4103e-1a52-4099-a48e-01588f597c70" ] }, { "uuid": "6a0eee76-c019-413b-9d5f-44712b55b993", diff --git a/frontend/src/state/selectors.js b/frontend/src/state/selectors.js index df8d77a2..ca7eeb64 100644 --- a/frontend/src/state/selectors.js +++ b/frontend/src/state/selectors.js @@ -110,31 +110,58 @@ const servicesForTopology = (projectId) => createSelector( [services, projectById(projectId)], (services, project) => services.filter((s) => s.project === project.uuid) - .map((service) => ({ - ...service, - uuid: service.uuid, - id: service.id, - name: service.name, - instances: instancesByServiceId(service.uuid).length, - connections: service.connections, - // tmp below - datacentres: 2, - metrics: [ - { - name: 'CPU', - value: '50%' - }, - { - name: 'Memory', - value: '20%' - }, - { - name: 'Network', - value: '2.9Kb/sec' + .reduce((acc, service, index, services) => { + const getService = (s) => ({ + ...s, + uuid: s.uuid, + id: s.id, + name: s.name, + instances: instancesByServiceId(s.uuid).length, + connections: s.connections, + // tmp below + datacentres: 2, + metrics: [ + { + name: 'CPU', + value: '50%' + }, + { + name: 'Memory', + value: '20%' + }, + { + name: 'Network', + value: '2.9Kb/sec' + } + ], + healthy: true + }); + const findService = (a, s, p) => s.uuid === p ? s : a; + if(service.parent) { + let parent = acc.reduce((a, s) => + findService(a, s, service.parent), null); + if(!parent) { + parent = services.reduce((a, s) => + findService(a, s, service.parent), null); + acc.push(parent); } - ], - healthy: true - })) + if(!parent.children) { + parent.children = []; + } + parent.children.push( + getService(service) + ); + } + else { + const s = acc.reduce((a, s, i) => s.uuid === service.uuid, null); + if(!s) { + acc.push( + getService(service) + ); + } + } + return acc; + }, []) ); const metricsByServiceId = (serviceId) => createSelector( diff --git a/ui/src/components/topology/graph-link.js b/ui/src/components/topology/graph-link.js index 798866ee..69c79f89 100644 --- a/ui/src/components/topology/graph-link.js +++ b/ui/src/components/topology/graph-link.js @@ -11,7 +11,7 @@ const StyledLine = styled.line` const StyledCircle = styled.circle` stroke: ${colors.base.secondaryActive}; - fill: colors.base.secondary; + fill: ${colors.base.secondary}; stroke-width: 1.5; `;