metricRulePresets.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import type {LinkProps} from 'sentry/components/links/link';
  2. import {t} from 'sentry/locale';
  3. import type {Project} from 'sentry/types';
  4. import {DisplayModes} from 'sentry/utils/discover/types';
  5. import type {TimePeriodType} from 'sentry/views/alerts/rules/metric/details/constants';
  6. import type {MetricRule} from 'sentry/views/alerts/rules/metric/types';
  7. import {getMetricRuleDiscoverUrl} from 'sentry/views/alerts/utils/getMetricRuleDiscoverUrl';
  8. interface PresetCta {
  9. /**
  10. * The CTA text
  11. */
  12. buttonText: string;
  13. /**
  14. * The location to direct to upon clicking the CTA.
  15. */
  16. to: LinkProps['to'];
  17. }
  18. interface PresetCtaOpts {
  19. orgSlug: string;
  20. projects: Project[];
  21. timePeriod: TimePeriodType;
  22. query?: string;
  23. rule?: MetricRule;
  24. }
  25. /**
  26. * Get the CTA used for alert rules that do not have a preset
  27. */
  28. export function makeDefaultCta({
  29. orgSlug,
  30. projects,
  31. rule,
  32. timePeriod,
  33. query,
  34. }: PresetCtaOpts): PresetCta {
  35. if (!rule) {
  36. return {
  37. buttonText: t('Open in Discover'),
  38. to: '',
  39. };
  40. }
  41. const extraQueryParams = {
  42. display: DisplayModes.TOP5,
  43. };
  44. return {
  45. buttonText: t('Open in Discover'),
  46. to: getMetricRuleDiscoverUrl({
  47. orgSlug,
  48. projects,
  49. rule,
  50. timePeriod,
  51. query,
  52. extraQueryParams,
  53. }),
  54. };
  55. }