functions.ts 1.1 KB

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