diff --git a/superset-frontend/src/components/Select/Select.test.tsx b/superset-frontend/src/components/Select/Select.test.tsx
index 4701af236ceba..b247950abafb8 100644
--- a/superset-frontend/src/components/Select/Select.test.tsx
+++ b/superset-frontend/src/components/Select/Select.test.tsx
@@ -314,6 +314,17 @@ test('searches for custom fields', async () => {
expect(screen.getByText(NO_DATA)).toBeInTheDocument();
});
+test('removes duplicated values', async () => {
+ render();
+ await type('a,b,b,b,c,d,d');
+ const values = await findAllSelectValues();
+ expect(values.length).toBe(4);
+ expect(values[0]).toHaveTextContent('a');
+ expect(values[1]).toHaveTextContent('b');
+ expect(values[2]).toHaveTextContent('c');
+ expect(values[3]).toHaveTextContent('d');
+});
+
test('renders a custom label', async () => {
const options = [
{ label: 'John', value: 1, customLabel:
John
},
diff --git a/superset-frontend/src/components/Select/Select.tsx b/superset-frontend/src/components/Select/Select.tsx
index 92e0ec8b3379d..fde08fdf3d336 100644
--- a/superset-frontend/src/components/Select/Select.tsx
+++ b/superset-frontend/src/components/Select/Select.tsx
@@ -385,31 +385,23 @@ const Select = (
const hasCustomLabels = fullSelectOptions.some(opt => !!opt?.customLabel);
- const handleOnSelect = (
- selectedValue: string | number | AntdLabeledValue,
- ) => {
+ const handleOnSelect = (selectedItem: string | number | AntdLabeledValue) => {
if (isSingleMode) {
- setSelectValue(selectedValue);
+ setSelectValue(selectedItem);
} 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 array = ensureIsArray(previousState);
+ const isObject = typeof selectedItem === 'object';
+ const value = isObject ? selectedItem.value : selectedItem;
+ // Tokenized values can contain duplicated values
+ if (!hasOption(value, array)) {
+ const result = [...array, selectedItem];
+ return isObject
+ ? (result as AntdLabeledValue[])
+ : (result as (string | number)[]);
+ }
+ return previousState;
+ });
}
setInputValue('');
};