utils.tsx 2.3 KB

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