Inspect: show DataFrame JSON *before* transformation and field config are applied (#53867)

This commit is contained in:
Ryan McKinley 2022-08-18 15:06:33 -07:00 committed by GitHub
parent 9be73e758d
commit 7755f4c4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View File

@ -1,8 +1,17 @@
import { t } from '@lingui/macro';
import React, { PureComponent } from 'react';
import AutoSizer from 'react-virtualized-auto-sizer';
import { firstValueFrom } from 'rxjs';
import { AppEvents, DataFrameJSON, dataFrameToJSON, DataTopic, PanelData, SelectableValue } from '@grafana/data';
import {
AppEvents,
DataFrameJSON,
dataFrameToJSON,
DataTopic,
PanelData,
SelectableValue,
LoadingState,
} from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { Button, CodeEditor, Field, Select } from '@grafana/ui';
import { appEvents } from 'app/core/core';
@ -34,8 +43,11 @@ const options: Array<SelectableValue<ShowContent>> = [
value: ShowContent.PanelData,
},
{
label: t({ id: 'dashboard.inspect-json.dataframe-label', message: 'DataFrame JSON' }),
description: t({ id: 'dashboard.inspect-json.dataframe-description', message: 'JSON formatted DataFrames' }),
label: t({ id: 'dashboard.inspect-json.dataframe-label', message: 'DataFrame JSON (from Query)' }),
description: t({
id: 'dashboard.inspect-json.dataframe-description',
message: 'Raw data without transformations and field config applied. ',
}),
value: ShowContent.DataFrames,
},
];
@ -65,8 +77,8 @@ export class InspectJSONTab extends PureComponent<Props, State> {
};
}
onSelectChanged = (item: SelectableValue<ShowContent>) => {
const show = this.getJSONObject(item.value!);
onSelectChanged = async (item: SelectableValue<ShowContent>) => {
const show = await this.getJSONObject(item.value!);
const text = getPrettyJSON(show);
this.setState({ text, show: item.value! });
};
@ -76,14 +88,25 @@ export class InspectJSONTab extends PureComponent<Props, State> {
this.setState({ text });
};
getJSONObject(show: ShowContent) {
async getJSONObject(show: ShowContent) {
const { data, panel } = this.props;
if (show === ShowContent.PanelData) {
return data;
}
if (show === ShowContent.DataFrames) {
return getPanelDataFrames(data);
let d = data;
// do not include transforms and
if (panel && data?.state === LoadingState.Done) {
d = await firstValueFrom(
panel.getQueryRunner().getData({
withFieldConfig: false,
withTransforms: false,
})
);
}
return getPanelDataFrames(d);
}
if (this.hasPanelJSON && show === ShowContent.PanelJSON) {

View File

@ -109,11 +109,11 @@ msgstr "Apply panel transformations"
#: public/app/features/inspector/InspectJSONTab.tsx
msgid "dashboard.inspect-json.dataframe-description"
msgstr "JSON formatted DataFrames"
msgstr "Raw data without transformations and field config applied."
#: public/app/features/inspector/InspectJSONTab.tsx
msgid "dashboard.inspect-json.dataframe-label"
msgstr "DataFrame JSON"
msgstr "DataFrame JSON (from Query)"
#: public/app/features/inspector/InspectJSONTab.tsx
msgid "dashboard.inspect-json.panel-data-description"