utils.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {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'
  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. default:
  44. return 'https://docs.sentry.io/product/accounts/quotas/manage-event-stream-guide/#common-workflows-for-managing-your-event-stream';
  45. }
  46. }
  47. /**
  48. * Returns the corresponding notification type name from the router path name
  49. */
  50. export function getNotificationTypeFromPathname(routerPathname: string) {
  51. const result = Object.entries(NOTIFICATION_SETTINGS_PATHNAMES).find(
  52. ([_, pathname]) => pathname === routerPathname
  53. ) ?? [routerPathname];
  54. return result[0];
  55. }