From 6b82e27561a40901c23e5af9ed8250af6bb2d240 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:38:18 -0500 Subject: [PATCH] fix: Inoperable dashboard filter slider when range is <= 1 (#27271) Co-authored-by: Justin Francos (cherry picked from commit ce9e4b4b776ba8071aab2ede538b51828250bb2b) --- .../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 0a866c094439..9e1d862ebefe 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 ( {Number.isNaN(Number(min)) || Number.isNaN(Number(max)) ? ( @@ -323,6 +333,7 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {