breadcrumb.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, getDiscoverQueriesUrl} 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. const HOMEPAGE_DEFAULT_LABEL = t('New Query');
  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: organization.features.includes('discover-query-builder-as-landing-page')
  28. ? getDiscoverQueriesUrl(organization)
  29. : getDiscoverLandingUrl(organization),
  30. query: {
  31. ...omit(location.query, 'homepage'),
  32. ...eventView.generateBlankQueryStringObject(),
  33. ...eventView.getPageFiltersQuery(),
  34. },
  35. }
  36. : null;
  37. crumbs.push({
  38. to: discoverTarget,
  39. label: t('Discover'),
  40. });
  41. if (eventView && eventView.isValid()) {
  42. crumbs.push({
  43. to: eventView.getResultsViewUrlTarget(organization.slug, isHomepage),
  44. label: isHomepage ? HOMEPAGE_DEFAULT_LABEL : eventView.name || '',
  45. });
  46. }
  47. if (event) {
  48. crumbs.push({
  49. label: t('Event Detail'),
  50. });
  51. }
  52. return <Breadcrumbs crumbs={crumbs} />;
  53. }
  54. export default DiscoverBreadcrumb;