breadcrumb.tsx 1.8 KB

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