You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2024/02/27 20:44:25 UTC

(superset) 08/08: fix: Inoperable dashboard filter slider when range is <= 1 (#27271)

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

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

commit 38bc2d3b02aabdf2599d6b29fb56c728b7decaa8
Author: Michael S. Molina <70...@users.noreply.github.com>
AuthorDate: Tue Feb 27 11:38:18 2024 -0500

    fix: Inoperable dashboard filter slider when range is <= 1 (#27271)
    
    Co-authored-by: Justin Francos <jf...@manifold.ai>
    (cherry picked from commit ce9e4b4b776ba8071aab2ede538b51828250bb2b)
---
 .../src/filters/components/Range/RangeFilterPlugin.tsx     | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/superset-frontend/src/filters/components/Range/RangeFilterPlugin.tsx b/superset-frontend/src/filters/components/Range/RangeFilterPlugin.tsx
index 5c8533dd1e..9b30cd4824 100644
--- a/superset-frontend/src/filters/components/Range/RangeFilterPlugin.tsx
+++ b/superset-frontend/src/filters/components/Range/RangeFilterPlugin.tsx
@@ -300,6 +300,16 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
     }
   }, [enableSingleExactValue]);
 
+  const MIN_NUM_STEPS = 20;
+  const stepHeuristic = (min: number, max: number) => {
+    const maxStepSize = (max - min) / MIN_NUM_STEPS;
+    // normalizedStepSize: .06 -> .01, .003 -> .001
+    const normalizedStepSize = `1E${Math.floor(Math.log10(maxStepSize))}`;
+    return Math.min(1, parseFloat(normalizedStepSize));
+  };
+
+  const step = max - min <= 1 ? stepHeuristic(min, max) : 1;
+
   return (
     <FilterPluginStyle height={height} width={width}>
       {Number.isNaN(Number(min)) || Number.isNaN(Number(max)) ? (
@@ -323,6 +333,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
               <AntdSlider
                 min={min}
                 max={max}
+                step={step}
                 value={minMax[maxIndex]}
                 tipFormatter={tipFormatter}
                 marks={marks}
@@ -335,6 +346,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
                 validateStatus={filterState.validateStatus}
                 min={min}
                 max={max}
+                step={step}
                 value={minMax[minIndex]}
                 tipFormatter={tipFormatter}
                 marks={marks}
@@ -346,6 +358,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
               <AntdSlider
                 min={min}
                 max={max}
+                step={step}
                 included={false}
                 value={minMax[minIndex]}
                 tipFormatter={tipFormatter}
@@ -359,6 +372,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
                 range
                 min={min}
                 max={max}
+                step={step}
                 value={minMax}
                 onAfterChange={handleAfterChange}
                 onChange={handleChange}