|
|
@@ -1,14 +1,19 @@
|
|
|
// Libraries
|
|
|
-import React, { Component } from 'react';
|
|
|
+import $ from 'jquery';
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
import { connect } from 'react-redux';
|
|
|
+import classNames from 'classnames';
|
|
|
|
|
|
// Components
|
|
|
import { LoadingPlaceholder } from '@grafana/ui';
|
|
|
import { DashboardGrid } from '../dashgrid/DashboardGrid';
|
|
|
+import { DashNav } from '../components/DashNav';
|
|
|
+import { DashboardSettings } from '../components/DashboardSettings';
|
|
|
|
|
|
// Redux
|
|
|
import { initDashboard } from '../state/initDashboard';
|
|
|
+import { setDashboardModel } from '../state/actions';
|
|
|
|
|
|
// Types
|
|
|
import { StoreState } from 'app/types';
|
|
|
@@ -20,22 +25,23 @@ interface Props {
|
|
|
urlUid?: string;
|
|
|
urlSlug?: string;
|
|
|
urlType?: string;
|
|
|
+ editview: string;
|
|
|
$scope: any;
|
|
|
$injector: any;
|
|
|
initDashboard: typeof initDashboard;
|
|
|
+ setDashboardModel: typeof setDashboardModel;
|
|
|
loadingState: DashboardLoadingState;
|
|
|
dashboard: DashboardModel;
|
|
|
}
|
|
|
|
|
|
interface State {
|
|
|
- dashboard: DashboardModel | null;
|
|
|
- notFound: boolean;
|
|
|
+ isSettingsOpening: boolean;
|
|
|
}
|
|
|
|
|
|
-export class DashboardPage extends Component<Props, State> {
|
|
|
+export class DashboardPage extends PureComponent<Props, State> {
|
|
|
state: State = {
|
|
|
- dashboard: null,
|
|
|
- notFound: false,
|
|
|
+ isSettingsOpening: false,
|
|
|
+ isSettingsOpen: false,
|
|
|
};
|
|
|
|
|
|
async componentDidMount() {
|
|
|
@@ -45,18 +51,82 @@ export class DashboardPage extends Component<Props, State> {
|
|
|
urlSlug: this.props.urlSlug,
|
|
|
urlUid: this.props.urlUid,
|
|
|
urlType: this.props.urlType,
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- render() {
|
|
|
- const { loadingState, dashboard } = this.props;
|
|
|
+ componentDidUpdate(prevProps: Props) {
|
|
|
+ const { dashboard, editview } = this.props;
|
|
|
+
|
|
|
+ // when dashboard has loaded subscribe to somme events
|
|
|
+ if (prevProps.dashboard === null && dashboard) {
|
|
|
+ dashboard.events.on('view-mode-changed', this.onViewModeChanged);
|
|
|
+
|
|
|
+ // set initial fullscreen class state
|
|
|
+ this.setPanelFullscreenClass();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!prevProps.editview && editview) {
|
|
|
+ this.setState({ isSettingsOpening: true });
|
|
|
+ setTimeout(() => {
|
|
|
+ this.setState({ isSettingsOpening: false});
|
|
|
+ }, 10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ onViewModeChanged = () => {
|
|
|
+ this.setPanelFullscreenClass();
|
|
|
+ };
|
|
|
+
|
|
|
+ setPanelFullscreenClass() {
|
|
|
+ $('body').toggleClass('panel-in-fullscreen', this.props.dashboard.meta.fullscreen === true);
|
|
|
+ }
|
|
|
|
|
|
- if (!dashboard) {
|
|
|
- return <LoadingPlaceholder text={loadingState.toString()} />;
|
|
|
+ componentWillUnmount() {
|
|
|
+ if (this.props.dashboard) {
|
|
|
+ this.props.dashboard.destroy();
|
|
|
+ this.props.setDashboardModel(null);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ renderLoadingState() {
|
|
|
+ return <LoadingPlaceholder text="Loading" />;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderDashboard() {
|
|
|
+ const { dashboard, editview } = this.props;
|
|
|
+
|
|
|
+ const classes = classNames({
|
|
|
+ 'dashboard-container': true,
|
|
|
+ 'dashboard-container--has-submenu': dashboard.meta.submenuEnabled
|
|
|
+ });
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className="scroll-canvas scroll-canvas--dashboard">
|
|
|
+ {dashboard && editview && <DashboardSettings dashboard={dashboard} />}
|
|
|
+
|
|
|
+ <div className={classes}>
|
|
|
+ <DashboardGrid dashboard={dashboard} />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { dashboard, editview } = this.props;
|
|
|
+ const { isSettingsOpening } = this.state;
|
|
|
+
|
|
|
+ const classes = classNames({
|
|
|
+ 'dashboard-page--settings-opening': isSettingsOpening,
|
|
|
+ 'dashboard-page--settings-open': !isSettingsOpening && editview,
|
|
|
+ });
|
|
|
|
|
|
- console.log(dashboard);
|
|
|
- return <DashboardGrid dashboard={dashboard} />
|
|
|
+ return (
|
|
|
+ <div className={classes}>
|
|
|
+ <DashNav dashboard={dashboard} />
|
|
|
+ {!dashboard && this.renderLoadingState()}
|
|
|
+ {dashboard && this.renderDashboard()}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -65,12 +135,14 @@ const mapStateToProps = (state: StoreState) => ({
|
|
|
urlSlug: state.location.routeParams.slug,
|
|
|
urlType: state.location.routeParams.type,
|
|
|
panelId: state.location.query.panelId,
|
|
|
+ editview: state.location.query.editview,
|
|
|
loadingState: state.dashboard.loadingState,
|
|
|
dashboard: state.dashboard.model as DashboardModel,
|
|
|
});
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
- initDashboard
|
|
|
+ initDashboard,
|
|
|
+ setDashboardModel
|
|
|
};
|
|
|
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(DashboardPage));
|