mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelInspect: Clean table display settings from field config (#71226)
* Does not work, hmm.. * now it works * fixing and refactoring * remove unused import
This commit is contained in:
@@ -30,7 +30,8 @@ export const usePanelLatestData = (
|
|||||||
|
|
||||||
querySubscription.current = panel
|
querySubscription.current = panel
|
||||||
.getQueryRunner()
|
.getQueryRunner()
|
||||||
.getData(options)
|
// We apply field config later
|
||||||
|
.getData({ withTransforms: options.withTransforms, withFieldConfig: false })
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (data) => {
|
next: (data) => {
|
||||||
if (checkSchema) {
|
if (checkSchema) {
|
||||||
@@ -58,7 +59,7 @@ export const usePanelLatestData = (
|
|||||||
* Otherwise, passing different references to the same object might cause troubles.
|
* Otherwise, passing different references to the same object might cause troubles.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [panel, options.withFieldConfig, options.withTransforms]);
|
}, [panel, options.withTransforms]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: latestData,
|
data: latestData,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import AutoSizer from 'react-virtualized-auto-sizer';
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
CSVConfig,
|
CSVConfig,
|
||||||
DataFrame,
|
DataFrame,
|
||||||
DataTransformerID,
|
DataTransformerID,
|
||||||
|
FieldConfigSource,
|
||||||
SelectableValue,
|
SelectableValue,
|
||||||
TimeZone,
|
TimeZone,
|
||||||
transformDataFrame,
|
transformDataFrame,
|
||||||
@@ -170,12 +172,14 @@ export class InspectDataTab extends PureComponent<Props, State> {
|
|||||||
return applyRawFieldOverrides(data);
|
return applyRawFieldOverrides(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to apply field config even though it was already applied in the PanelQueryRunner.
|
const fieldConfig = this.cleanTableConfigFromFieldConfig(panel.type, panel.fieldConfig);
|
||||||
// That's because transformers create new fields and data frames, so i.e. display processor is no longer there
|
|
||||||
|
// We need to apply field config as it's not done by PanelQueryRunner (even when withFieldConfig is true).
|
||||||
|
// It's because transformers create new fields and data frames, and we need to clean field config of any table settings.
|
||||||
return applyFieldOverrides({
|
return applyFieldOverrides({
|
||||||
data,
|
data,
|
||||||
theme: config.theme2,
|
theme: config.theme2,
|
||||||
fieldConfig: panel.fieldConfig,
|
fieldConfig,
|
||||||
timeZone,
|
timeZone,
|
||||||
replaceVariables: (value: string) => {
|
replaceVariables: (value: string) => {
|
||||||
return value;
|
return value;
|
||||||
@@ -183,6 +187,29 @@ export class InspectDataTab extends PureComponent<Props, State> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Because we visualize this data in a table we have to remove any custom table display settings
|
||||||
|
cleanTableConfigFromFieldConfig(panelPluginId: string, fieldConfig: FieldConfigSource): FieldConfigSource {
|
||||||
|
if (panelPluginId !== 'table') {
|
||||||
|
return fieldConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldConfig = cloneDeep(fieldConfig);
|
||||||
|
// clear all table specific options
|
||||||
|
fieldConfig.defaults.custom = {};
|
||||||
|
|
||||||
|
// clear all table override properties
|
||||||
|
for (const override of fieldConfig.overrides) {
|
||||||
|
for (const prop of override.properties) {
|
||||||
|
if (prop.id.startsWith('custom.')) {
|
||||||
|
const index = override.properties.indexOf(prop);
|
||||||
|
override.properties.slice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fieldConfig;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isLoading, options, data, panel, onOptionsChange, app } = this.props;
|
const { isLoading, options, data, panel, onOptionsChange, app } = this.props;
|
||||||
const { dataFrameIndex, transformId, transformationOptions, selectedDataFrame, downloadForExcel } = this.state;
|
const { dataFrameIndex, transformId, transformationOptions, selectedDataFrame, downloadForExcel } = this.state;
|
||||||
|
|||||||
Reference in New Issue
Block a user