This is an automated email from the ASF dual-hosted git repository.

yongjiezhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c252d7524 feat: adding truncate metric control on timeseries charts 
(#20373)
7c252d7524 is described below

commit 7c252d75240559d0bba9be3be8419b65b86967df
Author: Yongjie Zhao <[email protected]>
AuthorDate: Wed Jun 15 20:55:10 2022 +0800

    feat: adding truncate metric control on timeseries charts (#20373)
---
 .../src/operators/renameOperator.ts                |  7 +++++--
 .../src/shared-controls/index.tsx                  |  8 ++++++++
 .../test/operators/renameOperator.test.ts          | 22 ++++++++++++++++++++++
 .../src/MixedTimeseries/controlPanel.tsx           |  9 +++++++++
 .../src/Timeseries/Area/controlPanel.tsx           |  1 +
 .../src/Timeseries/Regular/Bar/controlPanel.tsx    |  1 +
 .../Timeseries/Regular/Scatter/controlPanel.tsx    |  1 +
 .../src/Timeseries/Regular/controlPanel.tsx        |  1 +
 .../src/Timeseries/Step/controlPanel.tsx           |  1 +
 .../src/Timeseries/controlPanel.tsx                |  1 +
 .../test/MixedTimeseries/buildQuery.test.ts        |  2 ++
 11 files changed, 52 insertions(+), 2 deletions(-)

diff --git 
a/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
 
b/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
index 94dfa70bbc..84cbbce8c5 100644
--- 
a/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
+++ 
b/superset-frontend/packages/superset-ui-chart-controls/src/operators/renameOperator.ts
@@ -32,12 +32,13 @@ export const renameOperator: 
PostProcessingFactory<PostProcessingRename> = (
 ) => {
   const metrics = ensureIsArray(queryObject.metrics);
   const columns = ensureIsArray(queryObject.columns);
-  const { x_axis: xAxis } = formData;
+  const { x_axis: xAxis, truncate_metric } = formData;
   // remove or rename top level of column name(metric name) in the MultiIndex 
when
   // 1) only 1 metric
   // 2) exist dimentsion
   // 3) exist xAxis
   // 4) exist time comparison, and comparison type is "actual values"
+  // 5) truncate_metric in form_data and truncate_metric is true
   if (
     metrics.length === 1 &&
     columns.length > 0 &&
@@ -52,7 +53,9 @@ export const renameOperator: 
PostProcessingFactory<PostProcessingRename> = (
           ComparisionType.Percentage,
         ].includes(formData.comparison_type)
       )
-    )
+    ) &&
+    truncate_metric !== undefined &&
+    !!truncate_metric
   ) {
     const renamePairs: [string, string | null][] = [];
 
diff --git 
a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx
 
b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx
index 5ff32d50b0..c5bc9d56d4 100644
--- 
a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx
+++ 
b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx
@@ -533,6 +533,13 @@ const color_scheme: 
SharedControlConfig<'ColorSchemeControl'> = {
   }),
 };
 
+const truncate_metric: SharedControlConfig<'CheckboxControl'> = {
+  type: 'CheckboxControl',
+  label: t('Truncate Metric'),
+  default: true,
+  description: t('Whether to truncate metrics'),
+};
+
 const enableExploreDnd = isFeatureEnabled(
   FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP,
 );
@@ -571,6 +578,7 @@ const sharedControls = {
   series_limit,
   series_limit_metric: enableExploreDnd ? dnd_sort_by : sort_by,
   legacy_order_by: enableExploreDnd ? dnd_sort_by : sort_by,
+  truncate_metric,
 };
 
 export { sharedControls, dndEntity, dndColumnsControl };
diff --git 
a/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
 
