From 9f2baaf5c3580ebba0185bd821c8e8c0f122a7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 10 Jul 2023 16:27:03 +0200 Subject: [PATCH] PanelInspect: Clean table display settings from field config (#71226) * Does not work, hmm.. * now it works * fixing and refactoring * remove unused import --- .../PanelEditor/usePanelLatestData.ts | 5 +-- .../app/features/inspector/InspectDataTab.tsx | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts b/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts index f3e2aa5f2d2..e3d24cae356 100644 --- a/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts +++ b/public/app/features/dashboard/components/PanelEditor/usePanelLatestData.ts @@ -30,7 +30,8 @@ export const usePanelLatestData = ( querySubscription.current = panel .getQueryRunner() - .getData(options) + // We apply field config later + .getData({ withTransforms: options.withTransforms, withFieldConfig: false }) .subscribe({ next: (data) => { if (checkSchema) { @@ -58,7 +59,7 @@ export const usePanelLatestData = ( * Otherwise, passing different references to the same object might cause troubles. */ // eslint-disable-next-line react-hooks/exhaustive-deps - }, [panel, options.withFieldConfig, options.withTransforms]); + }, [panel, options.withTransforms]); return { data: latestData, diff --git a/public/app/features/inspector/InspectDataTab.tsx b/public/app/features/inspector/InspectDataTab.tsx index 9025cfdba8e..a3adea4dec4 100644 --- a/public/app/features/inspector/InspectDataTab.tsx +++ b/public/app/features/inspector/InspectDataTab.tsx @@ -1,4 +1,5 @@ import { css } from '@emotion/css'; +import { cloneDeep } from 'lodash'; import React, { PureComponent } from 'react'; import AutoSizer from 'react-virtualized-auto-sizer'; @@ -9,6 +10,7 @@ import { CSVConfig, DataFrame, DataTransformerID, + FieldConfigSource, SelectableValue, TimeZone, transformDataFrame, @@ -170,12 +172,14 @@ export class InspectDataTab extends PureComponent { return applyRawFieldOverrides(data); } - // We need to apply field config even though it was already applied in the PanelQueryRunner. - // That's because transformers create new fields and data frames, so i.e. display processor is no longer there + const fieldConfig = this.cleanTableConfigFromFieldConfig(panel.type, panel.fieldConfig); + + // 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({ data, theme: config.theme2, - fieldConfig: panel.fieldConfig, + fieldConfig, timeZone, replaceVariables: (value: string) => { return value; @@ -183,6 +187,29 @@ export class InspectDataTab extends PureComponent { }); } + // 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() { const { isLoading, options, data, panel, onOptionsChange, app } = this.props; const { dataFrameIndex, transformId, transformationOptions, selectedDataFrame, downloadForExcel } = this.state;