From 8cdfb00af61f7ebeedca145a1ce8f671235cbc35 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 8 Sep 2023 12:17:28 -0300 Subject: [PATCH] chore(reactflowUtils.ts): add TODO comment to update to new types feat(reactflowUtils.ts): add function to update group node template to set visibility of basic types to advanced true feat(reactflowUtils.ts): add function to generate node template for group node based on flow data feat(reactflowUtils.ts): add function to generate node from flow data --- src/frontend/src/utils/reactflowUtils.ts | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 5c1386b47..c6021e84e 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -517,6 +517,40 @@ export function validateSelection( } return errorsArray; } +// TODO UPDATE TO NEW TYPES +function updateGroupNodeTemplate(template: APITemplateType) { + /*this function receives a template, iterates for it's items + updating the visibility of all basic types setting it to advanced true*/ + Object.keys(template).forEach((key) => { + let type = template[key].type; + if ( + (type === "str" || + type === "bool" || + type === "float" || + type === "code" || + type === "prompt" || + type === "file" || + type === "int") && + !template[key].required + ) { + template[key].advanced = true; + } + }); + return template; +} + +export function generateNodeTemplate(Flow: FlowType) { + /* + this function receives a flow and generate a template for the group node + */ + let template = mergeNodeTemplates({ + nodes: Flow.data!.nodes, + edges: Flow.data!.edges, + }); + updateGroupNodeTemplate(template); + return template; +} + export function generateNodeFromFlow(flow: FlowType): NodeType { const { nodes } = flow.data!;