-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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: Don't allow duplicated tag values in the Select #19283
fix: Don't allow duplicated tag values in the Select #19283
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19283 +/- ##
=======================================
Coverage 66.57% 66.57%
=======================================
Files 1667 1667
Lines 64418 64429 +11
Branches 6503 6503
=======================================
+ Hits 42886 42896 +10
Misses 19849 19849
- Partials 1683 1684 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! Added a couple of comments.
const valueAsArray = <T,>(value: any): T[] => { | ||
const array = value ? (Array.isArray(value) ? value : [value]) : []; | ||
return array as T[]; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a ensureIsArray
function in @superset-ui/core
setSelectValue(previousState => { | ||
const primitiveArray = valueAsArray<string | number>(previousState); | ||
// Tokenized values can contain duplicated values | ||
if (!primitiveArray.some(value => value === selectedValue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!primitiveArray.some(value => value === selectedValue)) { | |
if (!primitiveArray.includes(selectedValue)) { |
setSelectValue(previousState => { | ||
const objectArray = valueAsArray<AntdLabeledValue>(previousState); | ||
// Tokenized values can contain duplicated values | ||
if (!objectArray.some(object => object.value === selectedValue.label)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we comparing value to labels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈 Lack of coffee
const array = value ? (Array.isArray(value) ? value : [value]) : []; | ||
return array as T[]; | ||
}; | ||
|
||
const handleOnSelect = ( | ||
selectedValue: string | number | AntdLabeledValue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this local selectedValue
to selectedItem
so not to confuse with selectValue
in the parent context which may also be an array?
} else if ( | ||
typeof selectedValue === 'number' || | ||
typeof selectedValue === 'string' | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these two if/else can be rewritten with hasOption
in Select/utils.
@ktmud I addressed all your comments. Thanks for the tips, they were valuable! I also added a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
expect(values[0]).toHaveTextContent('a'); | ||
expect(values[1]).toHaveTextContent('b'); | ||
expect(values[2]).toHaveTextContent('c'); | ||
expect(values[3]).toHaveTextContent('d'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* fix: Don't allow duplicated tag values in the Select * Addresses comments and adds test
* fix: Don't allow duplicated tag values in the Select * Addresses comments and adds test (cherry picked from commit d3ce398)
SUMMARY
This PR fixes two bugs in the Select component:
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Screen.Recording.2022-03-21.at.11.19.43.AM.mov
Screen.Recording.2022-03-21.at.11.16.48.AM.mov
TESTING INSTRUCTIONS
Check the videos for instructions.
ADDITIONAL INFORMATION