grafana/public/app/features/explore/Wrapper.tsx
Maria Alexandra cebe67ab01
Explore: Fix Browser title not updated on Navigation to Explore (#34651)
- Update document.title on Explore page
- Add unit test and snapshot for Wrapper component
2021-05-26 18:44:16 +02:00

78 lines
2.4 KiB
TypeScript

import React, { PureComponent } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { ExploreId, ExploreQueryParams } from 'app/types/explore';
import { ErrorBoundaryAlert } from '@grafana/ui';
import { lastSavedUrl, resetExploreAction, richHistoryUpdatedAction } from './state/main';
import { getRichHistory } from '../../core/utils/richHistory';
import { ExplorePaneContainer } from './ExplorePaneContainer';
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
import { NavModel } from '@grafana/data';
import { Branding } from '../../core/components/Branding/Branding';
import { getNavModel } from '../../core/selectors/navModel';
import { StoreState } from 'app/types';
interface RouteProps extends GrafanaRouteComponentProps<{}, ExploreQueryParams> {}
interface OwnProps {}
const mapStateToProps = (state: StoreState) => {
return {
navModel: getNavModel(state.navIndex, 'explore'),
};
};
const mapDispatchToProps = {
resetExploreAction,
richHistoryUpdatedAction,
};
const connector = connect(mapStateToProps, mapDispatchToProps);
type Props = OwnProps & RouteProps & ConnectedProps<typeof connector>;
class WrapperUnconnected extends PureComponent<Props> {
updatePageDocumentTitle(navModel: NavModel) {
if (navModel) {
document.title = `${navModel.main.text} - ${Branding.AppTitle}`;
} else {
document.title = Branding.AppTitle;
}
}
componentWillUnmount() {
this.props.resetExploreAction({});
}
componentDidMount() {
lastSavedUrl.left = undefined;
lastSavedUrl.right = undefined;
const richHistory = getRichHistory();
this.props.richHistoryUpdatedAction({ richHistory });
this.updatePageDocumentTitle(this.props.navModel);
}
render() {
const { left, right } = this.props.queryParams;
const hasSplit = Boolean(left) && Boolean(right);
return (
<div className="page-scrollbar-wrapper">
<div className="explore-wrapper">
<ErrorBoundaryAlert style="page">
<ExplorePaneContainer split={hasSplit} exploreId={ExploreId.left} urlQuery={left} />
</ErrorBoundaryAlert>
{hasSplit && (
<ErrorBoundaryAlert style="page">
<ExplorePaneContainer split={hasSplit} exploreId={ExploreId.right} urlQuery={right} />
</ErrorBoundaryAlert>
)}
</div>
</div>
);
}
}
const Wrapper = connector(WrapperUnconnected);
export default Wrapper;