From e12ee59b13822241dca8d8015f1222c477edd4f3 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Tue, 28 Jun 2022 20:21:36 +0200 Subject: [PATCH] feat(explore): Apply denormalization to tier 2 charts form data (#20524) * feat(explore): Denormalize form data in Calendar Heatmap * feat(explore): Denormalize form data in Bubble * feat(explore): Denormalize form data in Chord * Dimensions -> Dimension for single selection * feat(explore): Denormalize form data in Country Map * feat(explore): Denormalize form data in Heatmap * feat(explore): Denormalize form data in Histogram * feat(explore): Denormalize form data in Handlebars * feat(explore): Denormalize form data in Percent Change * Use new standardized form data interface --- .../src/shared-controls/dndControls.tsx | 2 +- .../src/utils/getStandardizedControls.ts | 4 ++++ .../src/controlPanel.ts | 5 +++++ .../src/controlPanel.ts | 18 ++++++++++++++++-- .../src/controlPanel.ts | 6 ++++++ .../src/controlPanel.ts | 5 +++++ .../src/controlPanel.ts | 5 +++++ .../src/Bubble/controlPanel.ts | 6 ++++++ .../src/Compare/controlPanel.ts | 11 ++++++++++- .../src/plugin/controlPanel.tsx | 6 ++++++ 10 files changed, 64 insertions(+), 4 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/dndControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/dndControls.tsx index 43b0059046..63aa64bf46 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/dndControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/dndControls.tsx @@ -72,7 +72,7 @@ export const dndColumnsControl: typeof dndGroupByControl = { export const dndSeries: typeof dndGroupByControl = { ...dndGroupByControl, - label: t('Dimensions'), + label: t('Dimension'), multi: false, default: null, description: t( diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getStandardizedControls.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getStandardizedControls.ts index 650e063d60..42ff874c58 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getStandardizedControls.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getStandardizedControls.ts @@ -43,6 +43,10 @@ class StandardizedControlsManager { return this.controls.metrics.shift(); } + shiftColumn() { + return this.controls.columns.shift(); + } + popAllMetrics() { return this.controls.metrics.splice(0, this.controls.metrics.length); } diff --git a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts index 2787687b06..fe2c1bd1fc 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-calendar/src/controlPanel.ts @@ -22,6 +22,7 @@ import { D3_FORMAT_DOCS, D3_TIME_FORMAT_OPTIONS, formatSelectOptions, + getStandardizedControls, sections, } from '@superset-ui/chart-controls'; @@ -191,6 +192,10 @@ const config: ControlPanelConfig = { label: t('Number Format'), }, }, + formDataOverrides: formData => ({ + ...formData, + metrics: getStandardizedControls().popAllMetrics(), + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-plugin-chart-chord/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-chord/src/controlPanel.ts index c2559a7b0d..5a58b567a7 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-chord/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-chord/src/controlPanel.ts @@ -16,8 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -import { t, validateNonEmpty } from '@superset-ui/core'; -import { ControlPanelConfig, sections } from '@superset-ui/chart-controls'; +import { ensureIsArray, t, validateNonEmpty } from '@superset-ui/core'; +import { + ControlPanelConfig, + getStandardizedControls, + sections, +} from '@superset-ui/chart-controls'; const config: ControlPanelConfig = { controlPanelSections: [ @@ -69,6 +73,16 @@ const config: ControlPanelConfig = { description: t('Choose a target'), }, }, + formDataOverrides: formData => { + const groupby = getStandardizedControls() + .popAllColumns() + .filter(col => !ensureIsArray(formData.columns).includes(col)); + return { + ...formData, + groupby, + metric: getStandardizedControls().shiftMetric(), + }; + }, }; export default config; diff --git a/superset-frontend/plugins/legacy-plugin-chart-country-map/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-country-map/src/controlPanel.ts index f1aad661ee..c6b26bd2b6 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-country-map/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-country-map/src/controlPanel.ts @@ -22,6 +22,7 @@ import { D3_FORMAT_OPTIONS, D3_FORMAT_DOCS, sections, + getStandardizedControls, } from '@superset-ui/chart-controls'; import { countryOptions } from './countries'; @@ -88,6 +89,11 @@ const config: ControlPanelConfig = { renderTrigger: false, }, }, + formDataOverrides: formData => ({ + ...formData, + entity: getStandardizedControls().shiftColumn(), + metric: getStandardizedControls().shiftMetric(), + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.ts index ab3eb2a59f..f4528d23b5 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.ts @@ -30,6 +30,7 @@ import { formatSelectOptionsForRange, sections, dndEntity, + getStandardizedControls, } from '@superset-ui/chart-controls'; const sortAxisChoices = [ @@ -329,6 +330,10 @@ const config: ControlPanelConfig = { label: t('Value Format'), }, }, + formDataOverrides: formData => ({ + ...formData, + metric: getStandardizedControls().shiftMetric(), + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-plugin-chart-histogram/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-histogram/src/controlPanel.ts index 26cec94749..6c5a13ce6a 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-histogram/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-histogram/src/controlPanel.ts @@ -29,6 +29,7 @@ import { formatSelectOptions, sections, dndColumnsControl, + getStandardizedControls, } from '@superset-ui/chart-controls'; const allColumns = { @@ -160,5 +161,9 @@ const config: ControlPanelConfig = { ], }, ], + formDataOverrides: formData => ({ + ...formData, + groupby: getStandardizedControls().popAllColumns(), + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bubble/controlPanel.ts b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bubble/controlPanel.ts index 33a4ea6bf0..1bac94b5af 100644 --- a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bubble/controlPanel.ts +++ b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bubble/controlPanel.ts @@ -22,6 +22,7 @@ import { formatSelectOptions, D3_FORMAT_OPTIONS, sections, + getStandardizedControls, } from '@superset-ui/chart-controls'; import { showLegend, @@ -128,6 +129,11 @@ const config: ControlPanelConfig = { renderTrigger: false, }, }, + formDataOverrides: formData => ({ + ...formData, + series: getStandardizedControls().shiftColumn(), + entity: getStandardizedControls().shiftColumn(), + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Compare/controlPanel.ts b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Compare/controlPanel.ts index db4a84fd47..fcae6dd397 100644 --- a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Compare/controlPanel.ts +++ b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Compare/controlPanel.ts @@ -17,7 +17,11 @@ * under the License. */ import { t } from '@superset-ui/core'; -import { ControlPanelConfig, sections } from '@superset-ui/chart-controls'; +import { + ControlPanelConfig, + getStandardizedControls, + sections, +} from '@superset-ui/chart-controls'; import { xAxisLabel, yAxisLabel, @@ -62,6 +66,11 @@ const config: ControlPanelConfig = { timeSeriesSection[1], sections.annotations, ], + formDataOverrides: formData => ({ + ...formData, + groupby: getStandardizedControls().popAllColumns(), + metrics: getStandardizedControls().popAllMetrics(), + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-handlebars/src/plugin/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-handlebars/src/plugin/controlPanel.tsx index da0ba7d589..288ec0972e 100644 --- a/superset-frontend/plugins/plugin-chart-handlebars/src/plugin/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-handlebars/src/plugin/controlPanel.tsx @@ -19,6 +19,7 @@ import { ControlPanelConfig, emitFilterControl, + getStandardizedControls, sections, } from '@superset-ui/chart-controls'; import { addLocaleData, t } from '@superset-ui/core'; @@ -78,6 +79,11 @@ const config: ControlPanelConfig = { ], }, ], + formDataOverrides: formData => ({ + ...formData, + groupby: getStandardizedControls().popAllColumns(), + metrics: getStandardizedControls().popAllMetrics(), + }), }; export default config;