utils.tsx 2.9 KB

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