mirror of https://github.com/apache/superset.git
fix: Removes unnecessary query on filters (#24814)
This commit is contained in:
parent
a50c43e0fa
commit
5bb8e0da89
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue