Skip to content

Commit

Permalink
fix: update Multiselect component to use 'values' prop instead of 'va…
Browse files Browse the repository at this point in the history
…lue' (#2640)
  • Loading branch information
ogabrielluiz authored Jul 11, 2024
1 parent 52db335 commit 7d75027
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/backend/base/langflow/inputs/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class MultiselectInput(BaseInputMixin, ListableInputMixin, DropDownMixin, Metada

field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
options: list[str] = Field(default_factory=list)
is_list: bool = Field(default=True, serialization_alias="list")


class FileInput(BaseInputMixin, ListableInputMixin, FileMixin, MetadataTraceMixin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export default function ParameterComponent({
condition={
left === true &&
type === "str" &&
!data.node?.template[name]?.list &&
(data.node?.template[name]?.options ||
data.node?.template[name]?.real_time_refresh)
}
Expand Down Expand Up @@ -570,7 +571,7 @@ export default function ParameterComponent({
<Multiselect
disabled={disabled}
options={data?.node?.template?.[name]?.options || []}
value={data?.node?.template?.[name]?.value || []}
values={data?.node?.template?.[name]?.value || []}
id={"multiselect-" + name}
onValueChange={handleOnNewValue}
/>
Expand Down
13 changes: 9 additions & 4 deletions src/frontend/src/components/multiselectComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ interface MultiselectProps<T>
asChild?: boolean;
className?: string;
editNode?: boolean;
value?: T[];
values?: T[];
}

export const Multiselect = forwardRef<
Expand All @@ -125,18 +125,23 @@ export const Multiselect = forwardRef<
asChild = false,
className,
editNode = false,
value,
values,
...props
},
ref,
) => {
// if elements in values are strings, create the multiselectValue object
// otherwise, use the values as is
const value = values?.map((v) =>
typeof v === "string" ? { label: v, value: v } : v,
);

const [selectedValues, setSelectedValues] = useState<MultiselectValue[]>(
value || [],
);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const combinedRef = useMergeRefs<HTMLButtonElement>(ref);

useEffect(() => {
if (!!value && value?.length > 0 && !isEqual(selectedValues, value)) {
setSelectedValues(value);
Expand Down Expand Up @@ -264,7 +269,7 @@ export const Multiselect = forwardRef<
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
{options?.map((option) => {
{value?.map((option) => {
const isSelected = !!selectedValues.find(
(sv) => sv.value === option.value,
);
Expand Down

0 comments on commit 7d75027

Please sign in to comment.