From aa21b6514c002431be49e695d083d9764440babd Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Wed, 10 May 2017 12:05:23 -0700 Subject: [PATCH] fix auto select override pre-selected value bug auto select should only apply to cases where select control doesn't have pre-selected value prop. If select control has pre-selected value (passed in from value prop), auto select first avaliable options should not apply. --- .../assets/javascripts/components/AsyncSelect.jsx | 2 +- .../spec/javascripts/components/AsyncSelect_spec.jsx | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/superset/assets/javascripts/components/AsyncSelect.jsx b/superset/assets/javascripts/components/AsyncSelect.jsx index 409ec4cbc0636..e045dc973c987 100644 --- a/superset/assets/javascripts/components/AsyncSelect.jsx +++ b/superset/assets/javascripts/components/AsyncSelect.jsx @@ -41,7 +41,7 @@ class AsyncSelect extends React.PureComponent { $.get(this.props.dataEndpoint, (data) => { this.setState({ options: mutator ? mutator(data) : data, isLoading: false }); - if (this.props.autoSelect && this.state.options.length) { + if (!this.props.value && this.props.autoSelect && this.state.options.length) { this.onChange(this.state.options[0]); } }) diff --git a/superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx b/superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx index 5b498464b0c77..c08cc664197c9 100644 --- a/superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx +++ b/superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx @@ -66,5 +66,17 @@ describe('AsyncSelect', () => { expect(spy.callCount).to.equal(1); expect(spy.calledWith(wrapper.instance().state.options[0])).to.equal(true); }); + it('should not auto select when value prop is set', () => { + const wrapper = mount( + , + ); + const spy = sinon.spy(wrapper.instance(), 'onChange'); + + server.respond(); + + expect(spy.callCount).to.equal(0); + expect(wrapper.find(Select)).to.have.length(1); + expect(wrapper.find('.Select-value-label').children().first().text()).to.equal('another'); + }); }); });