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

Commit

Permalink
fix: Filter values are not updating when dependencies are set (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Apr 3, 2023
1 parent cdc7af1 commit 3bc4960
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
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

0 comments on commit 3bc4960

Please sign in to comment.