You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/01/23 15:25:46 UTC
[superset] branch master updated: fix: Unexpected error on simple filter (#22814)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new d479009e35 fix: Unexpected error on simple filter (#22814)
d479009e35 is described below
commit d479009e35a86dfda321492afeda2a1683a9345a
Author: Michael S. Molina <70...@users.noreply.github.com>
AuthorDate: Mon Jan 23 10:25:28 2023 -0500
fix: Unexpected error on simple filter (#22814)
---
.../src/components/Select/Select.test.tsx | 13 ++++++---
superset-frontend/src/components/Select/Select.tsx | 31 ++++++++++++++++------
2 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/superset-frontend/src/components/Select/Select.test.tsx b/superset-frontend/src/components/Select/Select.test.tsx
index 52f834d7cd..220ad4fe98 100644
--- a/superset-frontend/src/components/Select/Select.test.tsx
+++ b/superset-frontend/src/components/Select/Select.test.tsx
@@ -808,14 +808,21 @@ test('"Select All" is checked when unchecking a newly added option and all the o
});
test('does not render "Select All" when there are 0 or 1 options', async () => {
- render(
+ const { rerender } = render(
<Select {...defaultProps} options={[]} mode="multiple" allowNewOptions />,
);
await open();
expect(screen.queryByText(selectAllOptionLabel(0))).not.toBeInTheDocument();
- await type(`${NEW_OPTION}{enter}`);
+ rerender(
+ <Select
+ {...defaultProps}
+ options={OPTIONS.slice(0, 1)}
+ mode="multiple"
+ allowNewOptions
+ />,
+ );
expect(screen.queryByText(selectAllOptionLabel(1))).not.toBeInTheDocument();
- await type(`Kyle2{enter}`);
+ await type(`${NEW_OPTION}{enter}`);
expect(screen.queryByText(selectAllOptionLabel(2))).toBeInTheDocument();
});
diff --git a/superset-frontend/src/components/Select/Select.tsx b/superset-frontend/src/components/Select/Select.tsx
index ac119423c8..68bc608719 100644
--- a/superset-frontend/src/components/Select/Select.tsx
+++ b/superset-frontend/src/components/Select/Select.tsx
@@ -178,8 +178,17 @@ const Select = forwardRef(
}, [selectOptions, selectValue]);
const selectAllEnabled = useMemo(
- () => !isSingleMode && fullSelectOptions.length > 1 && !inputValue,
- [fullSelectOptions, isSingleMode, inputValue],
+ () =>
+ !isSingleMode &&
+ selectOptions.length > 0 &&
+ fullSelectOptions.length > 1 &&
+ !inputValue,
+ [
+ isSingleMode,
+ selectOptions.length,
+ fullSelectOptions.length,
+ inputValue,
+ ],
);
const selectAllMode = useMemo(
@@ -329,7 +338,7 @@ const Select = forwardRef(
if (
!isSingleMode &&
ensureIsArray(value).length === fullSelectOptions.length &&
- fullSelectOptions.length > 0
+ selectOptions.length > 0
) {
setSelectValue(
labelInValue
@@ -340,18 +349,24 @@ const Select = forwardRef(
] as AntdLabeledValue[]),
);
}
- }, [value, isSingleMode, labelInValue, fullSelectOptions.length]);
+ }, [
+ value,
+ isSingleMode,
+ labelInValue,
+ fullSelectOptions.length,
+ selectOptions.length,
+ ]);
useEffect(() => {
const checkSelectAll = ensureIsArray(selectValue).some(
v => getValue(v) === SELECT_ALL_VALUE,
);
if (checkSelectAll && !selectAllMode) {
- setSelectValue(
- labelInValue
- ? ([...fullSelectOptions, selectAllOption] as AntdLabeledValue[])
- : ([...fullSelectOptions, SELECT_ALL_VALUE] as AntdLabeledValue[]),
+ const optionsToSelect = fullSelectOptions.map(option =>
+ labelInValue ? option : option.value,
);
+ optionsToSelect.push(labelInValue ? selectAllOption : SELECT_ALL_VALUE);
+ setSelectValue(optionsToSelect);
}
}, [selectValue, selectAllMode, labelInValue, fullSelectOptions]);