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: allow to select <NULL> in a native filter single mode #19076

Conversation

diegomedina248
Copy link
Contributor

@diegomedina248 diegomedina248 commented Mar 9, 2022

SUMMARY

The native filter used in the Dashboard filters values in single mode, which is a valid state.
The filter needs to be made only on undefined specifically.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Fix demo:

Screen.Recording.2022-03-09.at.11.07.53.mov

TESTING INSTRUCTIONS

  1. go to FCC survey dashboard
  2. create value filter for bootcamp name
  3. unselect ' Can select multiple values'
  4. Select <'NULL'> in the bootcamp name

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #19076 (93480f9) into master (8d53db1) will decrease coverage by 0.00%.
The diff coverage is 50.00%.

❗ Current head 93480f9 differs from pull request most recent head d796c65. Consider uploading reports for the commit d796c65 to get more accurate results

@@            Coverage Diff             @@
##           master   #19076      +/-   ##
==========================================
- Coverage   66.54%   66.54%   -0.01%     
==========================================
  Files        1646     1646              
  Lines       63630    63630              
  Branches     6475     6476       +1     
==========================================
- Hits        42343    42342       -1     
  Misses      19607    19607              
- Partials     1680     1681       +1     
Flag Coverage Δ
javascript 51.29% <50.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/filters/components/Select/SelectFilterPlugin.tsx 64.47% <0.00%> (-1.32%) ⬇️
...et-frontend/src/filters/components/Select/types.ts 100.00% <ø> (ø)
superset-frontend/src/components/Select/utils.ts 52.94% <100.00%> (ø)

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 8d53db1...d796c65. Read the comment docs.

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM!

@rusackas
Copy link
Member

rusackas commented Mar 9, 2022

@michael-s-molina @geido could one of you approve this as codeowners?

@michael-s-molina
Copy link
Member

@michael-s-molina @geido could one of you approve this as codeowners?

@rusackas Before approving this PR we need to discuss how are we going to deal with null values in the Select component. Right now, Select values don't accept a null value as you can see by checking Typescript constraints.

export function getValue(option: string | number | { value: string | number }) {
  - return typeof option === 'object' ? option.value : option;
  + return option && typeof option === 'object' ? option.value : option;
}

This change, for instance, shouldn't be valid because option can only be a string, number or object. The problem is that in FilterSelectPlugin we have:

<Select
   // @ts-ignore
   options={options}
>

I already talked to @geido about this we will schedule a meeting to discuss the best approach.

Copy link
Member

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

I think it's ok to allow option.value to be of arbitrary type, as long as there is a option.label string for display and search.

@@ -61,7 +61,7 @@ export function findValue<OptionType extends OptionTypeBase>(
}

export function getValue(option: string | number | { value: string | number }) {
return typeof option === 'object' ? option.value : option;
return option && typeof option === 'object' ? option.value : option;
Copy link
Member

Choose a reason for hiding this comment

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

If we are allowing option to be null then we need to update the signature of getValue as well (add | null).

@diegomedina248
Copy link
Contributor Author

@michael-s-molina @ktmud yeah, agreed.
Some other libraries store the selectedOptions instead of the value directly, so you will have: {value: null, label: 'x'} instead of plain null, which could lead to errors if treated like undefined

@michael-s-molina
Copy link
Member

@diegomedina248 We discussed null values and we're already supporting it in the Select, so you just need to apply the suggestions to getValue and we're good to go.

@@ -61,7 +61,7 @@ export function findValue<OptionType extends OptionTypeBase>(
}

export function getValue(option: string | number | { value: string | number }) {
return typeof option === 'object' ? option.value : option;
return option && typeof option === 'object' ? option.value : option;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return option && typeof option === 'object' ? option.value : option;
return typeof option === 'object' ? option.value : option;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typeof option === 'object' returns true when the value is null, that's why the change.
Repl.it: https://replit.com/@DiegoMedina6/BaggyGratefulAdware#index.js

Copy link
Member

@michael-s-molina michael-s-molina Mar 15, 2022

Choose a reason for hiding this comment

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

The option shouldn't be null because we need a label to describe the null value. The value of an object option is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The getValue is called with the selectValue in which we store the value itself, not the option (for multi select, an array of the values)

Copy link
Member

@michael-s-molina michael-s-molina Mar 15, 2022

Choose a reason for hiding this comment

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

@diegomedina248 Please disregard my previous message. To support Ant Design's different behavior depending on whether labelInValue is active, we need to also account for an option being null. You can keep your last commit where getValue(option: string | number | { value: string | number | null } | null)

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix @diegomedina248!

We currently have a broken frontend test related to timezone issues. People are already looking into it. As soon as they fix it you will need to rebase your PR.

@diegomedina248 diegomedina248 force-pushed the fix/native-filter-allow-to-select-null-in-single-mode branch from 8546d83 to 7a324df Compare March 15, 2022 16:20
@diegomedina248 diegomedina248 force-pushed the fix/native-filter-allow-to-select-null-in-single-mode branch from 7a324df to d796c65 Compare March 16, 2022 22:52
@michael-s-molina michael-s-molina merged commit 19fcd03 into apache:master Mar 17, 2022
@sadpandajoe
Copy link
Member

🏷️ preset:2022.11

sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Mar 18, 2022
)

* fix: allow to select <NULL> in a native filter single mode

* fix lint issue

* Update superset-frontend/src/components/Select/utils.ts

Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>

* fix

Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
(cherry picked from commit 19fcd03)
villebro pushed a commit that referenced this pull request Apr 3, 2022
* fix: allow to select <NULL> in a native filter single mode

* fix lint issue

* Update superset-frontend/src/components/Select/utils.ts

Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>

* fix

Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
(cherry picked from commit 19fcd03)
@mistercrunch mistercrunch added 🍒 1.5.2 🍒 1.5.3 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 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 lts-v1 preset:2022.11 size/M 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants