Commit d3115325 by Johannes Schill

feat: Only use the DataPanel component when panel plugin has isDataPanel set to…

feat: Only use the DataPanel component when panel plugin has isDataPanel set to true in plugin.json. And fix PanelData when using snapshots
parent 3f64d61f
...@@ -10,14 +10,14 @@ import { PanelHeader } from './PanelHeader/PanelHeader'; ...@@ -10,14 +10,14 @@ import { PanelHeader } from './PanelHeader/PanelHeader';
import { DataPanel } from './DataPanel'; import { DataPanel } from './DataPanel';
// Utils // Utils
import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel'; import { applyPanelTimeOverrides, snapshotDataToPanelData } from 'app/features/dashboard/utils/panel';
import { PANEL_HEADER_HEIGHT } from 'app/core/constants'; import { PANEL_HEADER_HEIGHT } from 'app/core/constants';
import { profiler } from 'app/core/profiler'; import { profiler } from 'app/core/profiler';
// Types // Types
import { DashboardModel, PanelModel } from '../state'; import { DashboardModel, PanelModel } from '../state';
import { PanelPlugin } from 'app/types'; import { PanelPlugin } from 'app/types';
import { TimeRange, LoadingState } from '@grafana/ui'; import { TimeRange, LoadingState, PanelData } from '@grafana/ui';
import variables from 'sass/_variables.scss'; import variables from 'sass/_variables.scss';
import templateSrv from 'app/features/templating/template_srv'; import templateSrv from 'app/features/templating/template_srv';
...@@ -94,7 +94,7 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -94,7 +94,7 @@ export class PanelChrome extends PureComponent<Props, State> {
return !this.props.dashboard.otherPanelInFullscreen(this.props.panel); return !this.props.dashboard.otherPanelInFullscreen(this.props.panel);
} }
renderPanel(loading, panelData, width, height): JSX.Element { renderPanelPlugin(loading: LoadingState, panelData: PanelData, width: number, height: number): JSX.Element {
const { panel, plugin } = this.props; const { panel, plugin } = this.props;
const { timeRange, renderCounter } = this.state; const { timeRange, renderCounter } = this.state;
const PanelComponent = plugin.exports.Panel; const PanelComponent = plugin.exports.Panel;
...@@ -121,11 +121,46 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -121,11 +121,46 @@ export class PanelChrome extends PureComponent<Props, State> {
); );
} }
renderHelper = (width: number, height: number): JSX.Element => {
const { panel, plugin } = this.props;
const { refreshCounter, timeRange } = this.state;
const { datasource, targets } = panel;
return (
<>
{panel.snapshotData && panel.snapshotData.length > 0 ? (
this.renderPanelPlugin(LoadingState.Done, snapshotDataToPanelData(panel), width, height)
) : (
<>
{plugin.isDataPanel === true ?
<DataPanel
panelId={panel.id}
datasource={datasource}
queries={targets}
timeRange={timeRange}
isVisible={this.isVisible}
widthPixels={width}
refreshCounter={refreshCounter}
onDataResponse={this.onDataResponse}
>
{({ loading, panelData }) => {
return this.renderPanelPlugin(loading, panelData, width, height);
}}
</DataPanel>
: (
this.renderPanelPlugin(LoadingState.Done, null, width, height)
)}
</>
)}
</>
);
}
render() { render() {
const { panel, dashboard } = this.props; const { dashboard, panel } = this.props;
const { refreshCounter, timeRange, timeInfo } = this.state; const { timeInfo } = this.state;
const { transparent } = panel;
const { datasource, targets, transparent } = panel;
const containerClassNames = `panel-container panel-container--absolute ${transparent ? 'panel-transparent' : ''}`; const containerClassNames = `panel-container panel-container--absolute ${transparent ? 'panel-transparent' : ''}`;
return ( return (
<AutoSizer> <AutoSizer>
...@@ -145,24 +180,7 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -145,24 +180,7 @@ export class PanelChrome extends PureComponent<Props, State> {
scopedVars={panel.scopedVars} scopedVars={panel.scopedVars}
links={panel.links} links={panel.links}
/> />
{panel.snapshotData ? ( {this.renderHelper(width, height)}
this.renderPanel(false, panel.snapshotData, width, height)
) : (
<DataPanel
panelId={panel.id}
datasource={datasource}
queries={targets}
timeRange={timeRange}
isVisible={this.isVisible}
widthPixels={width}
refreshCounter={refreshCounter}
onDataResponse={this.onDataResponse}
>
{({ loading, panelData }) => {
return this.renderPanel(loading, panelData, width, height);
}}
</DataPanel>
)}
</div> </div>
); );
}} }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment