utils.tsx 2.5 KB

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