Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filter values are not updating when dependencies are set #23566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Select = forwardRef(
{
allowClear,
allowNewOptions = false,
allowSelectAll = true,
ariaLabel,
filterOption = true,
header = null,
Expand Down Expand Up @@ -195,10 +196,17 @@ const Select = forwardRef(
const selectAllEnabled = useMemo(
() =>
!isSingleMode &&
allowSelectAll &&
selectOptions.length > 0 &&
enabledOptions.length > 1 &&
!inputValue,
[isSingleMode, selectOptions.length, enabledOptions.length, inputValue],
[
isSingleMode,
allowSelectAll,
selectOptions.length,
enabledOptions.length,
inputValue,
],
);

const selectAllMode = useMemo(
Expand Down Expand Up @@ -360,9 +368,8 @@ const Select = forwardRef(
useEffect(() => {
// if all values are selected, add select all to value
if (
!isSingleMode &&
ensureIsArray(value).length === selectAllEligible.length &&
selectOptions.length > 0
selectAllEnabled &&
ensureIsArray(value).length === selectAllEligible.length
) {
setSelectValue(
labelInValue
Expand All @@ -373,13 +380,7 @@ const Select = forwardRef(
] as AntdLabeledValue[]),
);
}
}, [
value,
isSingleMode,
labelInValue,
selectAllEligible.length,
selectOptions.length,
]);
}, [labelInValue, selectAllEligible.length, selectAllEnabled, value]);

useEffect(() => {
const checkSelectAll = ensureIsArray(selectValue).some(
Expand Down
5 changes: 5 additions & 0 deletions superset-frontend/src/components/Select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export interface BaseSelectProps extends AntdExposedProps {
}

export interface SelectProps extends BaseSelectProps {
/**
* It enables the user to select all options.
* True by default.
* */
allowSelectAll?: boolean;
/**
* It defines the options of the Select.
* The options can be static, an array of options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ const FiltersConfigForm = (
const formFilter = formValues || undoFormValues || defaultFormFilter;

const dependencies: string[] =
formFilter?.dependencies || filterToEdit?.cascadeParentIds;
formFilter?.dependencies || filterToEdit?.cascadeParentIds || [];

const nativeFilterItems = getChartMetadataRegistry().items;
const nativeFilterVizTypes = Object.entries(nativeFilterItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
}),
[],
);
const [initialData, setInitialData] = useState<typeof data>([]);

const updateDataMask = useCallback(
(values: SelectValue) => {
Expand Down Expand Up @@ -238,7 +237,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
}, [filterState.validateMessage, filterState.validateStatus]);

const options = useMemo(() => {
const allOptions = [...data, ...initialData];
const allOptions = [...data];
const uniqueOptions = uniqWith(allOptions, isEqual);
const selectOptions: { label: string; value: DataRecordValue }[] = [];
uniqueOptions.forEach(row => {
Expand All @@ -249,7 +248,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
});
});
return selectOptions;
}, [data, initialData, datatype, groupby, labelFormatter]);
}, [data, datatype, groupby, labelFormatter]);

const sortComparator = useCallback(
(a: AntdLabeledValue, b: AntdLabeledValue) => {
Expand Down Expand Up @@ -296,12 +295,6 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
setDataMask(dataMask);
}, [JSON.stringify(dataMask)]);

useEffect(() => {
if (data.length && !initialData.length) {
setInitialData(data);
}
}, [data, initialData.length]);

return (
<FilterPluginStyle height={height} width={width}>
<StyledFormItem
Expand All @@ -311,6 +304,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
<Select
allowClear
allowNewOptions
allowSelectAll={!searchAllOptions}
// @ts-ignore
value={filterState.value || []}
disabled={isDisabled}
Expand Down