metricRulePresets.tsx 1.4 KB

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