From 856a2bd5ed63f905da99ab19295ce515e2bc293d Mon Sep 17 00:00:00 2001 From: Yaozong Liu <750188453@qq.com> Date: Sun, 13 Jun 2021 11:24:39 +0800 Subject: [PATCH] fix(explore): fix y-axis lower bound 0 value (#15091) --- .../explore/components/BoundsControl_spec.jsx | 9 +++++++++ .../src/explore/components/controls/BoundsControl.jsx | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx b/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx index 2e25d130f0..53e1cdc0f2 100644 --- a/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/BoundsControl_spec.jsx @@ -51,3 +51,12 @@ test('calls onChange with correct values', async () => { expect(defaultProps.onChange).toHaveBeenLastCalledWith([1, 2]), ); }); + +test('receives 0 value', async () => { + render(); + const minInput = screen.getAllByRole('spinbutton')[0]; + userEvent.type(minInput, '0'); + await waitFor(() => + expect(defaultProps.onChange).toHaveBeenLastCalledWith([0, null]), + ); +}); diff --git a/superset-frontend/src/explore/components/controls/BoundsControl.jsx b/superset-frontend/src/explore/components/controls/BoundsControl.jsx index ff22cebf3b..39a0d560bc 100644 --- a/superset-frontend/src/explore/components/controls/BoundsControl.jsx +++ b/superset-frontend/src/explore/components/controls/BoundsControl.jsx @@ -97,8 +97,8 @@ export default class BoundsControl extends React.Component { onChange() { const mm = this.state.minMax; - const min = parseFloat(mm[0]) || null; - const max = parseFloat(mm[1]) || null; + const min = Number.isNaN(parseFloat(mm[0])) ? null : parseFloat(mm[0]); + const max = Number.isNaN(parseFloat(mm[1])) ? null : parseFloat(mm[1]); this.props.onChange([min, max]); }