+ { /*
*/ }
+ {serviceList}
+ { /* */ }
+
+
+
);
}
}
-const ServiceListWithData = graphql(ServicesQuery, {
+const PortalGql = graphql(PortalQuery, {});
+
+const ServicesGql = graphql(ServicesQuery, {
options(props) {
return {
variables: {
@@ -46,10 +70,17 @@ const ServiceListWithData = graphql(ServicesQuery, {
}
},
props: ({ data: { deploymentGroup, loading, error }}) => ({
- services: deploymentGroup ? deploymentGroup.services : null,
+ deploymentGroup,
+ services: deploymentGroup ?
+ processServices(deploymentGroup.services, null) : null,
loading,
error
})
-})(ServiceList);
+});
+
+const ServiceListWithData = compose(
+ PortalGql,
+ ServicesGql
+)(ServiceList);
export default ServiceListWithData;
diff --git a/frontend/src/containers/services/topology.js b/frontend/src/containers/services/topology.js
index 10c2cf4a..ec69408d 100644
--- a/frontend/src/containers/services/topology.js
+++ b/frontend/src/containers/services/topology.js
@@ -5,6 +5,8 @@ import styled from 'styled-components';
import PortalQuery from '@graphql/Portal.gql';
import ServicesQuery from '@graphql/ServicesTopology.gql';
+import { processServices } from '@root/state/selectors';
+
import { LayoutContainer } from '@components/layout';
import { Loader, ErrorMessage } from '@components/messaging';
@@ -49,61 +51,18 @@ const ServicesTopology = ({
)
}
- const findService = (ss, uuid) =>
- ss.reduce((s, service) => service.uuid === uuid ?
- service : s, null);
-
- const getService = (s, i) => ({
- index: i,
- ...s,
- metrics: [1, 2, 3].map((m) => ({
- name: `${m}`,
- value: `${m}`
- })),
- instances: s.instances.length,
- datacenter: datacenter
- });
-
- // Selector???
- const ss = services.reduce((ss, s, i) => {
- // check whether it exits in thing, if so, add as child
- // if not, create and add as child
-
- if(s.parent) {
- let parent = findService(ss, s.parent);
- if(!parent) {
- parent = { uuid: s.parent };
- ss.push(parent);
- }
- if(!parent.children) {
- parent.children = [];
- }
- parent.children.push(getService(s, i));
- }
- if(!s.parent) {
- ss.push(getService(s, i));
- }
- return ss;
- }, []);
-
return (
);
}
-const PortalGql = graphql(PortalQuery, {
- props: ({ data: { portal, loading, error }}) => ({
- datacenter: portal ? portal.datacenter.id : null,
- loading,
- error
- })
-})
+const PortalGql = graphql(PortalQuery, {});
const ServicesGql = graphql(ServicesQuery, {
options(props) {
@@ -114,7 +73,8 @@ const ServicesGql = graphql(ServicesQuery, {
}
},
props: ({ data: { deploymentGroup, loading, error }}) => ({
- services: deploymentGroup ? deploymentGroup.services : null,
+ services: deploymentGroup ?
+ processServices(deploymentGroup.services, null) : null,
loading,
error
})
diff --git a/frontend/src/graphql/Services.gql b/frontend/src/graphql/Services.gql
index a572584d..4fe85705 100644
--- a/frontend/src/graphql/Services.gql
+++ b/frontend/src/graphql/Services.gql
@@ -6,6 +6,10 @@ query Services($deploymentGroupSlug: String!){
...DeploymentGroupInfo
services {
...ServiceInfo
+ parent
+ instances {
+ uuid
+ }
}
}
}
diff --git a/frontend/src/router.js b/frontend/src/router.js
index b05a0e82..0a8139b0 100644
--- a/frontend/src/router.js
+++ b/frontend/src/router.js
@@ -45,11 +45,11 @@ const Router = (
-
+
-
-
+
+
diff --git a/frontend/src/state/selectors.js b/frontend/src/state/selectors.js
index 248cc5ef..231b685e 100644
--- a/frontend/src/state/selectors.js
+++ b/frontend/src/state/selectors.js
@@ -2,7 +2,9 @@ import { createSelector } from 'reselect';
const apollo = (state) => state.apollo;
-const deploymentGroupById = (deploymentGroupSlug) => createSelector(
+// redux selectors //
+
+const deploymentGroupBySlug = (deploymentGroupSlug) => createSelector(
[apollo],
(apollo) => apollo ? Object.keys(apollo).reduce((dg, k) =>
apollo[k].__typename === 'DeploymentGroup' &&
@@ -10,7 +12,7 @@ const deploymentGroupById = (deploymentGroupSlug) => createSelector(
apollo[k] : dg, {}) : null
);
-const servicesById = (serviceSlug) => createSelector(
+const servicesBySlug = (serviceSlug) => createSelector(
[apollo],
(apollo) => apollo ? Object.keys(apollo).reduce((s, k) =>
apollo[k].__typename === 'Service' &&
@@ -18,7 +20,50 @@ const servicesById = (serviceSlug) => createSelector(
apollo[k] : s, {}) : null
);
-export {
- deploymentGroupById as deploymentGroupByIdSelector,
- servicesById as servicesByIdSelector
+// apollo gql utils //
+
+const findService = (services, uuid) =>
+ services.reduce((service, s) => s.uuid === uuid ?
+ s : service, null);
+
+const getService = (service, index, datacenter) => ({
+ index,
+ ...service,
+ // tmp for topology
+ metrics: [1, 2, 3].map((m) => ({
+ name: `${m}`,
+ value: `${m}`
+ })),
+ instances: service.instances.length,
+ datacenter
+});
+
+const processServices = (services, datacenter) => {
+ console.log('services = ', services);
+ return services.reduce((ss, s, i) => {
+ // check whether it exits in thing, if so, add as child
+ // if not, create and add as child
+
+ if(s.parent) {
+ let parent = findService(ss, s.parent);
+ if(!parent) {
+ parent = { uuid: s.parent };
+ ss.push(parent);
+ }
+ if(!parent.children) {
+ parent.children = [];
+ }
+ parent.children.push(getService(s, i, datacenter));
+ }
+ if(!s.parent) {
+ ss.push(getService(s, i, datacenter));
+ }
+ return ss;
+ }, []);
+}
+
+export {
+ deploymentGroupBySlug as deploymentGroupBySlugSelector,
+ servicesBySlug as servicesBySlugSelector,
+ processServices as processServices
}