breadcrumb.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. isHomepage && eventView
  37. ? eventView.getResultsViewUrlTarget(organization.slug, isHomepage)
  38. : discoverTarget,
  39. label: t('Discover'),
  40. });
  41. if (!isHomepage && eventView && eventView.isValid()) {
  42. crumbs.push({
  43. to: `/organizations/${organization.slug}/discover/queries/`,
  44. label: t('Saved Queries'),
  45. });
  46. crumbs.push({
  47. to: eventView.getResultsViewUrlTarget(organization.slug, isHomepage),
  48. label: eventView.name || '',
  49. });
  50. }
  51. if (event) {
  52. crumbs.push({
  53. label: t('Event Detail'),
  54. });
  55. }
  56. return <Breadcrumbs crumbs={crumbs} />;
  57. }
  58. export default DiscoverBreadcrumb;