feat(cp-frontend): handle removal of parent property

This commit is contained in:
Sérgio Ramos 2017-07-14 12:15:57 +01:00 committed by Judit Greskovits
parent 92181a2df0
commit 9802bba502
2 changed files with 17 additions and 27 deletions

View File

@ -6,7 +6,15 @@ query Services($deploymentGroupSlug: String!){
...DeploymentGroupInfo
services {
...ServiceInfo
parent
branches {
name
slug
instances {
id
status
healthy
}
}
connections
instances {
id

View File

@ -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;
}, []);
};