|
|
|
@ -3,98 +3,78 @@ import React, { Component } from 'react'; |
|
|
|
|
import { hot } from 'react-hot-loader'; |
|
|
|
|
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
|
|
|
|
|
import { DashboardPanel } from '../dashgrid/DashboardPanel'; |
|
|
|
|
|
|
|
|
|
// Redux
|
|
|
|
|
import { updateLocation } from 'app/core/actions'; |
|
|
|
|
import { initDashboard } from '../state/initDashboard'; |
|
|
|
|
|
|
|
|
|
// Types
|
|
|
|
|
import { StoreState } from 'app/types'; |
|
|
|
|
import { StoreState, DashboardRouteInfo } from 'app/types'; |
|
|
|
|
import { PanelModel, DashboardModel } from 'app/features/dashboard/state'; |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
panelId: string; |
|
|
|
|
urlPanelId: string; |
|
|
|
|
urlUid?: string; |
|
|
|
|
urlSlug?: string; |
|
|
|
|
urlType?: string; |
|
|
|
|
$scope: any; |
|
|
|
|
$injector: any; |
|
|
|
|
updateLocation: typeof updateLocation; |
|
|
|
|
routeInfo: DashboardRouteInfo; |
|
|
|
|
initDashboard: typeof initDashboard; |
|
|
|
|
dashboard: DashboardModel | null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface State { |
|
|
|
|
panel: PanelModel | null; |
|
|
|
|
dashboard: DashboardModel | null; |
|
|
|
|
notFound: boolean; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class SoloPanelPage extends Component<Props, State> { |
|
|
|
|
|
|
|
|
|
state: State = { |
|
|
|
|
panel: null, |
|
|
|
|
dashboard: null, |
|
|
|
|
notFound: false, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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() { |
|
|
|
|
const { panelId } = this.props; |
|
|
|
|
const { notFound, panel, dashboard } = this.state; |
|
|
|
|
const { urlPanelId, dashboard } = this.props; |
|
|
|
|
const { notFound, panel } = this.state; |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
@ -113,11 +93,13 @@ const mapStateToProps = (state: StoreState) => ({ |
|
|
|
|
urlUid: state.location.routeParams.uid, |
|
|
|
|
urlSlug: state.location.routeParams.slug, |
|
|
|
|
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 = { |
|
|
|
|
updateLocation |
|
|
|
|
initDashboard, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(SoloPanelPage)); |
|
|
|
|