mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix: Preserves selected scopes when toggling between scope types (#23475)
This commit is contained in:
parent
439d687e1f
commit
80d1e4ffa3
@ -129,7 +129,7 @@ describe('FilterScope', () => {
|
|||||||
expect(screen.getByRole('tree')).toBeInTheDocument();
|
expect(screen.getByRole('tree')).toBeInTheDocument();
|
||||||
expect(
|
expect(
|
||||||
document.querySelectorAll('.ant-tree-checkbox-checked').length,
|
document.querySelectorAll('.ant-tree-checkbox-checked').length,
|
||||||
).toBe(1);
|
).toBe(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { FC, useCallback, useState } from 'react';
|
import React, { FC, useCallback, useRef, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
NativeFilterScope,
|
NativeFilterScope,
|
||||||
styled,
|
styled,
|
||||||
@ -67,6 +67,7 @@ const FilterScope: FC<FilterScopeProps> = ({
|
|||||||
const [initialFilterScope] = useState(
|
const [initialFilterScope] = useState(
|
||||||
filterScope || getDefaultScopeValue(chartId, initiallyExcludedCharts),
|
filterScope || getDefaultScopeValue(chartId, initiallyExcludedCharts),
|
||||||
);
|
);
|
||||||
|
const lastSpecificScope = useRef(initialFilterScope);
|
||||||
const [initialScopingType] = useState(
|
const [initialScopingType] = useState(
|
||||||
isScopingAll(initialFilterScope, chartId)
|
isScopingAll(initialFilterScope, chartId)
|
||||||
? ScopingType.all
|
? ScopingType.all
|
||||||
@ -78,10 +79,13 @@ const FilterScope: FC<FilterScopeProps> = ({
|
|||||||
|
|
||||||
const onUpdateFormValues = useCallback(
|
const onUpdateFormValues = useCallback(
|
||||||
(formValues: any) => {
|
(formValues: any) => {
|
||||||
|
if (formScopingType === ScopingType.specific) {
|
||||||
|
lastSpecificScope.current = formValues.scope;
|
||||||
|
}
|
||||||
updateFormValues(formValues);
|
updateFormValues(formValues);
|
||||||
setHasScopeBeenModified(true);
|
setHasScopeBeenModified(true);
|
||||||
},
|
},
|
||||||
[updateFormValues],
|
[formScopingType, updateFormValues],
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateScopes = useCallback(() => {
|
const updateScopes = useCallback(() => {
|
||||||
@ -113,12 +117,11 @@ const FilterScope: FC<FilterScopeProps> = ({
|
|||||||
>
|
>
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
onChange={({ target: { value } }) => {
|
onChange={({ target: { value } }) => {
|
||||||
if (value === ScopingType.all) {
|
const scope =
|
||||||
const scope = getDefaultScopeValue(chartId);
|
value === ScopingType.all
|
||||||
updateFormValues({
|
? getDefaultScopeValue(chartId)
|
||||||
scope,
|
: lastSpecificScope.current;
|
||||||
});
|
updateFormValues({ scope });
|
||||||
}
|
|
||||||
setHasScopeBeenModified(true);
|
setHasScopeBeenModified(true);
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user