diff --git a/src/frontend/src/components/dropdownComponent/index.tsx b/src/frontend/src/components/dropdownComponent/index.tsx index b9991e274..f930d18d1 100644 --- a/src/frontend/src/components/dropdownComponent/index.tsx +++ b/src/frontend/src/components/dropdownComponent/index.tsx @@ -5,6 +5,7 @@ import { ChangeEvent, useEffect, useRef, useState } from "react"; import { DropDownComponentType } from "../../types/components"; import { cn } from "../../utils/utils"; import { default as ForwardedIconComponent } from "../genericIconComponent"; +import ShadTooltip from "../shadTooltipComponent"; import { Button } from "../ui/button"; import { Command, @@ -47,15 +48,21 @@ export default function Dropdown({ const value = event.target.value; const searchValues = fuse.search(value); const filtered = searchValues.map((search) => search.item); - if (!filtered.includes(value) && combobox) filtered.push(value); + if (!filtered.includes(value) && combobox && value) filtered.push(value); setFilteredOptions(value ? filtered : options); setCustomValue(value); }; + useEffect(() => { + if (disabled && value !== "") { + onSelect("", undefined, true); + } + }, [disabled]); + useEffect(() => { if (open) { const filtered = cloneDeep(options); - if (customValue === value && combobox) { + if (customValue === value && value && combobox) { filtered.push(customValue); } setFilteredOptions(filtered); @@ -64,7 +71,7 @@ export default function Dropdown({ return ( <> - {Object.keys(options ?? [])?.length > 0 ? ( + {Object.keys(options ?? [])?.length > 0 || combobox ? ( <> {} : setOpen}> {children ? ( @@ -131,32 +138,40 @@ export default function Dropdown({ No values found. {filteredOptions?.map((option, id) => ( - { - onSelect(currentValue); - setOpen(false); - }} - className="items-center truncate" - data-testid={`${option}-${id ?? ""}-option`} + content={option} > - {customValue === option ? ( - - Text:  - - ) : ( - <> - )} - {option} - - +
+ { + onSelect(currentValue); + setOpen(false); + }} + className="items-center overflow-hidden truncate" + data-testid={`${option}-${id ?? ""}-option`} + > + {customValue === option ? ( + + Text:  + + ) : ( + <> + )} + {option} + + +
+ ))}
diff --git a/src/frontend/src/components/inputListComponent/index.tsx b/src/frontend/src/components/inputListComponent/index.tsx index e089bb865..ddf75c1c1 100644 --- a/src/frontend/src/components/inputListComponent/index.tsx +++ b/src/frontend/src/components/inputListComponent/index.tsx @@ -18,7 +18,7 @@ export default function InputListComponent({ }: InputListComponentType): JSX.Element { useEffect(() => { if (disabled && value.length > 0 && value[0] !== "") { - onChange([""]); + onChange([""], undefined, true); } }, [disabled]); diff --git a/src/frontend/src/components/multiselectComponent/index.tsx b/src/frontend/src/components/multiselectComponent/index.tsx index ba8e825d9..d432d6a24 100644 --- a/src/frontend/src/components/multiselectComponent/index.tsx +++ b/src/frontend/src/components/multiselectComponent/index.tsx @@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from "react"; import { MultiselectComponentType } from "../../types/components"; import { cn } from "../../utils/utils"; import { default as ForwardedIconComponent } from "../genericIconComponent"; +import ShadTooltip from "../shadTooltipComponent"; import { Button } from "../ui/button"; import { Command, @@ -51,7 +52,7 @@ export default function MultiselectComponent({ const fuse = onlySelected ? fuseValues : fuseOptions; const searchValues = fuse.search(v); let filtered: string[] = searchValues.map((search) => search.item); - if (!filtered.includes(v) && combobox) filtered = [v, ...filtered]; + if (!filtered.includes(v) && combobox && v) filtered = [v, ...filtered]; setFilteredOptions( v ? filtered @@ -61,6 +62,12 @@ export default function MultiselectComponent({ ); }; + useEffect(() => { + if (disabled && value.length > 0 && value[0] !== "") { + onSelect([], undefined, true); + } + }, [disabled]); + useEffect(() => { searchRoleByTerm(searchValue); }, [onlySelected]); @@ -72,7 +79,7 @@ export default function MultiselectComponent({ useEffect(() => { setCustomValues(value.filter((v) => !defaultOptions.includes(v)) ?? []); setOptions([ - ...value.filter((v) => !defaultOptions.includes(v)), + ...value.filter((v) => !defaultOptions.includes(v) && v), ...defaultOptions, ]); }, [value]); @@ -87,7 +94,7 @@ export default function MultiselectComponent({ return ( <> - {Object.keys(options ?? [])?.length > 0 ? ( + {Object.keys(options ?? [])?.length > 0 || combobox ? ( <> {} : setOpen}> {children ? ( @@ -171,38 +178,48 @@ export default function MultiselectComponent({ No values found. {filteredOptions?.map((option, id) => ( - { - if (value.includes(currentValue)) { - onSelect(value.filter((v) => v !== currentValue)); - } else { - onSelect([...value, currentValue]); - } - }} - className="items-center truncate" - data-testid={`${option}-${id ?? ""}-option`} + content={option} > - {customValues.includes(option) || - searchValue === option ? ( - - Text:  - - ) : ( - <> - )} - {option} - - +
+ { + if (value.includes(currentValue)) { + onSelect( + value.filter((v) => v !== currentValue), + ); + } else { + onSelect([...value, currentValue]); + } + }} + className="items-center overflow-hidden truncate" + data-testid={`${option}-${id ?? ""}-option`} + > + {customValues.includes(option) || + searchValue === option ? ( + + Text:  + + ) : ( + <> + )} + {option} + + +
+ ))}
diff --git a/src/frontend/src/contexts/index.tsx b/src/frontend/src/contexts/index.tsx index 95d9d761a..5405d2dac 100644 --- a/src/frontend/src/contexts/index.tsx +++ b/src/frontend/src/contexts/index.tsx @@ -14,7 +14,7 @@ export default function ContextWrapper({ children }: { children: ReactNode }) { - + {children} diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index 7840c5fa3..02da4d336 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -56,7 +56,7 @@ export type DropDownComponentType = { value: string; combobox?: boolean; options: string[]; - onSelect: (value: string) => void; + onSelect: (value: string, dbValue?: boolean, snapshot?: boolean) => void; editNode?: boolean; id?: string; children?: ReactNode; @@ -67,7 +67,7 @@ export type MultiselectComponentType = { value: string[]; combobox?: boolean; options: string[]; - onSelect: (value: string[]) => void; + onSelect: (value: string[], dbValue?: boolean, snapshot?: boolean) => void; editNode?: boolean; id?: string; children?: ReactNode; @@ -96,7 +96,7 @@ export type ParameterComponentType = { }; export type InputListComponentType = { value: string[]; - onChange: (value: string[]) => void; + onChange: (value: string[], dbValue?: boolean, snapshot?: boolean) => void; disabled: boolean; editNode?: boolean; componentName?: string;