From 9802bba502ea1a39ece6f9753db1e88977862221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Fri, 14 Jul 2017 12:15:57 +0100 Subject: [PATCH] feat(cp-frontend): handle removal of parent property --- packages/cp-frontend/src/graphql/Services.gql | 10 +++++- packages/cp-frontend/src/state/selectors.js | 34 +++++-------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/packages/cp-frontend/src/graphql/Services.gql b/packages/cp-frontend/src/graphql/Services.gql index c446b232..5931cfef 100644 --- a/packages/cp-frontend/src/graphql/Services.gql +++ b/packages/cp-frontend/src/graphql/Services.gql @@ -6,7 +6,15 @@ query Services($deploymentGroupSlug: String!){ ...DeploymentGroupInfo services { ...ServiceInfo - parent + branches { + name + slug + instances { + id + status + healthy + } + } connections instances { id diff --git a/packages/cp-frontend/src/state/selectors.js b/packages/cp-frontend/src/state/selectors.js index 9770b73c..f6e69ee2 100644 --- a/packages/cp-frontend/src/state/selectors.js +++ b/packages/cp-frontend/src/state/selectors.js @@ -132,34 +132,16 @@ const getService = (service, index) => { const processServices = services => { return forceArray(services).reduce((ss, s, i) => { - if (s.parent) { - const parents = ss.filter(parentS => parentS.id === s.parent); - let parent; - if (parents.length) { - parent = parents[0]; - } else { - parent = { id: s.parent }; - ss.push(parent); - } - if (!parent.children) { - parent.children = []; - } - const child = getService(s, i); - parent.instancesActive = parent.instancesActive - ? true - : child.instancesActive; - parent.children.push(child); + const serviceIndex = ss.findIndex(existingS => existingS.id === s.id); + if (serviceIndex === -1) { + ss.push(getService(s, i)); } else { - const serviceIndex = ss.findIndex(existingS => existingS.id === s.id); - if (serviceIndex === -1) { - ss.push(getService(s, i)); - } else { - ss.splice(serviceIndex, 1, { - ...ss[serviceIndex], - ...getService(s, i) - }); - } + ss.splice(serviceIndex, 1, { + ...ss[serviceIndex], + ...getService(s, i) + }); } + return ss; }, []); };