From fe3ba12801dca32359a6ad811fe9a4f75502106a Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:10:33 -0300 Subject: [PATCH] refactor: Adds the sort_by_metric control to sharedControls (#29325) --- .../src/shared-controls/sharedControls.tsx | 9 +++++++++ .../legacy-plugin-chart-chord/src/controlPanel.ts | 13 +------------ .../src/controlPanel.tsx | 13 +------------ .../legacy-plugin-chart-sankey/src/controlPanel.ts | 13 +------------ .../src/controlPanel.ts | 13 +------------ .../src/Funnel/controlPanel.tsx | 6 +----- .../plugin-chart-echarts/src/Gauge/controlPanel.tsx | 13 +------------ .../plugin-chart-echarts/src/Pie/controlPanel.tsx | 7 ++----- .../src/Sunburst/controlPanel.tsx | 13 +------------ .../src/Treemap/controlPanel.tsx | 13 +------------ .../src/plugin/controlPanel.ts | 13 +------------ 11 files changed, 20 insertions(+), 106 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index c01b4052d..eaf0f172b 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -362,6 +362,14 @@ const temporal_columns_lookup: SharedControlConfig<'HiddenControl'> = { ), }; +const sort_by_metric: SharedControlConfig<'CheckboxControl'> = { + type: 'CheckboxControl', + label: t('Sort by metric'), + description: t( + 'Whether to sort results by the selected metric in descending order.', + ), +}; + export default { metrics: dndAdhocMetricsControl, metric: dndAdhocMetricControl, @@ -400,4 +408,5 @@ export default { show_empty_columns, temporal_columns_lookup, currency_format, + sort_by_metric, }; 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 679e95970..031382a45 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-chord/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-chord/src/controlPanel.ts @@ -33,18 +33,7 @@ const config: ControlPanelConfig = { ['metric'], ['adhoc_filters'], ['row_limit'], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, { diff --git a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.tsx b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.tsx index 53394c99e..d22428e1e 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.tsx +++ b/superset-frontend/plugins/legacy-plugin-chart-heatmap/src/controlPanel.tsx @@ -64,18 +64,7 @@ const config: ControlPanelConfig = { ['metric'], ['adhoc_filters'], ['row_limit'], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, { diff --git a/superset-frontend/plugins/legacy-plugin-chart-sankey/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-sankey/src/controlPanel.ts index ef9f0394d..7505f1a4a 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-sankey/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-sankey/src/controlPanel.ts @@ -49,18 +49,7 @@ const config: ControlPanelConfig = { }, }, ], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, { 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 82d8dcb1e..f75764e9f 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 @@ -54,18 +54,7 @@ const config: ControlPanelConfig = { ['metric'], ['adhoc_filters'], ['row_limit'], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, { 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 a8e4f0164..df2b23c59 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx @@ -62,12 +62,8 @@ const config: ControlPanelConfig = { { name: 'sort_by_metric', config: { + ...sharedControls.sort_by_metric, default: true, - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), }, }, ], 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 8727a23c7..5d6df447a 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/controlPanel.tsx @@ -53,18 +53,7 @@ const config: ControlPanelConfig = { }, }, ], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/controlPanel.tsx index 7e700c18c..583444508 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/controlPanel.tsx @@ -26,6 +26,7 @@ import { D3_FORMAT_OPTIONS, D3_TIME_FORMAT_OPTIONS, getStandardizedControls, + sharedControls, } from '@superset-ui/chart-controls'; import { DEFAULT_FORM_DATA } from './types'; import { legendSection } from '../controls'; @@ -56,12 +57,8 @@ const config: ControlPanelConfig = { { name: 'sort_by_metric', config: { + ...sharedControls.sort_by_metric, default: true, - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), }, }, ], diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Sunburst/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Sunburst/controlPanel.tsx index 532b19b41..2a64a8f96 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Sunburst/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Sunburst/controlPanel.tsx @@ -42,18 +42,7 @@ const config: ControlPanelConfig = { ['secondary_metric'], ['adhoc_filters'], ['row_limit'], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, { 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 2e09f25d1..1e1dc4757 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/controlPanel.tsx @@ -40,18 +40,7 @@ const config: ControlPanelConfig = { ['groupby'], ['metric'], ['row_limit'], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ['adhoc_filters'], ], }, diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/src/plugin/controlPanel.ts b/superset-frontend/plugins/plugin-chart-word-cloud/src/plugin/controlPanel.ts index 3ba153d24..9425f1211 100644 --- a/superset-frontend/plugins/plugin-chart-word-cloud/src/plugin/controlPanel.ts +++ b/superset-frontend/plugins/plugin-chart-word-cloud/src/plugin/controlPanel.ts @@ -32,18 +32,7 @@ const config: ControlPanelConfig = { ['metric'], ['adhoc_filters'], ['row_limit'], - [ - { - name: 'sort_by_metric', - config: { - type: 'CheckboxControl', - label: t('Sort by metric'), - description: t( - 'Whether to sort results by the selected metric in descending order.', - ), - }, - }, - ], + ['sort_by_metric'], ], }, {