index.tsx 840 B

123456789101112131415161718192021222324252627282930313233343536
  1. import {BooleanOperator} from 'sentry/components/searchSyntax/parser';
  2. function constructQueryString(queryObject: Record<string, string>) {
  3. return Object.entries(queryObject)
  4. .map(([key, value]) => `${key}:"${value}"`)
  5. .join(' ');
  6. }
  7. export function extendQueryWithGroupBys(
  8. query: string = '',
  9. groupBys?: (Record<string, string> | undefined)[]
  10. ) {
  11. const focusedSeriesQuery = groupBys
  12. ?.map(groupBy => {
  13. if (!groupBy || Object.keys(groupBy).length === 0) {
  14. return '';
  15. }
  16. return constructQueryString(groupBy);
  17. })
  18. .filter(Boolean)
  19. .join(` ${BooleanOperator.OR} `);
  20. if (!focusedSeriesQuery) {
  21. return query;
  22. }
  23. if (!query) {
  24. return focusedSeriesQuery;
  25. }
  26. if (query === focusedSeriesQuery) {
  27. return query;
  28. }
  29. return `(${query}) AND (${focusedSeriesQuery})`;
  30. }