mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Separate SoloPanel rendering logic (#41408)
This commit is contained in:
@@ -4,7 +4,7 @@ import AutoSizer from 'react-virtualized-auto-sizer';
|
|||||||
import { DashboardPanel } from '../dashgrid/DashboardPanel';
|
import { DashboardPanel } from '../dashgrid/DashboardPanel';
|
||||||
import { initDashboard } from '../state/initDashboard';
|
import { initDashboard } from '../state/initDashboard';
|
||||||
import { StoreState } from 'app/types';
|
import { StoreState } from 'app/types';
|
||||||
import { PanelModel } from 'app/features/dashboard/state';
|
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||||
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
||||||
|
|
||||||
export interface DashboardPageRouteParams {
|
export interface DashboardPageRouteParams {
|
||||||
@@ -74,41 +74,54 @@ export class SoloPanelPage extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { dashboard } = this.props;
|
|
||||||
const { notFound, panel } = this.state;
|
|
||||||
|
|
||||||
if (notFound) {
|
|
||||||
return <div className="alert alert-error">Panel with id {this.getPanelId()} not found</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!panel || !dashboard) {
|
|
||||||
return <div>Loading & initializing dashboard</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="panel-solo">
|
<SoloPanel
|
||||||
<AutoSizer>
|
dashboard={this.props.dashboard}
|
||||||
{({ width, height }) => {
|
notFound={this.state.notFound}
|
||||||
if (width === 0) {
|
panel={this.state.panel}
|
||||||
return null;
|
panelId={this.getPanelId()}
|
||||||
}
|
/>
|
||||||
return (
|
|
||||||
<DashboardPanel
|
|
||||||
stateKey={panel.key}
|
|
||||||
width={width}
|
|
||||||
height={height}
|
|
||||||
dashboard={dashboard}
|
|
||||||
panel={panel}
|
|
||||||
isEditing={false}
|
|
||||||
isViewing={false}
|
|
||||||
isInView={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</AutoSizer>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SoloPanelProps extends State {
|
||||||
|
dashboard: DashboardModel | null;
|
||||||
|
panelId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SoloPanel = ({ dashboard, notFound, panel, panelId }: SoloPanelProps) => {
|
||||||
|
if (notFound) {
|
||||||
|
return <div className="alert alert-error">Panel with id {panelId} not found</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!panel || !dashboard) {
|
||||||
|
return <div>Loading & initializing dashboard</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="panel-solo">
|
||||||
|
<AutoSizer>
|
||||||
|
{({ width, height }) => {
|
||||||
|
if (width === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<DashboardPanel
|
||||||
|
stateKey={panel.key}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
dashboard={dashboard}
|
||||||
|
panel={panel}
|
||||||
|
isEditing={false}
|
||||||
|
isViewing={false}
|
||||||
|
isInView={true}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</AutoSizer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default connector(SoloPanelPage);
|
export default connector(SoloPanelPage);
|
||||||
|
|||||||
Reference in New Issue
Block a user