index.tsx 753 B

123456789101112131415161718192021222324
  1. import {BooleanOperator} from 'sentry/components/searchSyntax/parser';
  2. import type {MetricWidgetQueryParams} 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(widget: MetricWidgetQueryParams) {
  9. const focusedSeriesQuery = widget.focusedSeries
  10. ?.map(series => {
  11. if (!series.groupBy) {
  12. return '';
  13. }
  14. return `(${constructQueryString(series.groupBy)})`;
  15. })
  16. .filter(Boolean)
  17. .join(` ${BooleanOperator.OR} `);
  18. return focusedSeriesQuery
  19. ? `${widget.query} (${focusedSeriesQuery})`.trim()
  20. : widget.query;
  21. }