utils.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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:
  36. | 'error'
  37. | 'transaction'
  38. | 'attachment'
  39. | 'replay'
  40. | 'monitorSeat'
  41. | 'span'
  42. | 'profileDuration'
  43. ) {
  44. switch (event) {
  45. case 'transaction':
  46. // For pre-AM3 plans prior to June 11th, 2024
  47. return 'https://docs.sentry.io/pricing/quotas/legacy-manage-transaction-quota/';
  48. case 'span':
  49. // For post-AM3 plans after June 11th, 2024
  50. return 'https://docs.sentry.io/pricing/quotas/manage-transaction-quota/';
  51. case 'attachment':
  52. return 'https://docs.sentry.io/product/accounts/quotas/manage-attachments-quota/#2-rate-limiting';
  53. case 'replay':
  54. return 'https://docs.sentry.io/product/session-replay/';
  55. case 'monitorSeat':
  56. return 'https://docs.sentry.io/product/crons/';
  57. case 'profileDuration':
  58. return 'https://docs.sentry.io/product/explore/profiling/';
  59. default:
  60. return 'https://docs.sentry.io/product/accounts/quotas/manage-event-stream-guide/#common-workflows-for-managing-your-event-stream';
  61. }
  62. }
  63. /**
  64. * Returns the corresponding notification type name from the router path name
  65. */
  66. export function getNotificationTypeFromPathname(routerPathname: string) {
  67. const result = Object.entries(NOTIFICATION_SETTINGS_PATHNAMES).find(
  68. ([_, pathname]) => pathname === routerPathname
  69. ) ?? [routerPathname];
  70. return result[0];
  71. }