2018-10-26 20:03:05 +08:00
|
|
|
import uniqBy from 'lodash/uniqBy';
|
2018-10-31 20:55:40 +08:00
|
|
|
import { alignOptions, aggOptions } from './constants';
|
2018-10-26 20:03:05 +08:00
|
|
|
|
|
|
|
|
export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');
|
|
|
|
|
|
|
|
|
|
export const getMetricTypesByService = (metricDescriptors, service) =>
|
|
|
|
|
metricDescriptors.filter(m => m.service === service);
|
2018-10-29 23:27:53 +08:00
|
|
|
|
2018-10-31 20:36:41 +08:00
|
|
|
export const getMetricTypes = (metricDescriptors, metricType, selectedService) => {
|
|
|
|
|
const metricTypes = getMetricTypesByService(metricDescriptors, selectedService).map(m => ({
|
2018-10-31 20:07:57 +08:00
|
|
|
value: m.type,
|
|
|
|
|
name: m.displayName,
|
|
|
|
|
}));
|
2018-10-31 20:36:41 +08:00
|
|
|
const metricTypeExistInArray = metricTypes.some(m => m.value === metricType);
|
|
|
|
|
const selectedMetricType = metricTypeExistInArray ? metricTypeExistInArray.value : metricTypes[0].value;
|
2018-10-31 20:07:57 +08:00
|
|
|
return {
|
|
|
|
|
metricTypes,
|
2018-10-31 20:36:41 +08:00
|
|
|
selectedMetricType,
|
2018-10-31 20:07:57 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-29 23:27:53 +08:00
|
|
|
export const getAlignmentOptionsByMetric = (metricValueType, metricKind) => {
|
|
|
|
|
return !metricValueType
|
|
|
|
|
? []
|
|
|
|
|
: alignOptions.filter(i => {
|
|
|
|
|
return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-10-29 23:57:07 +08:00
|
|
|
|
|
|
|
|
export const getAggregationOptionsByMetric = (valueType, metricKind) => {
|
|
|
|
|
return !metricKind
|
|
|
|
|
? []
|
|
|
|
|
: aggOptions.filter(i => {
|
|
|
|
|
return i.valueTypes.indexOf(valueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
|
|
|
|
|
});
|
|
|
|
|
};
|