index.tsx 779 B

1234567891011121314151617181920212223242526272829303132
  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. return `(${query}) AND (${focusedSeriesQuery})`;
  27. }