Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [filter_box] fix 2 issues in single value filter_box #9829

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented May 18, 2020

SUMMARY

This PR is to fix 2 issues in single value filter_box.

BEFORE

  1. Issue 1: Clear filter_box won't clear filter's default value
    gGtwLBI2qw

  2. Issue 2: Set default value for a single value filter_box, the column's data type is FLOAT:

Screen Shot 2020-05-17 at 6 48 57 PM

In dashboard, this string value doesn't match with filter's data type, so that it looks the same option show twice:

Screen Shot 2020-05-17 at 6 50 46 PM

Proposed solution:

  1. Issue 1: When user clear filter_box, the option value should be null. While when filter_box value is undefined, should use defaultValue.
  2. Issue 2: When user update defaultValue for filter_box, add type cast for numeric and boolean type column.

TEST PLAN

CI and manual test.

@mistercrunch @ktmud @etr2460

@codecov-io
Copy link

codecov-io commented May 18, 2020

Codecov Report

Merging #9829 into master will increase coverage by 4.84%.
The diff coverage is 73.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9829      +/-   ##
==========================================
+ Coverage   66.16%   71.01%   +4.84%     
==========================================
  Files         585      583       -2     
  Lines       30427    30634     +207     
  Branches     3152     3165      +13     
==========================================
+ Hits        20133    21755    +1622     
+ Misses      10113     8766    -1347     
+ Partials      181      113      -68     
Flag Coverage Δ
#cypress 53.55% <26.66%> (?)
#javascript 59.31% <66.66%> (+0.05%) ⬆️
#python 71.27% <ø> (+0.24%) ⬆️
Impacted Files Coverage Δ
...rontend/src/visualizations/FilterBox/FilterBox.jsx 74.16% <33.33%> (+69.08%) ⬆️
...plore/components/controls/FilterBoxItemControl.jsx 75.47% <78.94%> (+10.60%) ⬆️
...src/dashboard/util/getFilterConfigsFromFormdata.js 89.28% <100.00%> (+0.82%) ⬆️
superset-frontend/src/explore/constants.js 100.00% <100.00%> (ø)
superset/errors.py 100.00% <0.00%> (ø)
superset/viz_sip38.py 0.00% <0.00%> (ø)
superset/exceptions.py 100.00% <0.00%> (ø)
...rset-frontend/src/components/ListView/ListView.tsx 98.07% <0.00%> (ø)
...frontend/src/components/ListView/LegacyFilters.tsx 75.00% <0.00%> (ø)
...src/SqlLab/components/ExploreCtasResultsButton.jsx 13.33% <0.00%> (ø)
... and 178 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea9b7f2...183f980. Read the comment docs.

datasource.columns.filter(
col => col.column_name === selectedColumnName,
) || []
).pop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectedColumn = datasource.columns.find(x => x.column_name === selectedColumnName);

@@ -27,6 +27,9 @@ import SelectControl from './SelectControl';
import CheckboxControl from './CheckboxControl';
import TextControl from './TextControl';

const INTEGRAL_TYPES = ['TINYINT', 'SMALLINT', 'INT', 'INTEGER', 'BIGINT'];
const DECIMAL_TYPES = ['FLOAT', 'DOUBLE'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Set? It's faster than arrays.

const DECIMAL_TYPES = new Set(['FLOAT', 'DOUBLE'])

DECIMAL_TYPES.has(columnType)

Not sure what types are returned to the frontend, but are we sure these types are exhaustive: https://github.com/apache/incubator-superset/blob/a6cedaaa879348aca49a520793bb20e63d152a1f/superset/connectors/base/models.py#L480-L493

Might want to add LONG to INTEGRAL_TYPES; and NUMERIC, NUMBER, REAL and DECIMAL to DECIMAL_TYPES, too?

@ktmud
Copy link
Member

ktmud commented May 18, 2020

LGTM, just a couple of style nits.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm as well after addressing Jesse's comment and mine about the try/catch

this.setState({ [attr]: value }, this.onChange);
let typedValue = value;
const { column: selectedColumnName, multiple } = this.state;
if (value && !multiple && attr === 'defaultValue') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should defaultValue be a string constant somewhere that's used here and in the filter config?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 2 constants, defaultValue and multiple (used by this feature). but there are quite a few other attributes used in many places...

} else if (DECIMAL_TYPES.includes(type)) {
typedValue = parseFloat(value);
}
} catch (ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@graceguo-supercat graceguo-supercat force-pushed the gg-FilterBoxDefaultValueDataType branch 2 times, most recently from fbc4fcb to c8afb83 Compare May 18, 2020 22:36
@pull-request-size pull-request-size bot added size/L and removed size/M labels May 18, 2020
@graceguo-supercat graceguo-supercat force-pushed the gg-FilterBoxDefaultValueDataType branch from c8afb83 to 183f980 Compare May 18, 2020 22:51
@graceguo-supercat graceguo-supercat merged commit d96bb87 into apache:master May 19, 2020
@graceguo-supercat graceguo-supercat deleted the gg-FilterBoxDefaultValueDataType branch June 11, 2020 23:17
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
* fix: [filter_box] fix 2 issues in single value filter_box

* add unit test

* add fix per comments
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants