grafana/public/app/features/explore/Wrapper.tsx

91 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-09-28 10:38:50 -05:00
import React, { Component } from 'react';
import { hot } from 'react-hot-loader';
import { connect } from 'react-redux';
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';
import ErrorBoundary from './ErrorBoundary';
2018-10-01 05:56:26 -05:00
import Explore from './Explore';
import { CustomScrollbar } from '@grafana/ui';
import { initializeExploreSplitAction, resetExploreAction } from './state/actionTypes';
interface WrapperProps {
initializeExploreSplitAction: typeof initializeExploreSplitAction;
split: boolean;
2019-01-11 11:26:56 -06:00
updateLocation: typeof updateLocation;
resetExploreAction: typeof resetExploreAction;
2019-01-12 16:22:28 -06:00
urlStates: { [key: string]: string };
}
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 };
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;
}
}
2019-01-12 16:22:28 -06:00
componentDidMount() {
if (this.initialSplit) {
this.props.initializeExploreSplitAction();
2019-01-12 16:22:28 -06:00
}
}
componentWillUnmount() {
this.props.resetExploreAction();
}
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;
return (
<div className="page-scrollbar-wrapper">
<CustomScrollbar autoHeightMin={'100%'} className="custom-scrollbar--page">
<div className="explore-wrapper">
<ErrorBoundary>
<Explore exploreId={ExploreId.left} urlState={leftState} />
</ErrorBoundary>
{split && (
<ErrorBoundary>
<Explore exploreId={ExploreId.right} urlState={rightState} />
</ErrorBoundary>
)}
</div>
</CustomScrollbar>
</div>
);
}
}
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
};
const mapDispatchToProps = {
initializeExploreSplitAction,
updateLocation,
resetExploreAction,
};
export default hot(module)(
connect(
mapStateToProps,
mapDispatchToProps
)(Wrapper)
);