Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix: Preserves selected scopes when toggling between scope types (apa…
Browse files Browse the repository at this point in the history
…che#23475)

(cherry picked from commit 80d1e4f)
  • Loading branch information
michael-s-molina committed Apr 7, 2023
1 parent 5bd92a2 commit 9c87e44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('FilterScope', () => {
expect(screen.getByRole('tree')).toBeInTheDocument();
expect(
document.querySelectorAll('.ant-tree-checkbox-checked').length,
).toBe(1);
).toBe(4);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { FC, useCallback, useState } from 'react';
import React, { FC, useCallback, useRef, useState } from 'react';
import { NativeFilterScope, styled, t } from '@superset-ui/core';
import { Radio } from 'src/components/Radio';
import { AntdForm, Typography } from 'src/components';
Expand Down Expand Up @@ -63,6 +63,7 @@ const FilterScope: FC<FilterScopeProps> = ({
const [initialFilterScope] = useState(
filterScope || getDefaultScopeValue(chartId, initiallyExcludedCharts),
);
const lastSpecificScope = useRef(initialFilterScope);
const [initialScopingType] = useState(
isScopingAll(initialFilterScope, chartId)
? ScopingType.all
Expand All @@ -74,10 +75,13 @@ const FilterScope: FC<FilterScopeProps> = ({

const onUpdateFormValues = useCallback(
(formValues: any) => {
if (formScopingType === ScopingType.specific) {
lastSpecificScope.current = formValues.scope;
}
updateFormValues(formValues);
setHasScopeBeenModified(true);
},
[updateFormValues],
[formScopingType, updateFormValues],
);

const updateScopes = useCallback(() => {
Expand Down Expand Up @@ -109,12 +113,11 @@ const FilterScope: FC<FilterScopeProps> = ({
>
<Radio.Group
onChange={({ target: { value } }) => {
if (value === ScopingType.all) {
const scope = getDefaultScopeValue(chartId);
updateFormValues({
scope,
});
}
const scope =
value === ScopingType.all
? getDefaultScopeValue(chartId)
: lastSpecificScope.current;
updateFormValues({ scope });
setHasScopeBeenModified(true);
forceUpdate();
}}
Expand Down

0 comments on commit 9c87e44

Please sign in to comment.