utils.tsx 2.9 KB

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