breadcrumb.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import type {Location} from 'history';
  2. import omit from 'lodash/omit';
  3. import type {Crumb} from 'sentry/components/breadcrumbs';
  4. import Breadcrumbs from 'sentry/components/breadcrumbs';
  5. import {t} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types';
  7. import type {Event} from 'sentry/types/event';
  8. import type EventView from 'sentry/utils/discover/eventView';
  9. import {getDiscoverLandingUrl} from 'sentry/utils/discover/urls';
  10. type Props = {
  11. eventView: EventView;
  12. location: Location;
  13. organization: Organization;
  14. event?: Event;
  15. isHomepage?: boolean;
  16. };
  17. function DiscoverBreadcrumb({
  18. eventView,
  19. event,
  20. organization,
  21. location,
  22. isHomepage,
  23. }: Props) {
  24. const crumbs: Crumb[] = [];
  25. const discoverTarget = organization.features.includes('discover-query')
  26. ? {
  27. pathname: getDiscoverLandingUrl(organization),
  28. query: {
  29. ...omit(location.query, 'homepage'),
  30. ...eventView.generateBlankQueryStringObject(),
  31. ...eventView.getPageFiltersQuery(),
  32. },
  33. }
  34. : null;
  35. crumbs.push({
  36. to:
  37. isHomepage && eventView
  38. ? eventView.getResultsViewUrlTarget(organization.slug, isHomepage)
  39. : discoverTarget,
  40. label: t('Discover'),
  41. });
  42. if (!isHomepage && eventView && eventView.isValid()) {
  43. crumbs.push({
  44. to: `/organizations/${organization.slug}/discover/queries/`,
  45. label: t('Saved Queries'),
  46. });
  47. crumbs.push({
  48. to: eventView.getResultsViewUrlTarget(organization.slug, isHomepage),
  49. label: eventView.name || '',
  50. });
  51. }
  52. if (event) {
  53. crumbs.push({
  54. label: t('Event Detail'),
  55. });
  56. }
  57. return <Breadcrumbs crumbs={crumbs} />;
  58. }
  59. export default DiscoverBreadcrumb;