Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dropdown combobox option #2991

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backend/base/langflow/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"required",
"list",
"multiline",
"combobox",
"fileTypes",
"password",
"input_types",
Expand Down
5 changes: 5 additions & 0 deletions src/backend/base/langflow/inputs/input_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class MultilineMixin(BaseModel):
multiline: CoalesceBool = True


class ComboboxMixin(BaseModel):
combobox: CoalesceBool = False
"""Variable that defines if the user can insert custom values in the dropdown."""


class TableMixin(BaseModel):
table_schema: Optional[TableSchema | list[Column]] = None

Expand Down
4 changes: 3 additions & 1 deletion src/backend/base/langflow/inputs/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
BaseInputMixin,
DatabaseLoadMixin,
DropDownMixin,
ComboboxMixin,
FieldTypes,
FileMixin,
InputTraceMixin,
Expand Down Expand Up @@ -292,7 +293,7 @@ class DictInput(BaseInputMixin, ListableInputMixin, InputTraceMixin):
value: Optional[dict] = {}


class DropdownInput(BaseInputMixin, DropDownMixin, MetadataTraceMixin):
class DropdownInput(BaseInputMixin, DropDownMixin, MetadataTraceMixin, ComboboxMixin):
"""
Represents a dropdown input field.
Expand All @@ -307,6 +308,7 @@ class DropdownInput(BaseInputMixin, DropDownMixin, MetadataTraceMixin):

field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
options: list[str] = Field(default_factory=list)
combobox: CoalesceBool = False


class MultiselectInput(BaseInputMixin, ListableInputMixin, DropDownMixin, MetadataTraceMixin):
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/dropdownComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function Dropdown({
isLoading,
value,
options,
combobox = true,
combobox,
onSelect,
editNode = false,
id = "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleOnNewValueType } from "@/CustomNodes/hooks/use-handle-new-value";
import { InputFieldType } from "@/types/api";
import Dropdown from "../../../dropdownComponent";
import InputGlobalComponent from "../../../inputGlobalComponent";
import InputListComponent from "../../../inputListComponent";
Expand All @@ -12,6 +14,14 @@ export function StrRenderComponent({
handleOnNewValue,
editNode,
id,
}: {
templateData: Partial<InputFieldType>;
value: any;
name: string;
disabled: boolean;
handleOnNewValue: handleOnNewValueType;
editNode: boolean;
id: string;
}) {
const onChange = (value: any, dbValue?: boolean, skipSnapshot?: boolean) => {
handleOnNewValue({ value, load_from_db: dbValue }, { skipSnapshot });
Expand Down Expand Up @@ -65,6 +75,7 @@ export function StrRenderComponent({
editNode={editNode}
options={templateData.options}
onSelect={onChange}
combobox={templateData.combobox}
value={value ?? "Choose an option"}
id={`dropdown_${id}`}
/>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type InputFieldType = {
real_time_refresh?: boolean;
refresh_button?: boolean;
refresh_button_text?: string;
combobox?: boolean;
[key: string]: any;
};

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/types/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export type InputGlobalComponentType = {
disabled: boolean;
onChange: (value: string, dbValue: boolean, snapshot?: boolean) => void;
name: string;
data: InputFieldType;
data: Partial<InputFieldType>;
editNode?: boolean;
playgroundDisabled?: boolean;
};
Expand Down
Loading