|
@@ -3,98 +3,78 @@ import React, { Component } from 'react';
|
|
|
import { hot } from 'react-hot-loader';
|
|
import { hot } from 'react-hot-loader';
|
|
|
import { connect } from 'react-redux';
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
-// Utils & Services
|
|
|
|
|
-import appEvents from 'app/core/app_events';
|
|
|
|
|
-import locationUtil from 'app/core/utils/location_util';
|
|
|
|
|
-import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
|
-
|
|
|
|
|
// Components
|
|
// Components
|
|
|
import { DashboardPanel } from '../dashgrid/DashboardPanel';
|
|
import { DashboardPanel } from '../dashgrid/DashboardPanel';
|
|
|
|
|
|
|
|
// Redux
|
|
// Redux
|
|
|
-import { updateLocation } from 'app/core/actions';
|
|
|
|
|
|
|
+import { initDashboard } from '../state/initDashboard';
|
|
|
|
|
|
|
|
// Types
|
|
// Types
|
|
|
-import { StoreState } from 'app/types';
|
|
|
|
|
|
|
+import { StoreState, DashboardRouteInfo } from 'app/types';
|
|
|
import { PanelModel, DashboardModel } from 'app/features/dashboard/state';
|
|
import { PanelModel, DashboardModel } from 'app/features/dashboard/state';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
- panelId: string;
|
|
|
|
|
|
|
+ urlPanelId: string;
|
|
|
urlUid?: string;
|
|
urlUid?: string;
|
|
|
urlSlug?: string;
|
|
urlSlug?: string;
|
|
|
urlType?: string;
|
|
urlType?: string;
|
|
|
$scope: any;
|
|
$scope: any;
|
|
|
$injector: any;
|
|
$injector: any;
|
|
|
- updateLocation: typeof updateLocation;
|
|
|
|
|
|
|
+ routeInfo: DashboardRouteInfo;
|
|
|
|
|
+ initDashboard: typeof initDashboard;
|
|
|
|
|
+ dashboard: DashboardModel | null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
interface State {
|
|
|
panel: PanelModel | null;
|
|
panel: PanelModel | null;
|
|
|
- dashboard: DashboardModel | null;
|
|
|
|
|
notFound: boolean;
|
|
notFound: boolean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export class SoloPanelPage extends Component<Props, State> {
|
|
export class SoloPanelPage extends Component<Props, State> {
|
|
|
-
|
|
|
|
|
state: State = {
|
|
state: State = {
|
|
|
panel: null,
|
|
panel: null,
|
|
|
- dashboard: null,
|
|
|
|
|
notFound: false,
|
|
notFound: false,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
- const { $injector, $scope, urlUid, urlType, urlSlug } = this.props;
|
|
|
|
|
-
|
|
|
|
|
- // handle old urls with no uid
|
|
|
|
|
- if (!urlUid && !(urlType === 'script' || urlType === 'snapshot')) {
|
|
|
|
|
- this.redirectToNewUrl();
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const dashboardLoaderSrv = $injector.get('dashboardLoaderSrv');
|
|
|
|
|
-
|
|
|
|
|
- // subscribe to event to know when dashboard controller is done with inititalization
|
|
|
|
|
- appEvents.on('dashboard-initialized', this.onDashoardInitialized);
|
|
|
|
|
-
|
|
|
|
|
- dashboardLoaderSrv.loadDashboard(urlType, urlSlug, urlUid).then(result => {
|
|
|
|
|
- result.meta.soloMode = true;
|
|
|
|
|
- $scope.initDashboard(result, $scope);
|
|
|
|
|
|
|
+ const { $injector, $scope, urlUid, urlType, urlSlug, routeInfo } = this.props;
|
|
|
|
|
+
|
|
|
|
|
+ this.props.initDashboard({
|
|
|
|
|
+ $injector: $injector,
|
|
|
|
|
+ $scope: $scope,
|
|
|
|
|
+ urlSlug: urlSlug,
|
|
|
|
|
+ urlUid: urlUid,
|
|
|
|
|
+ urlType: urlType,
|
|
|
|
|
+ routeInfo: routeInfo,
|
|
|
|
|
+ fixUrl: false,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- redirectToNewUrl() {
|
|
|
|
|
- getBackendSrv().getDashboardBySlug(this.props.urlSlug).then(res => {
|
|
|
|
|
- if (res) {
|
|
|
|
|
- const url = locationUtil.stripBaseFromUrl(res.meta.url.replace('/d/', '/d-solo/'));
|
|
|
|
|
- this.props.updateLocation(url);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- onDashoardInitialized = () => {
|
|
|
|
|
- const { $scope, panelId } = this.props;
|
|
|
|
|
|
|
+ componentDidUpdate(prevProps: Props) {
|
|
|
|
|
+ const { urlPanelId, dashboard } = this.props;
|
|
|
|
|
|
|
|
- const dashboard: DashboardModel = $scope.dashboard;
|
|
|
|
|
- const panel = dashboard.getPanelById(parseInt(panelId, 10));
|
|
|
|
|
-
|
|
|
|
|
- if (!panel) {
|
|
|
|
|
- this.setState({ notFound: true });
|
|
|
|
|
|
|
+ if (!dashboard) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.setState({ dashboard, panel });
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // we just got the dashboard!
|
|
|
|
|
+ if (!prevProps.dashboard) {
|
|
|
|
|
+ const panel = dashboard.getPanelById(parseInt(urlPanelId, 10));
|
|
|
|
|
+ if (!panel) {
|
|
|
|
|
+ this.setState({ notFound: true });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.setState({ panel });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { panelId } = this.props;
|
|
|
|
|
- const { notFound, panel, dashboard } = this.state;
|
|
|
|
|
|
|
+ const { urlPanelId, dashboard } = this.props;
|
|
|
|
|
+ const { notFound, panel } = this.state;
|
|
|
|
|
|
|
|
if (notFound) {
|
|
if (notFound) {
|
|
|
- return (
|
|
|
|
|
- <div className="alert alert-error">
|
|
|
|
|
- Panel with id { panelId } not found
|
|
|
|
|
- </div>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ return <div className="alert alert-error">Panel with id {urlPanelId} not found</div>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!panel) {
|
|
if (!panel) {
|
|
@@ -113,11 +93,13 @@ const mapStateToProps = (state: StoreState) => ({
|
|
|
urlUid: state.location.routeParams.uid,
|
|
urlUid: state.location.routeParams.uid,
|
|
|
urlSlug: state.location.routeParams.slug,
|
|
urlSlug: state.location.routeParams.slug,
|
|
|
urlType: state.location.routeParams.type,
|
|
urlType: state.location.routeParams.type,
|
|
|
- panelId: state.location.query.panelId
|
|
|
|
|
|
|
+ urlPanelId: state.location.query.panelId,
|
|
|
|
|
+ loadingState: state.dashboard.loadingState,
|
|
|
|
|
+ dashboard: state.dashboard.model as DashboardModel,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
const mapDispatchToProps = {
|
|
|
- updateLocation
|
|
|
|
|
|
|
+ initDashboard,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(SoloPanelPage));
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(SoloPanelPage));
|