Wrapper.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { Component } from 'react';
  2. import { hot } from 'react-hot-loader';
  3. import { connect } from 'react-redux';
  4. import { updateLocation } from 'app/core/actions';
  5. import { StoreState } from 'app/types';
  6. import { ExploreId, ExploreUrlState } from 'app/types/explore';
  7. import { parseUrlState } from 'app/core/utils/explore';
  8. import { initializeExploreSplit } from './state/actions';
  9. import ErrorBoundary from './ErrorBoundary';
  10. import Explore from './Explore';
  11. import { CustomScrollbar } from '@grafana/ui';
  12. interface WrapperProps {
  13. initializeExploreSplit: typeof initializeExploreSplit;
  14. split: boolean;
  15. updateLocation: typeof updateLocation;
  16. urlStates: { [key: string]: string };
  17. }
  18. export class Wrapper extends Component<WrapperProps> {
  19. initialSplit: boolean;
  20. urlStates: { [key: string]: ExploreUrlState };
  21. constructor(props: WrapperProps) {
  22. super(props);
  23. this.urlStates = {};
  24. const { left, right } = props.urlStates;
  25. if (props.urlStates.left) {
  26. this.urlStates.leftState = parseUrlState(left);
  27. }
  28. if (props.urlStates.right) {
  29. this.urlStates.rightState = parseUrlState(right);
  30. this.initialSplit = true;
  31. }
  32. }
  33. componentDidMount() {
  34. if (this.initialSplit) {
  35. this.props.initializeExploreSplit();
  36. }
  37. }
  38. render() {
  39. const { split } = this.props;
  40. const { leftState, rightState } = this.urlStates;
  41. return (
  42. <div className="page-scrollbar-wrapper">
  43. <CustomScrollbar autoHeightMin={'100%'}>
  44. <div className="explore-wrapper">
  45. <ErrorBoundary>
  46. <Explore exploreId={ExploreId.left} urlState={leftState} />
  47. </ErrorBoundary>
  48. {split && (
  49. <ErrorBoundary>
  50. <Explore exploreId={ExploreId.right} urlState={rightState} />
  51. </ErrorBoundary>
  52. )}
  53. </div>
  54. </CustomScrollbar>
  55. </div>
  56. );
  57. }
  58. }
  59. const mapStateToProps = (state: StoreState) => {
  60. const urlStates = state.location.query;
  61. const { split } = state.explore;
  62. return { split, urlStates };
  63. };
  64. const mapDispatchToProps = {
  65. initializeExploreSplit,
  66. updateLocation,
  67. };
  68. export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(Wrapper));