From 2185ae5b7a759c16b61ffccbd3c510fb11da7c02 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Wed, 8 Jun 2022 12:28:37 +0200 Subject: [PATCH 1/3] feat(explore): Apply denormalize form data function to echarts and world map --- .../src/controlPanel.ts | 4 ++++ .../src/Line/controlPanel.ts | 5 +++++ .../src/BoxPlot/controlPanel.ts | 13 ++++++++++++- .../src/Funnel/controlPanel.tsx | 5 +++++ .../plugin-chart-echarts/src/Gauge/controlPanel.tsx | 6 +++++- .../plugin-chart-echarts/src/Graph/controlPanel.tsx | 4 ++++ .../plugin-chart-echarts/src/Radar/controlPanel.tsx | 5 +++++ .../src/Timeseries/Area/controlPanel.tsx | 5 +++++ .../src/Timeseries/Regular/Bar/controlPanel.tsx | 5 +++++ .../src/Timeseries/Regular/Scatter/controlPanel.tsx | 5 +++++ .../src/Timeseries/Regular/controlPanel.tsx | 1 + .../src/Timeseries/Step/controlPanel.tsx | 5 +++++ .../src/Timeseries/controlPanel.tsx | 5 +++++ .../plugin-chart-echarts/src/Tree/controlPanel.tsx | 4 ++++ .../src/Treemap/controlPanel.tsx | 5 +++++ 15 files changed, 75 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/controlPanel.ts index 93fc1ab1c9c02..f9f7dfb09dc2e 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-world-map/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-world-map/src/controlPanel.ts @@ -152,6 +152,10 @@ const config: ControlPanelConfig = { Boolean(controls?.color_by.value === ColorBy.country), }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Line/controlPanel.ts b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Line/controlPanel.ts index 5b277cf6718ca..fa4738ebfd2e2 100644 --- a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Line/controlPanel.ts +++ b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Line/controlPanel.ts @@ -96,6 +96,11 @@ const config: ControlPanelConfig = { default: 50000, }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/controlPanel.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/controlPanel.ts index f8e5cbb62950f..b92c289bb43e0 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/controlPanel.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/controlPanel.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { t } from '@superset-ui/core'; +import { ensureIsArray, t } from '@superset-ui/core'; import { D3_FORMAT_DOCS, D3_FORMAT_OPTIONS, @@ -136,5 +136,16 @@ const config: ControlPanelConfig = { ), }, }, + denormalizeFormData: formData => { + const groupby = + formData.standardizedFormData.standardizedState.columns.filter( + col => !ensureIsArray(formData.columns).includes(col), + ); + return { + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby, + }; + }, }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx index fe2269cf89c05..39ce57d498eb0 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx @@ -143,6 +143,11 @@ const config: ControlPanelConfig = { }, }; }, + denormalizeFormData: formData => ({ + ...formData, + metric: formData.standardizedFormData.standardizedState.metrics[0], + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/controlPanel.tsx index ff03da4153b18..d9dbb3025e8b2 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/controlPanel.tsx @@ -39,7 +39,6 @@ const config: ControlPanelConfig = { name: 'groupby', config: { ...sharedControls.groupby, - label: t('Dimensions'), description: t('Columns to group by'), }, }, @@ -309,6 +308,11 @@ const config: ControlPanelConfig = { ], }, ], + denormalizeFormData: formData => ({ + ...formData, + metric: formData.standardizedFormData.standardizedState.metrics[0], + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Graph/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Graph/controlPanel.tsx index cb2f586110177..39547f683a8da 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Graph/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Graph/controlPanel.tsx @@ -320,6 +320,10 @@ const controlPanel: ControlPanelConfig = { ], }, ], + denormalizeFormData: formData => ({ + ...formData, + metric: formData.standardizedFormData.standardizedState.metrics[0], + }), }; export default controlPanel; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx index d24497280ae6b..d78d935a79109 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx @@ -210,6 +210,11 @@ const config: ControlPanelConfig = { ], }, ], + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx index b973cb6782c03..14ceb042f11bb 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Area/controlPanel.tsx @@ -280,6 +280,11 @@ const config: ControlPanelConfig = { default: rowLimit, }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx index 8716bffe2d389..f0c8aa52ac0ea 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx @@ -398,6 +398,11 @@ const config: ControlPanelConfig = { default: rowLimit, }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx index abc5e9a29e724..52e799309890d 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Scatter/controlPanel.tsx @@ -223,6 +223,11 @@ const config: ControlPanelConfig = { default: rowLimit, }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx index eaf3cb2615fd3..c56c4a2ab20ab 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/controlPanel.tsx @@ -243,6 +243,7 @@ const config: ControlPanelConfig = { denormalizeFormData: formData => ({ ...formData, metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, }), }; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx index b8d3a31b2c295..94d179c5a4ab7 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Step/controlPanel.tsx @@ -296,6 +296,11 @@ const config: ControlPanelConfig = { default: rowLimit, }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx index 8f22acadeefc3..843affc3d07e4 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx @@ -299,6 +299,11 @@ const config: ControlPanelConfig = { default: rowLimit, }, }, + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Tree/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Tree/controlPanel.tsx index cd48e0f636e0b..097a882fa3f2d 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Tree/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Tree/controlPanel.tsx @@ -285,6 +285,10 @@ const controlPanel: ControlPanelConfig = { ], }, ], + denormalizeFormData: formData => ({ + ...formData, + metric: formData.standardizedFormData.standardizedState.metrics[0], + }), }; export default controlPanel; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/controlPanel.tsx index 63ca40225ffe6..8887377d2de51 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/controlPanel.tsx @@ -137,6 +137,11 @@ const config: ControlPanelConfig = { ], }, ], + denormalizeFormData: formData => ({ + ...formData, + metric: formData.standardizedFormData.standardizedState.metrics[0], + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; From 869e7fbee45c84e591129f48dc600b4299fb06c9 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Wed, 8 Jun 2022 16:11:01 +0200 Subject: [PATCH 2/3] Denormalize form data in mixed timeseries --- .../src/MixedTimeseries/controlPanel.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx index e39c023661696..22539e31b76e5 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx @@ -17,7 +17,12 @@ * under the License. */ import React from 'react'; -import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; +import { + ensureIsArray, + FeatureFlag, + isFeatureEnabled, + t, +} from '@superset-ui/core'; import { cloneDeep } from 'lodash'; import { ControlPanelConfig, @@ -452,6 +457,21 @@ const config: ControlPanelConfig = { ], }, ], + denormalizeFormData: formData => { + const groupby = + formData.standardizedFormData.standardizedState.columns.filter( + col => !ensureIsArray(formData.groupby_b).includes(col), + ); + const metrics = + formData.standardizedFormData.standardizedState.metrics.filter( + metric => !ensureIsArray(formData.metrics_b).includes(metric), + ); + return { + ...formData, + metrics, + groupby, + }; + }, }; export default config; From e2d2442f39ae6bc7d0cbb432d34878ea79a511c6 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Wed, 8 Jun 2022 17:05:26 +0200 Subject: [PATCH 3/3] Add dist bar chart --- .../legacy-preset-chart-nvd3/src/Bar/controlPanel.ts | 5 +++++ .../src/DistBar/controlPanel.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bar/controlPanel.ts b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bar/controlPanel.ts index 61d3f14add90a..91af47f1f7934 100644 --- a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bar/controlPanel.ts +++ b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/Bar/controlPanel.ts @@ -122,6 +122,11 @@ const config: ControlPanelConfig = { timeSeriesSection[1], sections.annotations, ], + denormalizeFormData: formData => ({ + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + groupby: formData.standardizedFormData.standardizedState.columns, + }), }; export default config; diff --git a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts index 278743d472749..5d526b43e38d9 100644 --- a/superset-frontend/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts +++ b/superset-frontend/plugins/legacy-preset-chart-nvd3/src/DistBar/controlPanel.ts @@ -106,7 +106,6 @@ const config: ControlPanelConfig = { ], controlOverrides: { groupby: { - label: t('Dimensions'), validators: [validateNonEmpty], mapStateToProps: (state, controlState) => { const groupbyProps = @@ -134,6 +133,17 @@ const config: ControlPanelConfig = { rerender: ['groupby'], }, }, + denormalizeFormData: formData => { + const columns = + formData.standardizedFormData.standardizedState.columns.filter( + col => !ensureIsArray(formData.groupby).includes(col), + ); + return { + ...formData, + metrics: formData.standardizedFormData.standardizedState.metrics, + columns, + }; + }, }; export default config;