Skip to content

Commit

Permalink
Fixes onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Feb 7, 2023
1 parent 882439b commit 9db99fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
25 changes: 9 additions & 16 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
getSuffixIcon,
SELECT_ALL_VALUE,
selectAllOption,
mapValues,
mapOptions,
} from './utils';
import { SelectOptionsType, SelectProps } from './types';
import {
Expand Down Expand Up @@ -415,20 +417,8 @@ const Select = forwardRef(
) {
// send all options to onchange if all are not currently there
if (!selectAllMode) {
newValues = labelInValue
? selectAllEligible.map(opt => ({
key: opt.value,
value: opt.value,
label: opt.label,
}))
: selectAllEligible.map(opt => opt.value);
newOptions = fullSelectOptions.map(opt => ({
children: opt.label,
key: opt.value,
value: opt.value,
label: opt.label,
disabled: opt.disabled,
}));
newValues = mapValues(selectAllEligible, labelInValue);
newOptions = mapOptions(selectAllEligible);
} else {
newValues = ensureIsArray(values).filter(
(val: any) => getValue(val) !== SELECT_ALL_VALUE,
Expand All @@ -438,8 +428,11 @@ const Select = forwardRef(
ensureIsArray(values).length === selectAllEligible.length &&
selectAllMode
) {
newValues = [];
newValues = [];
const array = selectAllEligible.filter(
option => hasOption(option.value, selectValue) && option.disabled,
);
newValues = mapValues(array, labelInValue);
newOptions = mapOptions(array);
}
}
onChange?.(newValues, newOptions);
Expand Down
18 changes: 18 additions & 0 deletions superset-frontend/src/components/Select/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,21 @@ export const renderSelectOptions = (options: SelectOptionsType) =>
</Option>
);
});

export const mapValues = (values: SelectOptionsType, labelInValue: boolean) =>
labelInValue
? values.map(opt => ({
key: opt.value,
value: opt.value,
label: opt.label,
}))
: values.map(opt => opt.value);

export const mapOptions = (values: SelectOptionsType) =>
values.map(opt => ({
children: opt.label,
key: opt.value,
value: opt.value,
label: opt.label,
disabled: opt.disabled,
}));

0 comments on commit 9db99fc

Please sign in to comment.