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.
This commit is contained in:
anovazzi1 2023-12-04 14:28:07 -03:00
commit faea687871
2 changed files with 5 additions and 2 deletions

View file

@ -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);

View file

@ -675,3 +675,5 @@ export const LANGFLOW_SUPPORTED_TYPES = new Set([
"dict",
"NestedDict",
]);
export const priorityFields = new Set(["code", "template"]);