The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard/containers/SoloPanelPage.tsx

110 lines
2.6 KiB

// 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} />
</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));