getAlertsUrl.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as qs from 'query-string';
  2. import type {PageFilters} from 'sentry/types/core';
  3. import type {Project} from 'sentry/types/project';
  4. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  5. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  6. export function getAlertsUrl({
  7. project,
  8. query,
  9. aggregate,
  10. orgSlug,
  11. pageFilters,
  12. name,
  13. interval,
  14. dataset = Dataset.GENERIC_METRICS,
  15. }: {
  16. aggregate: string;
  17. orgSlug: string;
  18. pageFilters: PageFilters;
  19. project: Project;
  20. dataset?: Dataset;
  21. interval?: string;
  22. name?: string;
  23. query?: string;
  24. }) {
  25. const statsPeriod = getStatsPeriod(pageFilters);
  26. const environment = pageFilters.environments;
  27. const queryParams = {
  28. aggregate: aggregate,
  29. dataset,
  30. project: project.slug,
  31. eventTypes: 'transaction',
  32. query,
  33. statsPeriod,
  34. environment,
  35. name,
  36. interval,
  37. };
  38. return normalizeUrl(
  39. `/organizations/${orgSlug}/alerts/new/metric/?${qs.stringify(queryParams)}`
  40. );
  41. }
  42. // Alert rules only support 24h, 3d, 7d, 14d periods
  43. function getStatsPeriod(pageFilters: PageFilters) {
  44. const {period} = pageFilters.datetime;
  45. switch (period) {
  46. case '24h':
  47. case '3d':
  48. case '7d':
  49. case '14d':
  50. return period;
  51. default:
  52. return '7d';
  53. }
  54. }