From d9ae6eb34a0ae2f06d65bf42860267c18a997d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Wed, 30 Aug 2017 14:52:17 +0100 Subject: [PATCH] fix(cp-frontend): handle no previous metrics --- .../containers/metrics/metrics-data-hoc.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/cp-frontend/src/containers/metrics/metrics-data-hoc.js b/packages/cp-frontend/src/containers/metrics/metrics-data-hoc.js index 89619daa..6324b2a5 100644 --- a/packages/cp-frontend/src/containers/metrics/metrics-data-hoc.js +++ b/packages/cp-frontend/src/containers/metrics/metrics-data-hoc.js @@ -55,7 +55,13 @@ export const withServiceMetricsGql = ({ instanceId, metricName ) => { - const service = find(get(previousResult, 'deploymentGroup.services', []), [ + const services = get(previousResult, 'deploymentGroup.services', []); + + if (!services.length) { + return []; + } + + const service = find(services, [ 'id', serviceId ]); @@ -64,9 +70,19 @@ export const withServiceMetricsGql = ({ return []; } - return service.instances - .find(i => i.id === instanceId) - .metrics.find(m => m.name === metricName).metrics; + const instance = find(service.instances, ['id', instanceId]); + + if (!instance) { + return []; + } + + const metrics = find(instance.metrics, ['name', metricName]); + + if (!metrics) { + return []; + } + + return get(metrics, 'metrics', []); }; const getNextResult = (previousResult, fetchNextResult) => {