mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard datasource: Return annotations as series when query topic is "annotations" (#95965)
This commit is contained in:
parent
a279220d74
commit
26b0e8f105
@ -7,6 +7,9 @@ import {
|
||||
DataSourceInstanceSettings,
|
||||
TestDataSourceResponse,
|
||||
ScopedVar,
|
||||
DataTopic,
|
||||
PanelData,
|
||||
DataFrame,
|
||||
} from '@grafana/data';
|
||||
import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes';
|
||||
import {
|
||||
@ -78,7 +81,7 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
|
||||
return sourceDataProvider!.getResultsStream!().pipe(
|
||||
map((result) => {
|
||||
return {
|
||||
data: [...result.data.series, ...(result.data.annotations ?? [])],
|
||||
data: this.getDataFramesForQueryTopic(result.data, query),
|
||||
state: result.data.state,
|
||||
errors: result.data.errors,
|
||||
error: result.data.error,
|
||||
@ -90,6 +93,21 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
|
||||
});
|
||||
}
|
||||
|
||||
private getDataFramesForQueryTopic(data: PanelData, query: DashboardQuery): DataFrame[] {
|
||||
const annotations = data.annotations ?? [];
|
||||
if (query.topic === DataTopic.Annotations) {
|
||||
return annotations.map((frame) => ({
|
||||
...frame,
|
||||
meta: {
|
||||
...frame.meta,
|
||||
dataTopic: DataTopic.Series,
|
||||
},
|
||||
}));
|
||||
} else {
|
||||
return [...data.series, ...annotations];
|
||||
}
|
||||
}
|
||||
|
||||
private findSourcePanel(scene: SceneObject, panelId: number) {
|
||||
return findVizPanelByKey(scene, getVizPanelKeyForPanelId(panelId));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user