Dashboards: Run shared queries even when source panel is in collapsed row (#77792)

This commit is contained in:
kay delaney 2023-12-12 12:05:05 +00:00 committed by GitHub
parent 3783d87576
commit 6989db1ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -516,12 +516,22 @@ export class DashboardModel implements TimeModel {
}
}
getPanelById(id: number): PanelModel | null {
getPanelById(id: number, includeCollapsed = false): PanelModel | null {
if (this.panelInEdit && this.panelInEdit.id === id) {
return this.panelInEdit;
}
return this.panels.find((p) => p.id === id) ?? null;
if (includeCollapsed) {
for (const panel of this.panelIterator()) {
if (panel.id === id) {
return panel;
}
}
return null;
} else {
return this.panels.find((p) => p.id === id) ?? null;
}
}
canEditPanel(panel?: PanelModel | null): boolean | undefined | null {

View File

@ -11,6 +11,7 @@ import {
DataTopic,
} from '@grafana/data';
import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
import { PanelModel } from 'app/features/dashboard/state';
import { QueryRunnerOptions } from 'app/features/query/state/PanelQueryRunner';
import { DashboardQuery, SHARED_DASHBOARD_QUERY } from './types';
@ -42,7 +43,12 @@ export function runSharedRequest(options: QueryRunnerOptions, query: DashboardQu
return undefined;
}
const listenToPanel = dashboard?.getPanelById(listenToPanelId);
// Source panel might be contained in a collapsed row, in which
// case we need to create a PanelModel
let listenToPanel = dashboard?.getPanelById(listenToPanelId, true);
if (!(listenToPanel instanceof PanelModel)) {
listenToPanel = new PanelModel(listenToPanel);
}
if (!listenToPanel) {
subscriber.next(getQueryError('Unknown Panel: ' + listenToPanelId));