| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- // Libraries
- import React, { Component } from 'react';
- import { hot } from 'react-hot-loader';
- import { connect } from 'react-redux';
- // Components
- import { DashboardPanel } from '../dashgrid/DashboardPanel';
- // Redux
- import { initDashboard } from '../state/initDashboard';
- // Types
- import { StoreState, DashboardRouteInfo } from 'app/types';
- import { PanelModel, DashboardModel } from 'app/features/dashboard/state';
- interface Props {
- urlPanelId: string;
- urlUid?: string;
- urlSlug?: string;
- urlType?: string;
- $scope: any;
- $injector: any;
- routeInfo: DashboardRouteInfo;
- initDashboard: typeof initDashboard;
- dashboard: DashboardModel | null;
- }
- interface State {
- panel: PanelModel | null;
- notFound: boolean;
- }
- export class SoloPanelPage extends Component<Props, State> {
- state: State = {
- panel: null,
- notFound: false,
- };
- componentDidMount() {
- 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,
- });
- }
- componentDidUpdate(prevProps: Props) {
- const { urlPanelId, dashboard } = this.props;
- if (!dashboard) {
- return;
- }
- // we just got the dashboard!
- if (!prevProps.dashboard) {
- const panelId = parseInt(urlPanelId, 10);
- // need to expand parent row if this panel is inside a row
- dashboard.expandParentRowFor(panelId);
- const panel = dashboard.getPanelById(panelId);
- if (!panel) {
- this.setState({ notFound: true });
- return;
- }
- this.setState({ panel });
- }
- }
- render() {
- const { urlPanelId, dashboard } = this.props;
- const { notFound, panel } = this.state;
- if (notFound) {
- return <div className="alert alert-error">Panel with id {urlPanelId} not found</div>;
- }
- if (!panel) {
- return <div>Loading & initializing dashboard</div>;
- }
- return (
- <div className="panel-solo">
- <DashboardPanel dashboard={dashboard} panel={panel} isEditing={false} isFullscreen={false} isInView={true} />
- </div>
- );
- }
- }
- const mapStateToProps = (state: StoreState) => ({
- urlUid: state.location.routeParams.uid,
- urlSlug: state.location.routeParams.slug,
- urlType: state.location.routeParams.type,
- urlPanelId: state.location.query.panelId,
- dashboard: state.dashboard.model as DashboardModel,
- });
- const mapDispatchToProps = {
- initDashboard,
- };
- export default hot(module)(
- connect(
- mapStateToProps,
- mapDispatchToProps
- )(SoloPanelPage)
- );
|