breadcrumb.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {Location} from 'history';
  2. import Breadcrumbs, {Crumb} from 'sentry/components/breadcrumbs';
  3. import {t} from 'sentry/locale';
  4. import {Organization} from 'sentry/types';
  5. import {Event} from 'sentry/types/event';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {getDiscoverLandingUrl} from 'sentry/utils/discover/urls';
  8. type Props = {
  9. eventView: EventView;
  10. location: Location;
  11. organization: Organization;
  12. event?: Event;
  13. };
  14. function DiscoverBreadcrumb({eventView, event, organization, location}: Props) {
  15. const crumbs: Crumb[] = [];
  16. const discoverTarget = organization.features.includes('discover-query')
  17. ? {
  18. pathname: getDiscoverLandingUrl(organization),
  19. query: {
  20. ...location.query,
  21. ...eventView.generateBlankQueryStringObject(),
  22. ...eventView.getPageFiltersQuery(),
  23. },
  24. }
  25. : null;
  26. crumbs.push({
  27. to: discoverTarget,
  28. label: t('Discover'),
  29. });
  30. if (eventView && eventView.isValid()) {
  31. crumbs.push({
  32. to: eventView.getResultsViewUrlTarget(organization.slug),
  33. label: eventView.name || '',
  34. });
  35. }
  36. if (event) {
  37. crumbs.push({
  38. label: t('Event Detail'),
  39. });
  40. }
  41. return <Breadcrumbs crumbs={crumbs} />;
  42. }
  43. export default DiscoverBreadcrumb;