Separate SoloPanel rendering logic (#41408)

This commit is contained in:
Alex Khomenko 2021-11-09 09:47:01 +02:00 committed by GitHub
parent 27f66a6df9
commit 112e44181e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ import AutoSizer from 'react-virtualized-auto-sizer';
import { DashboardPanel } from '../dashgrid/DashboardPanel';
import { initDashboard } from '../state/initDashboard';
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';
export interface DashboardPageRouteParams {
@ -74,41 +74,54 @@ export class SoloPanelPage extends Component<Props, State> {
}
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 (
<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>
<SoloPanel
dashboard={this.props.dashboard}
notFound={this.state.notFound}
panel={this.state.panel}
panelId={this.getPanelId()}
/>
);
}
}
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);