utils.tsx 887 B

123456789101112131415161718192021222324252627282930313233343536
  1. import {BreadcrumbType, Crumb} from 'sentry/types/breadcrumbs';
  2. /**
  3. * Generate breadcrumb descriptions based on type
  4. */
  5. export function getDescription(crumb: Crumb) {
  6. switch (crumb.type) {
  7. case BreadcrumbType.NAVIGATION:
  8. return `${crumb.data?.to ?? ''}`;
  9. case BreadcrumbType.DEFAULT:
  10. return JSON.stringify(crumb.data);
  11. default:
  12. return crumb.message || '';
  13. }
  14. }
  15. /**
  16. * Get title of breadcrumb
  17. */
  18. export function getTitle(crumb: Crumb) {
  19. const [type, action] = crumb.category?.split('.') || [];
  20. // Supports replay specific breadcrumbs
  21. if (crumb.data && 'label' in crumb.data) {
  22. return crumb.data.label;
  23. }
  24. return `${type === 'ui' ? 'User' : type} ${action || ''}`;
  25. }
  26. /**
  27. * Generate breadcrumb title + descriptions
  28. */
  29. export function getDetails(crumb: Crumb) {
  30. return {title: getTitle(crumb), description: getDescription(crumb)};
  31. }