transformMetricsResponseToSeries.tsx 686 B

1234567891011121314151617181920212223
  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. Object.keys(group.series).map(field => ({
  10. seriesName: `${queryAlias ? `${queryAlias}: ` : ''}${field}${Object.entries(
  11. group.by
  12. )
  13. .map(([key, value]) => `|${key}:${value}`)
  14. .join('')}`,
  15. data: response.intervals.map((interval, index) => ({
  16. name: interval,
  17. value: group.series[field][index] ?? 0,
  18. })),
  19. }))
  20. ) ?? []
  21. );
  22. }