You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ar...@apache.org on 2024/02/12 13:51:11 UTC

(superset) branch master updated: feat(plugins): Update custom controls for BigNumber with Time Comparison chart (#27054)

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

arivero 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 435cd2705e feat(plugins): Update custom controls for BigNumber with Time Comparison chart (#27054)
435cd2705e is described below

commit 435cd2705e22248ff0d6a856e78179338c427654
Author: Antonio Rivero <38...@users.noreply.github.com>
AuthorDate: Mon Feb 12 14:51:04 2024 +0100

    feat(plugins): Update custom controls for BigNumber with Time Comparison chart (#27054)
---
 .../src/plugin/controlPanel.ts                     | 55 ++++++++++++++++------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/superset-frontend/plugins/plugin-chart-period-over-period-kpi/src/plugin/controlPanel.ts b/superset-frontend/plugins/plugin-chart-period-over-period-kpi/src/plugin/controlPanel.ts
index 82379745fd..89afdb4835 100644
--- a/superset-frontend/plugins/plugin-chart-period-over-period-kpi/src/plugin/controlPanel.ts
+++ b/superset-frontend/plugins/plugin-chart-period-over-period-kpi/src/plugin/controlPanel.ts
@@ -16,12 +16,27 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { t, validateNonEmpty } from '@superset-ui/core';
+import { ensureIsArray, t, validateNonEmpty } from '@superset-ui/core';
 import {
   ControlPanelConfig,
+  ControlPanelState,
+  ControlState,
   sharedControls,
 } from '@superset-ui/chart-controls';
 
+const validateTimeComparisonRangeValues = (
+  timeRangeValue?: any,
+  controlValue?: any,
+) => {
+  const isCustomTimeRange = timeRangeValue === 'c';
+  const isCustomControlEmpty = controlValue?.every(
+    (val: any) => ensureIsArray(val).length === 0,
+  );
+  return isCustomTimeRange && isCustomControlEmpty
+    ? [t('Filters for comparison must have a value')]
+    : [];
+};
+
 const config: ControlPanelConfig = {
   controlPanelSections: [
     {
@@ -54,32 +69,42 @@ const config: ControlPanelConfig = {
                 ['r', 'Range'],
                 ['c', 'Custom'],
               ],
+              rerender: ['adhoc_custom'],
             },
           },
         ],
-        [
-          {
-            name: 'row_limit',
-            config: sharedControls.row_limit,
-          },
-        ],
-      ],
-    },
-    {
-      label: t('Custom Time Range'),
-      expanded: true,
-      controlSetRows: [
         [
           {
             name: `adhoc_custom`,
             config: {
               ...sharedControls.adhoc_filters,
-              label: t('FILTERS (Custom)'),
+              label: t('Filters for Comparison'),
               description:
-                'This only applies when selecting the Range for Comparison Type- Custom',
+                'This only applies when selecting the Range for Comparison Type: Custom',
+              visibility: ({ controls }) =>
+                controls?.time_comparison?.value === 'c',
+              mapStateToProps: (
+                state: ControlPanelState,
+                controlState: ControlState,
+              ) => ({
+                ...(sharedControls.adhoc_filters.mapStateToProps?.(
+                  state,
+                  controlState,
+                ) || {}),
+                externalValidationErrors: validateTimeComparisonRangeValues(
+                  state.controls?.time_comparison?.value,
+                  controlState.value,
+                ),
+              }),
             },
           },
         ],
+        [
+          {
+            name: 'row_limit',
+            config: sharedControls.row_limit,
+          },
+        ],
       ],
     },
     {