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,15 +235,13 @@ 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 });
|
getWrapper({ searchAllOptions: true, multiSelect: false });
|
||||||
userEvent.click(screen.getByRole('combobox'));
|
userEvent.click(screen.getByRole('combobox'));
|
||||||
expect(await screen.findByRole('combobox')).toBeInTheDocument();
|
expect(await screen.findByRole('combobox')).toBeInTheDocument();
|
||||||
userEvent.click(screen.getByTitle('girl'));
|
userEvent.click(screen.getByTitle('girl'));
|
||||||
expect(setDataMask).toHaveBeenCalledWith({
|
expect(setDataMask).toHaveBeenLastCalledWith(
|
||||||
__cache: {
|
expect.objectContaining({
|
||||||
value: ['boy'],
|
|
||||||
},
|
|
||||||
extraFormData: {
|
extraFormData: {
|
||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
|
@ -253,16 +251,17 @@ describe('SelectFilterPlugin', () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
filterState: {
|
}),
|
||||||
label: 'girl',
|
);
|
||||||
value: ['girl'],
|
|
||||||
},
|
|
||||||
ownState: {
|
|
||||||
coltypeMap: {
|
|
||||||
gender: 1,
|
|
||||||
},
|
|
||||||
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],
|
[dispatchDataMask, initialColtypeMap, searchAllOptions],
|
||||||
);
|
);
|
||||||
|
|
||||||
const clearSuggestionSearch = useCallback(() => {
|
|
||||||
setSearch('');
|
|
||||||
if (searchAllOptions) {
|
|
||||||
dispatchDataMask({
|
|
||||||
type: 'ownState',
|
|
||||||
ownState: {
|
|
||||||
coltypeMap: initialColtypeMap,
|
|
||||||
search: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [dispatchDataMask, initialColtypeMap, searchAllOptions]);
|
|
||||||
|
|
||||||
const handleBlur = useCallback(() => {
|
const handleBlur = useCallback(() => {
|
||||||
clearSuggestionSearch();
|
|
||||||
unsetFocusedFilter();
|
unsetFocusedFilter();
|
||||||
}, [clearSuggestionSearch, unsetFocusedFilter]);
|
}, [unsetFocusedFilter]);
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
(value?: SelectValue | number | string) => {
|
(value?: SelectValue | number | string) => {
|
||||||
|
@ -323,7 +309,6 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
|
||||||
mode={multiSelect ? 'multiple' : 'single'}
|
mode={multiSelect ? 'multiple' : 'single'}
|
||||||
placeholder={placeholderText}
|
placeholder={placeholderText}
|
||||||
onSearch={onSearch}
|
onSearch={onSearch}
|
||||||
onSelect={clearSuggestionSearch}
|
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
onFocus={setFocusedFilter}
|
onFocus={setFocusedFilter}
|
||||||
onMouseEnter={setHoveredFilter}
|
onMouseEnter={setHoveredFilter}
|
||||||
|
|
Loading…
Reference in New Issue