From faea6878714dfc532df3d5bde05246706ae74062 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 4 Dec 2023 14:28:07 -0300 Subject: [PATCH] feat(GenericNode): add priorityFields constant to improve sorting logic in GenericNode component The `GenericNode` component in `index.tsx` has been updated to include an import statement for the `priorityFields` constant from `constants.ts`. This constant is a `Set` containing the field names "code" and "template". In the `sort` function of the `GenericNode` component, the logic has been modified to check if a field name is present in the `priorityFields` set. If so, it gives higher priority to that field during sorting. This change improves the sorting logic in the component. The `constants.ts` file has also been updated to include the `priorityFields` constant. --- src/frontend/src/CustomNodes/GenericNode/index.tsx | 5 +++-- src/frontend/src/constants/constants.ts | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index 594744bf5..e212b5329 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -6,6 +6,7 @@ import Tooltip from "../../components/TooltipComponent"; import IconComponent from "../../components/genericIconComponent"; import InputComponent from "../../components/inputComponent"; import { Textarea } from "../../components/ui/textarea"; +import { priorityFields } from "../../constants/constants"; import { useSSE } from "../../contexts/SSEContext"; import { FlowsContext } from "../../contexts/flowsContext"; import { typesContext } from "../../contexts/typesContext"; @@ -438,9 +439,9 @@ export default function GenericNode({ {Object.keys(data.node!.template) .filter((templateField) => templateField.charAt(0) !== "_") .sort((a, b) => { - if (a.toLowerCase() === "code") { + if (priorityFields.has(a.toLowerCase())) { return -1; - } else if (b.toLowerCase() === "code") { + } else if (priorityFields.has(b.toLowerCase())) { return 1; } else { return a.localeCompare(b); diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index 3a048a730..f1026fec2 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -675,3 +675,5 @@ export const LANGFLOW_SUPPORTED_TYPES = new Set([ "dict", "NestedDict", ]); + +export const priorityFields = new Set(["code", "template"]);