refactor for field types

This commit is contained in:
anovazzi1 2023-11-23 21:33:30 -03:00
commit 037f7f5b1b
6 changed files with 499 additions and 561 deletions

View file

@ -22,7 +22,7 @@ import PromptAreaComponent from "../../../../components/promptComponent";
import TextAreaComponent from "../../../../components/textAreaComponent"; import TextAreaComponent from "../../../../components/textAreaComponent";
import ToggleShadComponent from "../../../../components/toggleShadComponent"; import ToggleShadComponent from "../../../../components/toggleShadComponent";
import { Button } from "../../../../components/ui/button"; import { Button } from "../../../../components/ui/button";
import { TOOLTIP_EMPTY } from "../../../../constants/constants"; import { LANGFLOW_SUPPORTED_TYPES, TOOLTIP_EMPTY } from "../../../../constants/constants";
import { FlowsContext } from "../../../../contexts/flowsContext"; import { FlowsContext } from "../../../../contexts/flowsContext";
import { typesContext } from "../../../../contexts/typesContext"; import { typesContext } from "../../../../contexts/typesContext";
import { ParameterComponentType } from "../../../../types/components"; import { ParameterComponentType } from "../../../../types/components";
@ -223,15 +223,7 @@ export default function ParameterComponent({
return !showNode ? ( return !showNode ? (
left && left &&
(type === "str" || (LANGFLOW_SUPPORTED_TYPES.has(type??"")) &&
type === "bool" ||
type === "float" ||
type === "code" ||
type === "prompt" ||
type === "file" ||
type === "int" ||
type === "dict" ||
type === "NestedDict") &&
!optionalHandle ? ( !optionalHandle ? (
<></> <></>
) : ( ) : (
@ -306,15 +298,7 @@ export default function ParameterComponent({
</div> </div>
</div> </div>
{left && {left &&
(type === "str" || (LANGFLOW_SUPPORTED_TYPES.has(type??"")) &&
type === "bool" ||
type === "float" ||
type === "code" ||
type === "prompt" ||
type === "file" ||
type === "int" ||
type === "dict" ||
type === "NestedDict") &&
!optionalHandle ? ( !optionalHandle ? (
<></> <></>
) : ( ) : (

File diff suppressed because it is too large Load diff

View file

@ -663,3 +663,6 @@ export const LAST_USED_SPAN_1 = "The last time this key was used.";
export const LAST_USED_SPAN_2 = export const LAST_USED_SPAN_2 =
"Accurate to within the hour from the most recent usage."; "Accurate to within the hour from the most recent usage.";
export const LANGFLOW_SUPPORTED_TYPES= new Set(["str","bool","float","code",
"prompt","file","int","dict","NestedDict"])

View file

@ -13,7 +13,7 @@ import {
// import "ace-builds/webpack-resolver"; // import "ace-builds/webpack-resolver";
import CodeTabsComponent from "../../components/codeTabsComponent"; import CodeTabsComponent from "../../components/codeTabsComponent";
import IconComponent from "../../components/genericIconComponent"; import IconComponent from "../../components/genericIconComponent";
import { EXPORT_CODE_DIALOG } from "../../constants/constants"; import { EXPORT_CODE_DIALOG, LANGFLOW_SUPPORTED_TYPES } from "../../constants/constants";
import { AuthContext } from "../../contexts/authContext"; import { AuthContext } from "../../contexts/authContext";
import { FlowsContext } from "../../contexts/flowsContext"; import { FlowsContext } from "../../contexts/flowsContext";
import { TemplateVariableType } from "../../types/api"; import { TemplateVariableType } from "../../types/api";
@ -99,15 +99,7 @@ const ApiModal = forwardRef(
(templateField) => (templateField) =>
templateField.charAt(0) !== "_" && templateField.charAt(0) !== "_" &&
node.data.node.template[templateField].show && node.data.node.template[templateField].show &&
(node.data.node.template[templateField].type === "str" || (LANGFLOW_SUPPORTED_TYPES.has(node.data.node.template[templateField].type))
node.data.node.template[templateField].type === "bool" ||
node.data.node.template[templateField].type === "float" ||
node.data.node.template[templateField].type === "code" ||
node.data.node.template[templateField].type === "prompt" ||
node.data.node.template[templateField].type === "file" ||
node.data.node.template[templateField].type === "int" ||
node.data.node.template[templateField].type === "dict" ||
node.data.node.template[templateField].type === "NestedDict")
) )
.map((n, i) => { .map((n, i) => {
arrNodesWithValues.push(node["id"]); arrNodesWithValues.push(node["id"]);
@ -146,9 +138,9 @@ const ApiModal = forwardRef(
); );
if (existingTweak) { if (existingTweak) {
existingTweak[tw][template["name"]] = changes as string; existingTweak[tw][template["name"]!] = changes as string;
if (existingTweak[tw][template["name"]] == template.value) { if (existingTweak[tw][template["name"]!] == template.value) {
tweak.current.forEach((element) => { tweak.current.forEach((element) => {
if (element[tw] && Object.keys(element[tw])?.length === 0) { if (element[tw] && Object.keys(element[tw])?.length === 0) {
tweak.current = tweak.current.filter((obj) => { tweak.current = tweak.current.filter((obj) => {
@ -161,7 +153,7 @@ const ApiModal = forwardRef(
} else { } else {
const newTweak = { const newTweak = {
[tw]: { [tw]: {
[template["name"]]: changes, [template["name"]!]: changes,
}, },
} as uniqueTweakType; } as uniqueTweakType;
tweak.current.push(newTweak); tweak.current.push(newTweak);

View file

@ -25,7 +25,7 @@ import {
TableHeader, TableHeader,
TableRow, TableRow,
} from "../../components/ui/table"; } from "../../components/ui/table";
import { limitScrollFieldsModal } from "../../constants/constants"; import { LANGFLOW_SUPPORTED_TYPES, limitScrollFieldsModal } from "../../constants/constants";
import { FlowsContext } from "../../contexts/flowsContext"; import { FlowsContext } from "../../contexts/flowsContext";
import { typesContext } from "../../contexts/typesContext"; import { typesContext } from "../../contexts/typesContext";
import { NodeDataType } from "../../types/flow"; import { NodeDataType } from "../../types/flow";
@ -145,24 +145,7 @@ const EditNodeModal = forwardRef(
(templateParam) => (templateParam) =>
templateParam.charAt(0) !== "_" && templateParam.charAt(0) !== "_" &&
myData.current.node?.template[templateParam].show && myData.current.node?.template[templateParam].show &&
(myData.current.node.template[templateParam] (LANGFLOW_SUPPORTED_TYPES.has(myData.current.node.template[templateParam].type))
.type === "str" ||
myData.current.node.template[templateParam]
.type === "bool" ||
myData.current.node.template[templateParam]
.type === "float" ||
myData.current.node.template[templateParam]
.type === "code" ||
myData.current.node.template[templateParam]
.type === "prompt" ||
myData.current.node.template[templateParam]
.type === "file" ||
myData.current.node.template[templateParam]
.type === "int" ||
myData.current.node.template[templateParam]
.type === "dict" ||
myData.current.node.template[templateParam]
.type === "NestedDict")
) )
.map((templateParam, index) => ( .map((templateParam, index) => (
<TableRow key={index} className="h-10"> <TableRow key={index} className="h-10">

View file

@ -9,7 +9,7 @@ import {
XYPosition, XYPosition,
} from "reactflow"; } from "reactflow";
import ShortUniqueId from "short-unique-id"; import ShortUniqueId from "short-unique-id";
import { specialCharsRegex } from "../constants/constants"; import { LANGFLOW_SUPPORTED_TYPES, specialCharsRegex } from "../constants/constants";
import { APITemplateType, TemplateVariableType } from "../types/api"; import { APITemplateType, TemplateVariableType } from "../types/api";
import { import {
FlowType, FlowType,
@ -634,15 +634,7 @@ function updateGroupNodeTemplate(template: APITemplateType) {
let type = template[key].type; let type = template[key].type;
let input_types = template[key].input_types; let input_types = template[key].input_types;
if ( if (
(type === "str" || LANGFLOW_SUPPORTED_TYPES.has(type) &&
type === "bool" ||
type === "float" ||
type === "code" ||
type === "prompt" ||
type === "file" ||
type === "int" ||
type === "dict" ||
type === "NestedDict") &&
!template[key].required && !template[key].required &&
!input_types !input_types
) { ) {