utils.tsx 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  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?.from ? `${crumb.data?.from} => ` : ''}${
  9. crumb.data?.to ?? ''
  10. }`;
  11. case BreadcrumbType.DEFAULT:
  12. return JSON.stringify(crumb.data);
  13. default:
  14. return crumb.message || '';
  15. }
  16. }
  17. /**
  18. * Get title of breadcrumb
  19. */
  20. export function getTitle(crumb: Crumb) {
  21. const [type, action] = crumb.category?.split('.') || [];
  22. // Supports replay specific breadcrumbs
  23. if (crumb.data && 'label' in crumb.data) {
  24. return crumb.data.label;
  25. }
  26. return `${type === 'ui' ? 'User' : type} ${action || ''}`;
  27. }
  28. /**
  29. * Generate breadcrumb title + descriptions
  30. */
  31. export function getDetails(crumb: Crumb) {
  32. return {title: getTitle(crumb), description: getDescription(crumb)};
  33. }