-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -385,31 +385,37 @@ const Select = ( | |||||
|
||||||
const hasCustomLabels = fullSelectOptions.some(opt => !!opt?.customLabel); | ||||||
|
||||||
const valueAsArray = <T,>(value: any): T[] => { | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this local |
||||||
) => { | ||||||
if (isSingleMode) { | ||||||
setSelectValue(selectedValue); | ||||||
} else if ( | ||||||
typeof selectedValue === 'number' || | ||||||
typeof selectedValue === 'string' | ||||||
) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe these two if/else can be rewritten with |
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return [...primitiveArray, selectedValue as string | number]; | ||||||
} | ||||||
return previousState; | ||||||
}); | ||||||
} else { | ||||||
const currentSelected = selectValue | ||||||
? Array.isArray(selectValue) | ||||||
? selectValue | ||||||
: [selectValue] | ||||||
: []; | ||||||
if ( | ||||||
typeof selectedValue === 'number' || | ||||||
typeof selectedValue === 'string' | ||||||
) { | ||||||
setSelectValue([ | ||||||
...(currentSelected as (string | number)[]), | ||||||
selectedValue as string | number, | ||||||
]); | ||||||
} else { | ||||||
setSelectValue([ | ||||||
...(currentSelected as AntdLabeledValue[]), | ||||||
selectedValue as AntdLabeledValue, | ||||||
]); | ||||||
} | ||||||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 🙈 Lack of coffee |
||||||
return [...objectArray, selectedValue as AntdLabeledValue]; | ||||||
} | ||||||
return previousState; | ||||||
}); | ||||||
} | ||||||
setInputValue(''); | ||||||
}; | ||||||
|
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