useModuleBreadcrumbs.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import type {Crumb} from 'sentry/components/breadcrumbs';
  2. import useOrganization from 'sentry/utils/useOrganization';
  3. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  4. import {useInsightsTitle} from 'sentry/views/performance/utils/useInsightsTitle';
  5. import {useInsightsURL} from 'sentry/views/performance/utils/useInsightsURL';
  6. import {useModuleTitle} from 'sentry/views/performance/utils/useModuleTitle';
  7. import {useModuleURL} from 'sentry/views/performance/utils/useModuleURL';
  8. import {ModuleName} from 'sentry/views/starfish/types';
  9. type ModuleNameStrings = `${ModuleName}`;
  10. type RoutableModuleNames = Exclude<ModuleNameStrings, '' | 'other'>;
  11. export function useModuleBreadcrumbs(moduleName: RoutableModuleNames): Crumb[] {
  12. const organization = useOrganization();
  13. const insightsURL = useInsightsURL(moduleName);
  14. const insightsTitle = useInsightsTitle(moduleName);
  15. const moduleLabel = useModuleTitle(moduleName);
  16. const moduleTo = useModuleURL(moduleName);
  17. // If `insights` flag is present, the root crumb is "Insights". If it's absent, LLMs base crumb is nothing, and other Insights modules base breadcrumb is "Performance"
  18. return organization?.features?.includes('performance-insights')
  19. ? [
  20. {
  21. label: insightsTitle,
  22. to: normalizeUrl(`/organizations/${organization.slug}/${insightsURL}/`),
  23. preservePageFilters: true,
  24. },
  25. {
  26. label: moduleLabel,
  27. to: moduleTo,
  28. preservePageFilters: true,
  29. },
  30. ]
  31. : moduleName === ModuleName.AI
  32. ? [
  33. {
  34. label: moduleLabel,
  35. to: moduleTo,
  36. preservePageFilters: true,
  37. },
  38. ]
  39. : [
  40. {
  41. label: insightsTitle,
  42. to: normalizeUrl(`/organizations/${organization.slug}/${insightsURL}/`),
  43. preservePageFilters: true,
  44. },
  45. {
  46. label: moduleLabel,
  47. to: moduleTo,
  48. preservePageFilters: true,
  49. },
  50. ];
  51. }