mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat: Only use the DataPanel component when panel plugin has isDataPanel set to true in plugin.json. And fix PanelData when using snapshots
This commit is contained in:
parent
3f64d61fd2
commit
d3115325a9
@ -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> {
|
|||||||
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> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
renderHelper = (width: number, height: number): JSX.Element => {
|
||||||
const { panel, dashboard } = this.props;
|
const { panel, plugin } = this.props;
|
||||||
const { refreshCounter, timeRange, timeInfo } = this.state;
|
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() {
|
||||||
|
const { dashboard, panel } = this.props;
|
||||||
|
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> {
|
|||||||
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>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user