Skip to content

Commit

Permalink
feat: Add 'isToolMode' prop for enhanced tool mode support (langflow-…
Browse files Browse the repository at this point in the history
…ai#4483)

* fix: update getIconName function to support optional parameters and add tool mode handling

* Add 'isToolMode' prop to components for tool mode support

- Introduced 'isToolMode' prop across various components to enable tool mode functionality.
- Updated icon logic in textAreaComponent to use 'getIconName' with 'isToolMode'.
- Passed 'isToolMode' prop through parameterRenderComponent and related components.
- Adjusted inputGlobalComponent and NodeInputField to handle 'isToolMode' for conditional rendering.

---------

Co-authored-by: anovazzi1 <otavio2204@gmail.com>
  • Loading branch information
2 people authored and diogocabral committed Nov 26, 2024
1 parent ee1f0af commit cb316a1
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default function NodeInputField({
nodeClass={data.node!}
disabled={disabled}
placeholder={isToolMode ? DEFAULT_TOOLSET_PLACEHOLDER : undefined}
isToolMode={isToolMode}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const getIconName = (
disabled: boolean,
selectedOption: string,
optionsIcon: string,
nodeStyle: boolean,
disabled?: boolean,
selectedOption?: string,
optionsIcon?: string,
nodeStyle?: boolean,
isToolMode?: boolean,
) => {
if (isToolMode) return "Hammer";
if (disabled) return "lock";
if (selectedOption && nodeStyle) return "GlobeOkIcon";
return optionsIcon;
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/components/inputComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function InputComponent({
name,
onChangeFolderName,
nodeStyle,
isToolMode,
}: InputComponentType): JSX.Element {
const [pwdVisible, setPwdVisible] = useState(false);
const refInput = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -183,6 +184,7 @@ export default function InputComponent({
selectedOption!,
optionsIcon,
nodeStyle!,
isToolMode!,
)}
className={cn(
disabled ? "cursor-grab text-placeholder" : "cursor-pointer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function InputGlobalComponent({
password,
editNode = false,
placeholder,
isToolMode = false,
}: InputProps<string, InputGlobalComponentType>): JSX.Element {
const setErrorData = useAlertStore((state) => state.setErrorData);

Expand Down Expand Up @@ -137,6 +138,7 @@ export default function InputGlobalComponent({
{ skipSnapshot },
);
}}
isToolMode={isToolMode}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function StrRenderComponent({
placeholder,
...baseInputProps
}: InputProps<string, StrRenderComponentType>) {
const { handleOnNewValue, id, disabled, editNode, value } = baseInputProps;
const { handleOnNewValue, id, disabled, editNode, value, isToolMode } =
baseInputProps;

if (!templateData.options) {
return templateData.multiline ? (
Expand All @@ -25,6 +26,7 @@ export function StrRenderComponent({
}
}}
id={`textarea_${id}`}
isToolMode={isToolMode}
/>
) : (
<InputGlobalComponent
Expand All @@ -33,6 +35,7 @@ export function StrRenderComponent({
load_from_db={templateData.load_from_db}
placeholder={placeholder}
id={"input-" + name}
isToolMode={isToolMode}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getIconName } from "@/components/inputComponent/components/helpers/get-icon-name";
import { GRADIENT_CLASS } from "@/constants/constants";
import ComponentTextModal from "@/modals/textAreaModal";
import { useRef, useState } from "react";
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function TextAreaComponent({
updateVisibility,
password,
placeholder,
isToolMode = false,
}: InputProps<string, TextAreaComponentType>): JSX.Element {
const inputRef = useRef<HTMLInputElement>(null);
const [isFocused, setIsFocused] = useState(false);
Expand Down Expand Up @@ -106,7 +108,7 @@ export default function TextAreaComponent({

<IconComponent
dataTestId={`button_open_text_area_modal_${id}${editNode ? "_advanced" : ""}`}
name={disabled ? "lock" : "Scan"}
name={getIconName(disabled, "", "", false, isToolMode) || "Scan"}
className={cn(
"cursor-pointer bg-background",
externalLinkIconClasses.icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function ParameterRenderComponent({
nodeClass,
disabled,
placeholder,
isToolMode,
}: {
handleOnNewValue: handleOnNewValueType;
name: string;
Expand All @@ -42,6 +43,7 @@ export function ParameterRenderComponent({
nodeClass: APIClassType;
disabled: boolean;
placeholder?: string;
isToolMode?: boolean;
}) {
const id = (
templateData.type +
Expand All @@ -61,6 +63,7 @@ export function ParameterRenderComponent({
handleNodeClass,
readonly: templateData.readonly,
placeholder,
isToolMode,
};
if (TEXT_FIELD_TYPES.includes(templateData.type ?? "")) {
if (templateData.list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type BaseInputProps<valueType = any> = {
handleNodeClass?: (value: any, code?: string, type?: string) => void;
readonly?: boolean;
placeholder?: string;
isToolMode?: boolean;
};

// Generic type for composing input props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function CustomParameterComponent({
nodeClass,
disabled,
placeholder,
isToolMode,
}: {
handleOnNewValue: handleOnNewValueType;
name: string;
Expand All @@ -25,6 +26,7 @@ export function CustomParameterComponent({
nodeClass: APIClassType;
disabled: boolean;
placeholder?: string;
isToolMode?: boolean;
}) {
return (
<ParameterRenderComponent
Expand All @@ -38,6 +40,7 @@ export function CustomParameterComponent({
nodeClass={nodeClass}
disabled={disabled}
placeholder={placeholder}
isToolMode={isToolMode}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/types/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type InputComponentType = {
isObjectOption?: boolean;
onChangeFolderName?: (e: any) => void;
nodeStyle?: boolean;
isToolMode?: boolean;
};
export type DropDownComponent = {
disabled?: boolean;
Expand Down

0 comments on commit cb316a1

Please sign in to comment.