Skip to content

Commit

Permalink
Merge pull request #2343 from upalatucci/fix-object-select
Browse files Browse the repository at this point in the history
CNV-54110: Fix object select
  • Loading branch information
openshift-merge-bot[bot] authored Jan 7, 2025
2 parents 902bfc8 + 4d59bff commit 38416db
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/utils/components/SelectTypeahead/SelectTypeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,26 @@ const SelectTypeahead: FC<SelectTypeaheadProps> = ({
_event: React.MouseEvent<Element, MouseEvent> | undefined,
value: number | string | undefined,
) => {
if (value) {
if (value === CREATE_NEW) {
if (!initialOptions?.some((item) => item.children === filterValue)) {
setInitialOptions?.((prevFolders) => [
...(prevFolders || []),
{ children: filterValue, icon: <FolderIcon />, value: filterValue },
]);
}
setSelected(filterValue);
setFilterValue('');
closeMenu();
} else {
const optionText = selectOptions.find((option) => option.value === value)?.children;
selectOption(value, optionText as string);
if (!value) return;

if (value === CREATE_NEW) {
if (!initialOptions?.some((item) => item.children === filterValue)) {
setInitialOptions?.((prevFolders) => [
...(prevFolders || []),
{ children: filterValue, icon: <FolderIcon />, value: filterValue },
]);
}
setSelected(filterValue);
setFilterValue('');
closeMenu();
return;
}

const optionChildren = selectOptions.find((option) => option.value === value)?.children;

if (typeof optionChildren === 'object') return selectOption(value, value);

selectOption(value, optionChildren as string);
};

const onTextInputChange = (_event: React.FormEvent<HTMLInputElement>, value: string) => {
Expand Down

0 comments on commit 38416db

Please sign in to comment.