etr2460 commented on a change in pull request #9829:
URL:
https://github.com/apache/incubator-superset/pull/9829#discussion_r426852348
##########
File path:
superset-frontend/src/explore/components/controls/FilterBoxItemControl.jsx
##########
@@ -60,7 +63,35 @@ export default class FilterBoxItemControl extends
React.Component {
this.props.onChange(this.state);
}
onControlChange(attr, value) {
- this.setState({ [attr]: value }, this.onChange);
+ let typedValue = value;
+ const { column: selectedColumnName, multiple } = this.state;
+ if (value && !multiple && attr === 'defaultValue') {
Review comment:
should `defaultValue` be a string constant somewhere that's used here
and in the filter config?
##########
File path:
superset-frontend/src/explore/components/controls/FilterBoxItemControl.jsx
##########
@@ -60,7 +63,35 @@ export default class FilterBoxItemControl extends
React.Component {
this.props.onChange(this.state);
}
onControlChange(attr, value) {
- this.setState({ [attr]: value }, this.onChange);
+ let typedValue = value;
+ const { column: selectedColumnName, multiple } = this.state;
+ if (value && !multiple && attr === 'defaultValue') {
+ // if single value filter_box,
+ // convert input value string to the column's data type
+ const { datasource } = this.props;
+ const selectedColumn = (
+ datasource.columns.filter(
+ col => col.column_name === selectedColumnName,
+ ) || []
+ ).pop();
+
+ if (selectedColumn && selectedColumn.type) {
+ const type = selectedColumn.type.toUpperCase();
+ try {
+ if (type === 'BOOLEAN') {
+ typedValue = value === 'true';
+ } else if (INTEGRAL_TYPES.includes(type)) {
+ typedValue = parseInt(value, 10);
+ } else if (DECIMAL_TYPES.includes(type)) {
+ typedValue = parseFloat(value);
+ }
+ } catch (ex) {
Review comment:
when does this fail? I don't think `parseInt` or `parseFloat` throw
errors with invalid input. instead they return `NaN`. I think we can remove the
try/catch block
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]