index.tsx 793 B

12345678910111213141516171819202122232425
  1. import {BooleanOperator} from 'sentry/components/searchSyntax/parser';
  2. import type {FocusedMetricsSeries} from 'sentry/utils/metrics/types';
  3. function constructQueryString(queryObject: Record<string, string>) {
  4. return Object.entries(queryObject)
  5. .map(([key, value]) => `${key}:"${value}"`)
  6. .join(' ');
  7. }
  8. export function getQueryWithFocusedSeries(
  9. query: string,
  10. focusedSeries?: FocusedMetricsSeries[]
  11. ) {
  12. const focusedSeriesQuery = focusedSeries
  13. ?.map(series => {
  14. if (!series.groupBy || Object.keys(series.groupBy).length === 0) {
  15. return '';
  16. }
  17. return `(${constructQueryString(series.groupBy)})`;
  18. })
  19. .filter(Boolean)
  20. .join(` ${BooleanOperator.OR} `);
  21. return focusedSeriesQuery ? `${query} (${focusedSeriesQuery})`.trim() : query;
  22. }