utils.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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'
  35. ) {
  36. switch (event) {
  37. case 'transaction':
  38. return 'https://docs.sentry.io/product/performance/transaction-summary/#what-is-a-transaction';
  39. case 'attachment':
  40. return 'https://docs.sentry.io/product/accounts/quotas/manage-attachments-quota/#2-rate-limiting';
  41. case 'replay':
  42. return 'https://docs.sentry.io/product/session-replay/';
  43. case 'monitorSeat':
  44. return 'https://docs.sentry.io/product/crons/';
  45. default:
  46. return 'https://docs.sentry.io/product/accounts/quotas/manage-event-stream-guide/#common-workflows-for-managing-your-event-stream';
  47. }
  48. }
  49. /**
  50. * Returns the corresponding notification type name from the router path name
  51. */
  52. export function getNotificationTypeFromPathname(routerPathname: string) {
  53. const result = Object.entries(NOTIFICATION_SETTINGS_PATHNAMES).find(
  54. ([_, pathname]) => pathname === routerPathname
  55. ) ?? [routerPathname];
  56. return result[0];
  57. }