Skip to content

Commit

Permalink
Revert "fix: Duplicated numeric values in Select (apache#21480)"
Browse files Browse the repository at this point in the history
This reverts commit b739e27.
  • Loading branch information
mayurnewase committed Sep 21, 2022
1 parent 219048f commit 7b2c8c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
20 changes: 0 additions & 20 deletions superset-frontend/src/components/Select/AsyncSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ const findSelectOption = (text: string) =>
within(getElementByClassName('.rc-virtual-list')).getByText(text),
);

const querySelectOption = (text: string) =>
waitFor(() =>
within(getElementByClassName('.rc-virtual-list')).queryByText(text),
);

const findAllSelectOptions = () =>
waitFor(() => getElementsByClassName('.ant-select-item-option-content'));

Expand Down Expand Up @@ -741,21 +736,6 @@ test('renders a helper text when one is provided', async () => {
expect(screen.queryByText(helperText)).toBeInTheDocument();
});

test('finds an element with a numeric value and does not duplicate the options', async () => {
const options = jest.fn(async () => ({
data: [
{ label: 'a', value: 11 },
{ label: 'b', value: 12 },
],
totalCount: 2,
}));
render(<AsyncSelect {...defaultProps} options={options} allowNewOptions />);
await open();
await type('11');
expect(await findSelectOption('a')).toBeInTheDocument();
expect(await querySelectOption('11')).not.toBeInTheDocument();
});

/*
TODO: Add tests that require scroll interaction. Needs further investigation.
- Fetches more data when scrolling and more data is available
Expand Down
17 changes: 0 additions & 17 deletions superset-frontend/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ const findSelectOption = (text: string) =>
within(getElementByClassName('.rc-virtual-list')).getByText(text),
);

const querySelectOption = (text: string) =>
waitFor(() =>
within(getElementByClassName('.rc-virtual-list')).queryByText(text),
);

const findAllSelectOptions = () =>
waitFor(() => getElementsByClassName('.ant-select-item-option-content'));

Expand Down Expand Up @@ -554,18 +549,6 @@ test('renders a helper text when one is provided', async () => {
expect(screen.queryByText(helperText)).toBeInTheDocument();
});

test('finds an element with a numeric value and does not duplicate the options', async () => {
const options = [
{ label: 'a', value: 11 },
{ label: 'b', value: 12 },
];
render(<Select {...defaultProps} options={options} allowNewOptions />);
await open();
await type('11');
expect(await findSelectOption('a')).toBeInTheDocument();
expect(await querySelectOption('11')).not.toBeInTheDocument();
});

/*
TODO: Add tests that require scroll interaction. Needs further investigation.
- Fetches more data when scrolling and more data is available
Expand Down
16 changes: 5 additions & 11 deletions superset-frontend/src/components/Select/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,20 @@ export function getValue(
return isLabeledValue(option) ? option.value : option;
}

type V = string | number | null | undefined;
type LabeledValue<V> = { label?: ReactNode; value?: V };

type LabeledValue = { label?: ReactNode; value?: V };

export function hasOption(
export function hasOption<V>(
value: V,
options?: V | LabeledValue | (V | LabeledValue)[],
options?: V | LabeledValue<V> | (V | LabeledValue<V>)[],
checkLabel = false,
): boolean {
const optionsArray = ensureIsArray(options);
// When comparing the values we use the equality
// operator to automatically convert different types
return (
optionsArray.find(
x =>
// eslint-disable-next-line eqeqeq
x == value ||
x === value ||
(isObject(x) &&
// eslint-disable-next-line eqeqeq
(('value' in x && x.value == value) ||
(('value' in x && x.value === value) ||
(checkLabel && 'label' in x && x.label === value))),
) !== undefined
);
Expand Down

0 comments on commit 7b2c8c3

Please sign in to comment.