mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix(native-filters): avoid double load on initialization (#15012)
This commit is contained in:
parent
1fc08523af
commit
d2a6e8cd20
@ -30,7 +30,7 @@ const selectMultipleProps = {
|
|||||||
enableEmptyFilter: true,
|
enableEmptyFilter: true,
|
||||||
defaultToFirstItem: false,
|
defaultToFirstItem: false,
|
||||||
inverseSelection: false,
|
inverseSelection: false,
|
||||||
searchAllOptions: true,
|
searchAllOptions: false,
|
||||||
datasource: '3__table',
|
datasource: '3__table',
|
||||||
groupby: ['gender'],
|
groupby: ['gender'],
|
||||||
adhocFilters: [],
|
adhocFilters: [],
|
||||||
@ -48,7 +48,7 @@ const selectMultipleProps = {
|
|||||||
},
|
},
|
||||||
height: 20,
|
height: 20,
|
||||||
hooks: {},
|
hooks: {},
|
||||||
ownState: { coltypeMap: { gender: 1 }, search: null },
|
ownState: {},
|
||||||
filterState: { value: ['boy'] },
|
filterState: { value: ['boy'] },
|
||||||
queriesData: [
|
queriesData: [
|
||||||
{
|
{
|
||||||
@ -92,11 +92,6 @@ describe('SelectFilterPlugin', () => {
|
|||||||
filterState: {
|
filterState: {
|
||||||
value: ['boy'],
|
value: ['boy'],
|
||||||
},
|
},
|
||||||
ownState: {
|
|
||||||
coltypeMap: {
|
|
||||||
gender: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
expect(setDataMask).toHaveBeenCalledWith({
|
expect(setDataMask).toHaveBeenCalledWith({
|
||||||
__cache: {
|
__cache: {
|
||||||
@ -115,11 +110,6 @@ describe('SelectFilterPlugin', () => {
|
|||||||
label: 'boy',
|
label: 'boy',
|
||||||
value: ['boy'],
|
value: ['boy'],
|
||||||
},
|
},
|
||||||
ownState: {
|
|
||||||
coltypeMap: {
|
|
||||||
gender: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
userEvent.click(screen.getByRole('combobox'));
|
userEvent.click(screen.getByRole('combobox'));
|
||||||
userEvent.click(screen.getByTitle('girl'));
|
userEvent.click(screen.getByTitle('girl'));
|
||||||
@ -140,12 +130,6 @@ describe('SelectFilterPlugin', () => {
|
|||||||
label: 'boy, girl',
|
label: 'boy, girl',
|
||||||
value: ['boy', 'girl'],
|
value: ['boy', 'girl'],
|
||||||
},
|
},
|
||||||
ownState: {
|
|
||||||
coltypeMap: {
|
|
||||||
gender: 1,
|
|
||||||
},
|
|
||||||
search: null,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -169,11 +153,6 @@ describe('SelectFilterPlugin', () => {
|
|||||||
label: '',
|
label: '',
|
||||||
value: null,
|
value: null,
|
||||||
},
|
},
|
||||||
ownState: {
|
|
||||||
coltypeMap: {
|
|
||||||
gender: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -189,11 +168,6 @@ describe('SelectFilterPlugin', () => {
|
|||||||
label: '',
|
label: '',
|
||||||
value: null,
|
value: null,
|
||||||
},
|
},
|
||||||
ownState: {
|
|
||||||
coltypeMap: {
|
|
||||||
gender: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -218,6 +192,27 @@ describe('SelectFilterPlugin', () => {
|
|||||||
label: 'girl (excluded)',
|
label: 'girl (excluded)',
|
||||||
value: ['girl'],
|
value: ['girl'],
|
||||||
},
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add ownState with column types when search all options', () => {
|
||||||
|
getWrapper({ searchAllOptions: true, multiSelect: false });
|
||||||
|
userEvent.click(screen.getByRole('combobox'));
|
||||||
|
userEvent.click(screen.getByTitle('girl'));
|
||||||
|
expect(setDataMask).toHaveBeenCalledWith({
|
||||||
|
extraFormData: {
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
col: 'gender',
|
||||||
|
op: 'IN',
|
||||||
|
val: ['girl'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
filterState: {
|
||||||
|
label: 'girl',
|
||||||
|
value: ['girl'],
|
||||||
|
},
|
||||||
ownState: {
|
ownState: {
|
||||||
coltypeMap: {
|
coltypeMap: {
|
||||||
gender: 1,
|
gender: 1,
|
||||||
|
@ -97,6 +97,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
|
|||||||
} = formData;
|
} = formData;
|
||||||
const groupby = ensureIsArray<string>(formData.groupby);
|
const groupby = ensureIsArray<string>(formData.groupby);
|
||||||
const [col] = groupby;
|
const [col] = groupby;
|
||||||
|
const [initialColtypeMap] = useState(coltypeMap);
|
||||||
const [selectedValues, setSelectedValues] = useState<SelectValue>(
|
const [selectedValues, setSelectedValues] = useState<SelectValue>(
|
||||||
filterState.value,
|
filterState.value,
|
||||||
);
|
);
|
||||||
@ -118,9 +119,6 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
|
|||||||
const [dataMask, dispatchDataMask] = useImmerReducer(reducer, {
|
const [dataMask, dispatchDataMask] = useImmerReducer(reducer, {
|
||||||
extraFormData: {},
|
extraFormData: {},
|
||||||
filterState,
|
filterState,
|
||||||
ownState: {
|
|
||||||
coltypeMap,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const updateDataMask = useCallback(
|
const updateDataMask = useCallback(
|
||||||
(values: SelectValue) => {
|
(values: SelectValue) => {
|
||||||
@ -174,6 +172,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
|
|||||||
dispatchDataMask({
|
dispatchDataMask({
|
||||||
type: 'ownState',
|
type: 'ownState',
|
||||||
ownState: {
|
ownState: {
|
||||||
|
coltypeMap: initialColtypeMap,
|
||||||
search: val,
|
search: val,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -194,6 +193,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
|
|||||||
dispatchDataMask({
|
dispatchDataMask({
|
||||||
type: 'ownState',
|
type: 'ownState',
|
||||||
ownState: {
|
ownState: {
|
||||||
|
coltypeMap: initialColtypeMap,
|
||||||
search: null,
|
search: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user