b/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
index 2c32e0791b..26bbe9e369 100644
--- 
a/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
+++ 
b/superset-frontend/packages/superset-ui-chart-controls/test/operators/renameOperator.test.ts
@@ -27,6 +27,7 @@ const formData: SqlaFormData = {
   granularity: 'month',
   datasource: 'foo',
   viz_type: 'table',
+  truncate_metric: true,
 };
 const queryObject: QueryObject = {
   is_timeseries: true,
@@ -144,3 +145,24 @@ test('should add renameOperator if exist "actual value" 
time comparison', () =>
     },
   });
 });
+
+test('should remove renameOperator', () => {
+  expect(
+    renameOperator(
+      {
+        ...formData,
+        truncate_metric: false,
+      },
+      queryObject,
+    ),
+  ).toEqual(undefined);
+  expect(
+    renameOperator(
+      {
+        ...formData,
+        truncate_metric: undefined,
+      },
+      queryObject,
+    ),
+  ).toEqual(undefined);
+});
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 74c0ac8890..fb164f1a26 100644
--- 
a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
+++ 
b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx
@@ -123,6 +123,15 @@ function createQuerySection(
           },
         },
       ],
+      [
+        {
+          name: `truncate_metric${controlSuffix}`,
+          config: {
+            ...sharedControls.truncate_metric,
+            default: sharedControls.truncate_metric.default,
+          },
+        },
+      ],
     ],
   };
 }
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 c2aeb2916b..c8922dd11e 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
@@ -87,6 +87,7 @@ const config: ControlPanelConfig = {
         ['timeseries_limit_metric'],
         ['order_desc'],
         ['row_limit'],
+        ['truncate_metric'],
       ],
     },
     sections.advancedAnalyticsControls,
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 f0c8aa52ac..2080fceef6 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
@@ -296,6 +296,7 @@ const config: ControlPanelConfig = {
         ['timeseries_limit_metric'],
         ['order_desc'],
         ['row_limit'],
+        ['truncate_metric'],
       ],
     },
     sections.advancedAnalyticsControls,
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 52e7993098..fd2fa79651 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
@@ -62,6 +62,7 @@ const config: ControlPanelConfig = {
         ['timeseries_limit_metric'],
         ['order_desc'],
         ['row_limit'],
+        ['truncate_metric'],
       ],
     },
     sections.advancedAnalyticsControls,
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 c56c4a2ab2..8dc34861b1 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
@@ -79,6 +79,7 @@ const config: ControlPanelConfig = {
         ['timeseries_limit_metric'],
         ['order_desc'],
         ['row_limit'],
+        ['truncate_metric'],
       ],
     },
     sections.advancedAnalyticsControls,
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 94d179c5a4..2902937333 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
@@ -85,6 +85,7 @@ const config: ControlPanelConfig = {
         ['timeseries_limit_metric'],
         ['order_desc'],
         ['row_limit'],
+        ['truncate_metric'],
       ],
     },
     sections.advancedAnalyticsControls,
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 843affc3d0..d039a059c5 100644
--- 
a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx
+++ 
b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/controlPanel.tsx
@@ -86,6 +86,7 @@ const config: ControlPanelConfig = {
         ['timeseries_limit_metric'],
         ['order_desc'],
         ['row_limit'],
+        ['truncate_metric'],
       ],
     },
     sections.advancedAnalyticsControls,
diff --git 
a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
 
b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
index eb95a4f71d..0b766c2dc4 100644
--- 
a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
+++ 
b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
@@ -47,6 +47,7 @@ const formDataMixedChart = {
   timeseries_limit_metric: 'count',
   order_desc: true,
   emit_filter: true,
+  truncate_metric: true,
   //   -- query b
   groupby_b: [],
   metrics_b: ['count'],
@@ -62,6 +63,7 @@ const formDataMixedChart = {
   timeseries_limit_metric_b: undefined,
   order_desc_b: false,
   emit_filter_b: undefined,
+  truncate_metric_b: true,
   // chart configs
   show_value: false,
   show_valueB: undefined,

Reply via email to