rusackas commented on code in PR #40984:
URL: https://github.com/apache/superset/pull/40984#discussion_r3523797314
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -315,23 +315,33 @@ export default function PluginFilterSelect(props:
PluginFilterSelectProps) {
const uniqueOptions = useMemo(() => {
const allOptions = new Set(data.map(el => el[col]));
- return [...allOptions].map((value: string) => ({
+ const baseOptions = [...allOptions].map((value: string) => ({
label: labelFormatter(value, datatype),
value,
isNewOption: false,
}));
- }, [data, datatype, col, labelFormatter]);
+ if (creatable !== false && filterState.value) {
+ const existing = new Set(allOptions);
+ ensureIsArray(filterState.value)
+ .filter(v => v !== null && v !== undefined && !existing.has(v))
+ .forEach(v => {
+ baseOptions.push({
+ label: String(v),
+ value: String(v),
+ isNewOption: true,
+ });
+ existing.add(v);
+ });
+ }
+ return baseOptions;
+ }, [data, datatype, col, labelFormatter, creatable, filterState.value]);
const options = useMemo(() => {
- if (search && !multiSelect && !hasOption(search, uniqueOptions, true)) {
- uniqueOptions.unshift({
- label: search,
- value: search,
- isNewOption: true,
- });
+ if (search && creatable !== false && !hasOption(search, uniqueOptions,
true)) {
+ return [{ label: search, value: search, isNewOption: true },
...uniqueOptions];
}
Review Comment:
The injection condition includes the `!searchAllOptions && creatable !==
false` guard now, matching the `allowNewOptions` prop on the Select.
##########
superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx:
##########
@@ -690,7 +690,9 @@ const Select = forwardRef(
}
} else {
const token = tokenSeparators.find(token =>
pastedText.includes(token));
- const array = token ? uniq(pastedText.split(token)) : [pastedText];
+ const array = token
+ ? uniq(pastedText.split(token).map(s => s.trim()).filter(Boolean))
+ : [pastedText.trim()].filter(Boolean);
Review Comment:
`AsyncSelect.tsx` got the same trim and empty-token filtering in the current
diff, with a matching test.
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -315,23 +315,40 @@ export default function PluginFilterSelect(props:
PluginFilterSelectProps) {
const uniqueOptions = useMemo(() => {
const allOptions = new Set(data.map(el => el[col]));
- return [...allOptions].map((value: string) => ({
+ const baseOptions = [...allOptions].map((value: string) => ({
label: labelFormatter(value, datatype),
value,
isNewOption: false,
}));
- }, [data, datatype, col, labelFormatter]);
+ if (creatable !== false && filterState.value) {
+ const existing = new Set(allOptions);
+ ensureIsArray(filterState.value)
+ .filter(v => v !== null && v !== undefined && !existing.has(v))
+ .forEach(v => {
+ baseOptions.push({
+ label: String(v),
+ value: String(v),
+ isNewOption: true,
+ });
Review Comment:
The pushed option keeps the raw value now and only stringifies the label, so
numeric defaults keep their type.
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.test.tsx:
##########
@@ -1659,6 +1659,61 @@ test('renders standard Select dropdown when operatorType
is Exact', () => {
expect(screen.getAllByRole('combobox').length).toBeGreaterThan(0);
});
+test('shows create option for multi-select creatable filter when typing',
async () => {
+ getWrapper({ creatable: true, multiSelect: true });
Review Comment:
Looks addressed... the `getWrapper` tests moved inside the describe block
and the standalone ones use `buildSelectFilterProps`, and lint-frontend is
green. Leaving this for you to close @sadpandajoe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]