|
@@ -5,21 +5,27 @@ import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
// Utils & Services
|
|
// Utils & Services
|
|
|
import appEvents from 'app/core/app_events';
|
|
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
|
|
|
|
|
+import { updateLocation } from 'app/core/actions';
|
|
|
|
|
+
|
|
|
// Types
|
|
// Types
|
|
|
import { StoreState } from 'app/types';
|
|
import { StoreState } 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;
|
|
panelId: string;
|
|
|
- uid?: string;
|
|
|
|
|
- slug?: string;
|
|
|
|
|
- type?: string;
|
|
|
|
|
|
|
+ urlUid?: string;
|
|
|
|
|
+ urlSlug?: string;
|
|
|
|
|
+ urlType?: string;
|
|
|
$scope: any;
|
|
$scope: any;
|
|
|
$injector: any;
|
|
$injector: any;
|
|
|
|
|
+ updateLocation: typeof updateLocation;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
interface State {
|
|
@@ -37,19 +43,34 @@ export class SoloPanelPage extends Component<Props, State> {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
- const { $injector, $scope, uid } = this.props;
|
|
|
|
|
|
|
+ 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');
|
|
const dashboardLoaderSrv = $injector.get('dashboardLoaderSrv');
|
|
|
|
|
|
|
|
// subscribe to event to know when dashboard controller is done with inititalization
|
|
// subscribe to event to know when dashboard controller is done with inititalization
|
|
|
appEvents.on('dashboard-initialized', this.onDashoardInitialized);
|
|
appEvents.on('dashboard-initialized', this.onDashoardInitialized);
|
|
|
|
|
|
|
|
- dashboardLoaderSrv.loadDashboard('', '', uid).then(result => {
|
|
|
|
|
|
|
+ dashboardLoaderSrv.loadDashboard(urlType, urlSlug, urlUid).then(result => {
|
|
|
result.meta.soloMode = true;
|
|
result.meta.soloMode = true;
|
|
|
$scope.initDashboard(result, $scope);
|
|
$scope.initDashboard(result, $scope);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ 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 = () => {
|
|
onDashoardInitialized = () => {
|
|
|
const { $scope, panelId } = this.props;
|
|
const { $scope, panelId } = this.props;
|
|
|
|
|
|
|
@@ -89,13 +110,14 @@ export class SoloPanelPage extends Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state: StoreState) => ({
|
|
const mapStateToProps = (state: StoreState) => ({
|
|
|
- uid: state.location.routeParams.uid,
|
|
|
|
|
- slug: state.location.routeParams.slug,
|
|
|
|
|
- type: state.location.routeParams.type,
|
|
|
|
|
|
|
+ urlUid: state.location.routeParams.uid,
|
|
|
|
|
+ urlSlug: state.location.routeParams.slug,
|
|
|
|
|
+ urlType: state.location.routeParams.type,
|
|
|
panelId: state.location.query.panelId
|
|
panelId: state.location.query.panelId
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
const mapDispatchToProps = {
|
|
|
|
|
+ updateLocation
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(SoloPanelPage));
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(SoloPanelPage));
|