groupBys.tsx 940 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type {Location} from 'history';
  2. import {defined} from 'sentry/utils';
  3. import {decodeList} from 'sentry/utils/queryString';
  4. export const UNGROUPED = '';
  5. export function defaultGroupBys(): string[] {
  6. return ['span.op'];
  7. }
  8. export function getGroupBysFromLocation(location: Location): string[] {
  9. const rawGroupBys = decodeList(location.query.groupBy);
  10. if (rawGroupBys.length) {
  11. return rawGroupBys;
  12. }
  13. // If the param is defined by has empty string for value
  14. // we're still getting back the empty list. This special
  15. // cases it and ensures we permit the empty group by.
  16. if (defined(location.query.groupBy)) {
  17. return [''];
  18. }
  19. return defaultGroupBys();
  20. }
  21. export function updateLocationWithGroupBys(
  22. location: Location,
  23. groupBys: string[] | null | undefined
  24. ) {
  25. if (defined(groupBys)) {
  26. location.query.groupBy = groupBys;
  27. } else if (groupBys === null) {
  28. delete location.query.groupBy;
  29. }
  30. }