fix: Removes unnecessary query on filters (#24814)

This commit is contained in:
Michael S. Molina 2023-07-28 10:56:51 -03:00 committed by GitHub
parent a50c43e0fa
commit 5bb8e0da89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 40 deletions

View File

@ -235,34 +235,33 @@ describe('SelectFilterPlugin', () => {
});
});
test('Add ownState with column types when search all options', async () => {
test('receives the correct filter when search all options', async () => {
getWrapper({ searchAllOptions: true, multiSelect: false });
userEvent.click(screen.getByRole('combobox'));
expect(await screen.findByRole('combobox')).toBeInTheDocument();
userEvent.click(screen.getByTitle('girl'));
expect(setDataMask).toHaveBeenCalledWith({
__cache: {
value: ['boy'],
},
extraFormData: {
filters: [
{
col: 'gender',
op: 'IN',
val: ['girl'],
},
],
},
filterState: {
label: 'girl',
value: ['girl'],
},
ownState: {
coltypeMap: {
gender: 1,
expect(setDataMask).toHaveBeenLastCalledWith(
expect.objectContaining({
extraFormData: {
filters: [
{
col: 'gender',
op: 'IN',
val: ['girl'],
},
],
},
search: null,
},
});
}),
);
});
test('number of fired queries when searching', async () => {
getWrapper({ searchAllOptions: true });
userEvent.click(screen.getByRole('combobox'));
expect(await screen.findByRole('combobox')).toBeInTheDocument();
await userEvent.type(screen.getByRole('combobox'), 'a');
// Closes the select
userEvent.tab();
// One call for the search term and other for the empty search
expect(setDataMask).toHaveBeenCalledTimes(2);
});
});

View File

@ -185,23 +185,9 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
[dispatchDataMask, initialColtypeMap, searchAllOptions],
);
const clearSuggestionSearch = useCallback(() => {
setSearch('');
if (searchAllOptions) {
dispatchDataMask({
type: 'ownState',
ownState: {
coltypeMap: initialColtypeMap,
search: null,
},
});
}
}, [dispatchDataMask, initialColtypeMap, searchAllOptions]);
const handleBlur = useCallback(() => {
clearSuggestionSearch();
unsetFocusedFilter();
}, [clearSuggestionSearch, unsetFocusedFilter]);
}, [unsetFocusedFilter]);
const handleChange = useCallback(
(value?: SelectValue | number | string) => {
@ -323,7 +309,6 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
mode={multiSelect ? 'multiple' : 'single'}
placeholder={placeholderText}
onSearch={onSearch}
onSelect={clearSuggestionSearch}
onBlur={handleBlur}
onFocus={setFocusedFilter}
onMouseEnter={setHoveredFilter}