breadcrumb.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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, getDiscoverQueriesUrl} 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: organization.features.includes('discover-query-builder-as-landing-page')
  19. ? getDiscoverQueriesUrl(organization)
  20. : getDiscoverLandingUrl(organization),
  21. query: {
  22. ...location.query,
  23. ...eventView.generateBlankQueryStringObject(),
  24. ...eventView.getPageFiltersQuery(),
  25. },
  26. }
  27. : null;
  28. crumbs.push({
  29. to: discoverTarget,
  30. label: t('Discover'),
  31. });
  32. if (eventView && eventView.isValid()) {
  33. crumbs.push({
  34. to: eventView.getResultsViewUrlTarget(organization.slug),
  35. label: eventView.name || '',
  36. });
  37. }
  38. if (event) {
  39. crumbs.push({
  40. label: t('Event Detail'),
  41. });
  42. }
  43. return <Breadcrumbs crumbs={crumbs} />;
  44. }
  45. export default DiscoverBreadcrumb;