From 3b017e0fb1b25192f4c3e7e68b07066b2ce5b9c6 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 18 May 2022 17:31:03 -0700 Subject: [PATCH] Inspect: include annotation data in DataFrameJSON debugger (#49204) --- .../app/features/inspector/InspectJSONTab.tsx | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/public/app/features/inspector/InspectJSONTab.tsx b/public/app/features/inspector/InspectJSONTab.tsx index dcf9b9ab886..3c9c1adfca9 100644 --- a/public/app/features/inspector/InspectJSONTab.tsx +++ b/public/app/features/inspector/InspectJSONTab.tsx @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react'; import AutoSizer from 'react-virtualized-auto-sizer'; -import { AppEvents, dataFrameToJSON, PanelData, SelectableValue } from '@grafana/data'; +import { AppEvents, DataFrameJSON, dataFrameToJSON, DataTopic, PanelData, SelectableValue } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { Button, CodeEditor, Field, Select } from '@grafana/ui'; import { appEvents } from 'app/core/core'; @@ -76,11 +76,7 @@ export class InspectJSONTab extends PureComponent { } if (show === ShowContent.DataFrames) { - const series = data?.series; - if (!series) { - return { note: 'Missing Response Data' }; - } - return data.series.map((frame) => dataFrameToJSON(frame)); + return getPanelDataFrames(data); } if (this.hasPanelJSON && show === ShowContent.PanelJSON) { @@ -159,6 +155,26 @@ export class InspectJSONTab extends PureComponent { } } +function getPanelDataFrames(data?: PanelData): DataFrameJSON[] { + const frames: DataFrameJSON[] = []; + if (data?.series) { + for (const f of data.series) { + frames.push(dataFrameToJSON(f)); + } + } + if (data?.annotations) { + for (const f of data.annotations) { + const json = dataFrameToJSON(f); + if (!json.schema?.meta) { + json.schema!.meta = {}; + } + json.schema!.meta.dataTopic = DataTopic.Annotations; + frames.push(json); + } + } + return frames; +} + function getPrettyJSON(obj: any): string { return JSON.stringify(obj, null, 2); }