diff --git a/superset-frontend/src/components/Select/Select.test.tsx b/superset-frontend/src/components/Select/Select.test.tsx index 52f834d7cda0d..220ad4fe9875c 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( , + ); 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 70ca4e6903342..f32ac797b5953 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]);