functions.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { alignOptions, aggOptions } from './constants';
  2. import uniqBy from 'lodash/uniqBy';
  3. export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');
  4. export const getMetricTypesByService = (metricDescriptors, service) =>
  5. metricDescriptors.filter(m => m.service === service);
  6. export const getMetricTypes = (metricDescriptors, metricType, selectedService) => {
  7. const metricTypes = getMetricTypesByService(metricDescriptors, selectedService).map(m => ({
  8. value: m.type,
  9. name: m.displayName,
  10. }));
  11. const metricTypeExistInArray = metricTypes.some(m => m.value === metricType);
  12. const selectedMetricType = metricTypeExistInArray ? metricTypeExistInArray.value : metricTypes[0].value;
  13. return {
  14. metricTypes,
  15. selectedMetricType,
  16. };
  17. };
  18. export const getAlignmentOptionsByMetric = (metricValueType, metricKind) => {
  19. return !metricValueType
  20. ? []
  21. : alignOptions.filter(i => {
  22. return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
  23. });
  24. };
  25. export const getAggregationOptionsByMetric = (valueType, metricKind) => {
  26. return !metricKind
  27. ? []
  28. : aggOptions.filter(i => {
  29. return i.valueTypes.indexOf(valueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
  30. });
  31. };