Skip to content

Commit

Permalink
fix: Removes unnecessary query on filters (#24814)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Jul 28, 2023
1 parent a50c43e commit 5bb8e0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 5bb8e0d

Please sign in to comment.