utils.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import type {OrganizationSummary, Project} from 'sentry/types';
  2. import {NOTIFICATION_SETTINGS_PATHNAMES} from 'sentry/views/settings/account/notifications/constants';
  3. /**
  4. * Which fine-tuning parts are grouped by project
  5. */
  6. const notificationsByProject = ['alerts', 'email', 'workflow', 'spikeProtection'];
  7. export const isGroupedByProject = (notificationType: string): boolean =>
  8. notificationsByProject.includes(notificationType);
  9. export const getParentKey = (notificationType: string): string => {
  10. return isGroupedByProject(notificationType) ? 'project' : 'organization';
  11. };
  12. export const groupByOrganization = (
  13. projects: Project[]
  14. ): Record<string, {organization: OrganizationSummary; projects: Project[]}> => {
  15. return projects.reduce<
  16. Record<string, {organization: OrganizationSummary; projects: Project[]}>
  17. >((acc, project) => {
  18. const orgSlug = project.organization.slug;
  19. if (acc.hasOwnProperty(orgSlug)) {
  20. acc[orgSlug].projects.push(project);
  21. } else {
  22. acc[orgSlug] = {
  23. organization: project.organization,
  24. projects: [project],
  25. };
  26. }
  27. return acc;
  28. }, {});
  29. };
  30. /**
  31. * Returns a link to docs on explaining how to manage quotas for that event type
  32. */
  33. export function getDocsLinkForEventType(
  34. event: 'error' | 'transaction' | 'attachment' | 'replay' | 'monitorSeat' | 'span'
  35. ) {
  36. switch (event) {
  37. case 'transaction':
  38. // For pre-AM3 plans prior to June 11th, 2024
  39. return 'https://docs.sentry.io/pricing/quotas/legacy-manage-transaction-quota/';
  40. case 'span':
  41. // For post-AM3 plans after June 11th, 2024
  42. return 'https://docs.sentry.io/pricing/quotas/manage-transaction-quota/';
  43. case 'attachment':
  44. return 'https://docs.sentry.io/product/accounts/quotas/manage-attachments-quota/#2-rate-limiting';
  45. case 'replay':
  46. return 'https://docs.sentry.io/product/session-replay/';
  47. case 'monitorSeat':
  48. return 'https://docs.sentry.io/product/crons/';
  49. default:
  50. return 'https://docs.sentry.io/product/accounts/quotas/manage-event-stream-guide/#common-workflows-for-managing-your-event-stream';
  51. }
  52. }
  53. /**
  54. * Returns the corresponding notification type name from the router path name
  55. */
  56. export function getNotificationTypeFromPathname(routerPathname: string) {
  57. const result = Object.entries(NOTIFICATION_SETTINGS_PATHNAMES).find(
  58. ([_, pathname]) => pathname === routerPathname
  59. ) ?? [routerPathname];
  60. return result[0];
  61. }