PanelChrome: Ignore data updates & errors for non data panels (#33477)

This commit is contained in:
Torkel Ödegaard
2021-04-28 14:46:10 +02:00
committed by GitHub
parent 7e6db1ee7e
commit 7087727400

View File

@ -63,11 +63,15 @@ export class PanelChrome extends Component<Props, State> {
renderCounter: 0, renderCounter: 0,
refreshWhenInView: false, refreshWhenInView: false,
eventBus: new EventBusWithSource(props.dashboard.events, `panel-${props.panel.id}`), eventBus: new EventBusWithSource(props.dashboard.events, `panel-${props.panel.id}`),
data: { data: this.getInitialPanelDataState(),
state: LoadingState.NotStarted, };
series: [], }
timeRange: getDefaultTimeRange(),
}, getInitialPanelDataState(): PanelData {
return {
state: LoadingState.NotStarted,
series: [],
timeRange: getDefaultTimeRange(),
}; };
} }
@ -138,13 +142,20 @@ export class PanelChrome extends Component<Props, State> {
// The next is outside a react synthetic event so setState is not batched // The next is outside a react synthetic event so setState is not batched
// So in this context we can only do a single call to setState // So in this context we can only do a single call to setState
onDataUpdate(data: PanelData) { onDataUpdate(data: PanelData) {
if (!this.props.isInView) { const { isInView, dashboard, panel, plugin } = this.props;
if (!isInView) {
if (data.state !== LoadingState.Streaming) { if (data.state !== LoadingState.Streaming) {
// Ignore events when not visible. // Ignore events when not visible.
// The call will be repeated when the panel comes into view // The call will be repeated when the panel comes into view
this.setState({ refreshWhenInView: true }); this.setState({ refreshWhenInView: true });
} }
return;
}
// Ignore this data update if we are now a non data panel
if (plugin.meta.skipDataQuery) {
this.setState({ data: this.getInitialPanelDataState() });
return; return;
} }
@ -169,8 +180,8 @@ export class PanelChrome extends Component<Props, State> {
break; break;
case LoadingState.Done: case LoadingState.Done:
// If we are doing a snapshot save data in panel model // If we are doing a snapshot save data in panel model
if (this.props.dashboard.snapshot) { if (dashboard.snapshot) {
this.props.panel.snapshotData = data.series.map((frame) => toDataFrameDTO(frame)); panel.snapshotData = data.series.map((frame) => toDataFrameDTO(frame));
} }
if (isFirstLoad) { if (isFirstLoad) {
isFirstLoad = false; isFirstLoad = false;