transformMetricsResponseToSeries.tsx 783 B

1234567891011121314151617181920212223242526
  1. import {MetricsApiResponse} from 'sentry/types';
  2. import {Series} from 'sentry/types/echarts';
  3. export function transformMetricsResponseToSeries(
  4. response: MetricsApiResponse | null,
  5. queryAlias?: string
  6. ): Series[] {
  7. return (
  8. response?.groups.flatMap(group => {
  9. if (group.series === undefined) {
  10. return [];
  11. }
  12. return Object.keys(group.series).map(field => ({
  13. seriesName: `${queryAlias ? `${queryAlias}: ` : ''}${field}${Object.entries(
  14. group.by
  15. )
  16. .map(([key, value]) => `|${key}:${value}`)
  17. .join('')}`,
  18. data: response.intervals.map((interval, index) => ({
  19. name: interval,
  20. value: group.series ? group.series[field][index] ?? 0 : 0,
  21. })),
  22. }));
  23. }) ?? []
  24. );
  25. }