1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 06:00:06 +02:00

fix(cp-frontend): handle no data in metrics loop

This commit is contained in:
Sérgio Ramos 2017-08-30 14:02:27 +01:00
parent 3db2cfaea5
commit d08a8b00a9
3 changed files with 19 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import {
const ServiceScale = ({
service,
handleSubmit = () => {},
onCancelClick = () => {},
onCancel = () => {},
invalid,
pristine
}) => (
@ -32,7 +32,7 @@ const ServiceScale = ({
<FormMeta />
<NumberInput minValue={1} />
</FormGroup>
<Button secondary onClick={onCancelClick}>
<Button type="button" secondary onClick={onCancel}>
Cancel
</Button>
<Button type="submit" disabled={pristine || invalid} secondary>

View File

@ -1,7 +1,9 @@
import React, { Component } from 'react';
import { compose, graphql } from 'react-apollo';
import moment from 'moment';
import find from 'lodash.find';
import uniqBy from 'lodash.uniqby';
import get from 'lodash.get';
import moment from 'moment';
export const MetricNames = [
'AVG_MEM_BYTES',
@ -53,8 +55,13 @@ export const withServiceMetricsGql = ({
instanceId,
metricName
) => {
return previousResult.deploymentGroup.services
.find(s => s.id === serviceId)
const service = find(get(previousResult, 'deploymentGroup.services', []), ['id', serviceId]);
if (!service) {
return [];
}
return service
.instances.find(i => i.id === instanceId)
.metrics.find(m => m.name === metricName).metrics;
};

View File

@ -184,7 +184,13 @@ export default compose(
return false;
}
const previousEnd = services
const _services = forceArray(services);
if (!_services.length) {
return false;
}
const previousEnd = _services
.map(service => get(service, 'instances[0].metrics[0].end', null))
.filter(Boolean)
.shift();