You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2021/11/22 19:41:00 UTC
[superset] 02/12: fix: Verify when null value should be undefined in Select (#17013)
This is an automated email from the ASF dual-hosted git repository.
elizabeth pushed a commit to branch 1.4
in repository https://gitbox.apache.org/repos/asf/superset.git
commit b775193f9f154fe74ac8ea3e5fc17b8b0c7efdd8
Author: Geido <60...@users.noreply.github.com>
AuthorDate: Fri Oct 8 17:32:09 2021 +0300
fix: Verify when null value should be undefined in Select (#17013)
* Check for null value
* Safety chek SelectControl and SelectAsyncControl
---
.../components/controls/SelectAsyncControl/index.tsx | 13 ++++++++++++-
.../src/explore/components/controls/SelectControl.jsx | 19 ++++++++++++++++---
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx b/superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx
index 85230f7..ae65843 100644
--- a/superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx
+++ b/superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx
@@ -71,6 +71,17 @@ const SelectAsyncControl = ({
onChange(onChangeVal);
};
+ const getValue = () => {
+ const currentValue =
+ value || (props.default !== undefined ? props.default : undefined);
+
+ // safety check - the value is intended to be undefined but null was used
+ if (currentValue === null && !options.find(o => o.value === null)) {
+ return undefined;
+ }
+ return currentValue;
+ };
+
useEffect(() => {
const onError = (response: Response) =>
getClientErrorObject(response).then(e => {
@@ -93,7 +104,7 @@ const SelectAsyncControl = ({
<Select
allowClear={allowClear}
ariaLabel={ariaLabel || t('Select ...')}
- value={value || (props.default !== undefined ? props.default : undefined)}
+ value={getValue()}
header={<ControlHeader {...props} />}
mode={multi ? 'multiple' : 'single'}
onChange={handleOnChange}
diff --git a/superset-frontend/src/explore/components/controls/SelectControl.jsx b/superset-frontend/src/explore/components/controls/SelectControl.jsx
index 4342485..a8c5a0e 100644
--- a/superset-frontend/src/explore/components/controls/SelectControl.jsx
+++ b/superset-frontend/src/explore/components/controls/SelectControl.jsx
@@ -203,6 +203,21 @@ export default class SelectControl extends React.PureComponent {
danger,
};
+ const getValue = () => {
+ const currentValue =
+ value ||
+ (this.props.default !== undefined ? this.props.default : undefined);
+
+ // safety check - the value is intended to be undefined but null was used
+ if (
+ currentValue === null &&
+ !this.state.options.find(o => o.value === null)
+ ) {
+ return undefined;
+ }
+ return currentValue;
+ };
+
const selectProps = {
allowNewOptions: freeForm,
autoFocus,
@@ -223,9 +238,7 @@ export default class SelectControl extends React.PureComponent {
optionRenderer,
options: this.state.options,
placeholder,
- value:
- value ||
- (this.props.default !== undefined ? this.props.default : undefined),
+ value: getValue(),
};
return (