breadcrumb.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {Component} from 'react';
  2. import {Location} from 'history';
  3. import Breadcrumbs, {Crumb} from 'app/components/breadcrumbs';
  4. import {t} from 'app/locale';
  5. import {Organization} from 'app/types';
  6. import {Event} from 'app/types/event';
  7. import EventView from 'app/utils/discover/eventView';
  8. import {getDiscoverLandingUrl} from 'app/utils/discover/urls';
  9. type DefaultProps = {
  10. event: Event | undefined;
  11. };
  12. type Props = DefaultProps & {
  13. eventView: EventView;
  14. organization: Organization;
  15. location: Location;
  16. };
  17. class DiscoverBreadcrumb extends Component<Props> {
  18. static defaultProps: DefaultProps = {
  19. event: undefined,
  20. };
  21. getCrumbs() {
  22. const crumbs: Crumb[] = [];
  23. const {eventView, event, organization, location} = this.props;
  24. const discoverTarget = organization.features.includes('discover-query')
  25. ? {
  26. pathname: getDiscoverLandingUrl(organization),
  27. query: {
  28. ...location.query,
  29. ...eventView.generateBlankQueryStringObject(),
  30. ...eventView.getGlobalSelectionQuery(),
  31. },
  32. }
  33. : null;
  34. crumbs.push({
  35. to: discoverTarget,
  36. label: t('Discover'),
  37. });
  38. if (eventView && eventView.isValid()) {
  39. crumbs.push({
  40. to: eventView.getResultsViewUrlTarget(organization.slug),
  41. label: eventView.name || '',
  42. });
  43. }
  44. if (event) {
  45. crumbs.push({
  46. label: t('Event Detail'),
  47. });
  48. }
  49. return crumbs;
  50. }
  51. render() {
  52. return <Breadcrumbs crumbs={this.getCrumbs()} />;
  53. }
  54. }
  55. export default DiscoverBreadcrumb;