2018-09-28 10:38:50 -05:00
|
|
|
import React, { Component } from 'react';
|
2018-09-28 09:44:07 -05:00
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
|
import { connect } from 'react-redux';
|
2018-05-15 10:07:38 -05:00
|
|
|
|
2018-09-28 09:44:07 -05:00
|
|
|
import { updateLocation } from 'app/core/actions';
|
|
|
|
import { StoreState } from 'app/types';
|
2019-01-12 16:22:28 -06:00
|
|
|
import { ExploreId, ExploreUrlState } from 'app/types/explore';
|
|
|
|
import { parseUrlState } from 'app/core/utils/explore';
|
2018-05-15 10:07:38 -05:00
|
|
|
|
2018-10-26 11:16:00 -05:00
|
|
|
import ErrorBoundary from './ErrorBoundary';
|
2018-10-01 05:56:26 -05:00
|
|
|
import Explore from './Explore';
|
2019-01-23 05:00:24 -06:00
|
|
|
import { CustomScrollbar } from '@grafana/ui';
|
2019-02-04 00:47:10 -06:00
|
|
|
import { initializeExploreSplitAction, resetExploreAction } from './state/actionTypes';
|
2018-09-28 09:44:07 -05:00
|
|
|
|
|
|
|
interface WrapperProps {
|
2019-02-04 00:47:10 -06:00
|
|
|
initializeExploreSplitAction: typeof initializeExploreSplitAction;
|
2018-09-28 09:44:07 -05:00
|
|
|
split: boolean;
|
2019-01-11 11:26:56 -06:00
|
|
|
updateLocation: typeof updateLocation;
|
2019-02-04 00:47:10 -06:00
|
|
|
resetExploreAction: typeof resetExploreAction;
|
2019-01-12 16:22:28 -06:00
|
|
|
urlStates: { [key: string]: string };
|
2018-09-28 09:44:07 -05:00
|
|
|
}
|
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
export class Wrapper extends Component<WrapperProps> {
|
2019-01-12 16:22:28 -06:00
|
|
|
initialSplit: boolean;
|
|
|
|
urlStates: { [key: string]: ExploreUrlState };
|
2018-09-28 09:44:07 -05:00
|
|
|
|
|
|
|
constructor(props: WrapperProps) {
|
|
|
|
super(props);
|
2019-01-12 16:22:28 -06:00
|
|
|
this.urlStates = {};
|
|
|
|
const { left, right } = props.urlStates;
|
|
|
|
if (props.urlStates.left) {
|
|
|
|
this.urlStates.leftState = parseUrlState(left);
|
|
|
|
}
|
|
|
|
if (props.urlStates.right) {
|
|
|
|
this.urlStates.rightState = parseUrlState(right);
|
|
|
|
this.initialSplit = true;
|
|
|
|
}
|
2018-09-28 09:44:07 -05:00
|
|
|
}
|
|
|
|
|
2019-01-12 16:22:28 -06:00
|
|
|
componentDidMount() {
|
|
|
|
if (this.initialSplit) {
|
2019-02-04 00:47:10 -06:00
|
|
|
this.props.initializeExploreSplitAction();
|
2019-01-12 16:22:28 -06:00
|
|
|
}
|
|
|
|
}
|
2018-05-15 10:07:38 -05:00
|
|
|
|
2019-01-28 06:27:56 -06:00
|
|
|
componentWillUnmount() {
|
2019-02-04 00:47:10 -06:00
|
|
|
this.props.resetExploreAction();
|
2019-01-28 06:27:56 -06:00
|
|
|
}
|
|
|
|
|
2018-05-15 10:07:38 -05:00
|
|
|
render() {
|
2019-01-11 11:26:56 -06:00
|
|
|
const { split } = this.props;
|
2019-01-12 16:22:28 -06:00
|
|
|
const { leftState, rightState } = this.urlStates;
|
2018-10-26 11:16:00 -05:00
|
|
|
|
2018-05-15 10:07:38 -05:00
|
|
|
return (
|
2019-01-23 05:00:24 -06:00
|
|
|
<div className="page-scrollbar-wrapper">
|
2019-02-21 02:41:53 -06:00
|
|
|
<CustomScrollbar autoHeightMin={'100%'} className="custom-scrollbar--page">
|
2019-01-23 05:00:24 -06:00
|
|
|
<div className="explore-wrapper">
|
|
|
|
<ErrorBoundary>
|
|
|
|
<Explore exploreId={ExploreId.left} urlState={leftState} />
|
|
|
|
</ErrorBoundary>
|
|
|
|
{split && (
|
|
|
|
<ErrorBoundary>
|
|
|
|
<Explore exploreId={ExploreId.right} urlState={rightState} />
|
|
|
|
</ErrorBoundary>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</CustomScrollbar>
|
2018-05-15 10:07:38 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 09:44:07 -05:00
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
const mapStateToProps = (state: StoreState) => {
|
2019-01-12 16:22:28 -06:00
|
|
|
const urlStates = state.location.query;
|
2019-01-11 11:26:56 -06:00
|
|
|
const { split } = state.explore;
|
2019-01-12 16:22:28 -06:00
|
|
|
return { split, urlStates };
|
2019-01-11 11:26:56 -06:00
|
|
|
};
|
2018-09-28 09:44:07 -05:00
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2019-02-04 00:47:10 -06:00
|
|
|
initializeExploreSplitAction,
|
2018-09-28 09:44:07 -05:00
|
|
|
updateLocation,
|
2019-02-04 00:47:10 -06:00
|
|
|
resetExploreAction,
|
2018-09-28 09:44:07 -05:00
|
|
|
};
|
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
export default hot(module)(
|
|
|
|
connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Wrapper)
|
|
|
|
);
|