feat(types/api): add 'dynamic' and 'proxy' properties to TemplateVariableType to support dynamic and proxy fields in templates
feat(utils/reactflowUtils): add 'toTitleCase' function to convert strings to title case refactor(utils/reactflowUtils): update function names and comments refactor(utils/reactflowUtils): update 'updateGroupNodeTemplate' function to handle 'dynamic' property refactor(utils/reactflowUtils): update 'mergeNodeTemplates' function to handle 'display_name' and 'dynamic' properties refactor(utils/reactflowUtils): update 'isHandleConnected' function to handle 'proxy' property refactor(utils/reactflowUtils): update 'generateNodeFromFlow' function to set 'type' as 'genericNode' instead of 'groupNode'
This commit is contained in:
parent
42f7821002
commit
e4471886e4
2 changed files with 16 additions and 18 deletions
|
|
@ -29,6 +29,8 @@ export type TemplateVariableType = {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
multiline?: boolean;
|
multiline?: boolean;
|
||||||
value?: any;
|
value?: any;
|
||||||
|
dynamic?:boolean;
|
||||||
|
proxy?:{id:string,field:string}
|
||||||
input_types?: Array<string>;
|
input_types?: Array<string>;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import {
|
||||||
unselectAllNodesType,
|
unselectAllNodesType,
|
||||||
updateEdgesHandleIdsType,
|
updateEdgesHandleIdsType,
|
||||||
} from "../types/utils/reactflowUtils";
|
} from "../types/utils/reactflowUtils";
|
||||||
import { toNormalCase } from "./utils";
|
import { toNormalCase, toTitleCase } from "./utils";
|
||||||
import ShortUniqueId from "short-unique-id";
|
import ShortUniqueId from "short-unique-id";
|
||||||
const uid = new ShortUniqueId({ length: 5 });
|
const uid = new ShortUniqueId({ length: 5 });
|
||||||
|
|
||||||
|
|
@ -517,7 +517,6 @@ export function validateSelection(
|
||||||
}
|
}
|
||||||
return errorsArray;
|
return errorsArray;
|
||||||
}
|
}
|
||||||
// TODO UPDATE TO NEW TYPES
|
|
||||||
function updateGroupNodeTemplate(template: APITemplateType) {
|
function updateGroupNodeTemplate(template: APITemplateType) {
|
||||||
/*this function receives a template, iterates for it's items
|
/*this function receives a template, iterates for it's items
|
||||||
updating the visibility of all basic types setting it to advanced true*/
|
updating the visibility of all basic types setting it to advanced true*/
|
||||||
|
|
@ -535,11 +534,14 @@ function updateGroupNodeTemplate(template: APITemplateType) {
|
||||||
!template[key].required && !input_types
|
!template[key].required && !input_types
|
||||||
) {
|
) {
|
||||||
template[key].advanced = true;
|
template[key].advanced = true;
|
||||||
|
if(template[key].dynamic)
|
||||||
|
{
|
||||||
|
template[key].dynamic = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
// TODO UPDATE TO NEW HANDLE FORMAT
|
|
||||||
export function mergeNodeTemplates({
|
export function mergeNodeTemplates({
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
|
|
@ -547,7 +549,7 @@ export function mergeNodeTemplates({
|
||||||
nodes: NodeType[];
|
nodes: NodeType[];
|
||||||
edges: Edge[];
|
edges: Edge[];
|
||||||
}): APITemplateType {
|
}): APITemplateType {
|
||||||
/* this function receives a flow and iterate trhow each node
|
/* this function receives a flow and iterate throw each node
|
||||||
and merge the templates with only the visible fields
|
and merge the templates with only the visible fields
|
||||||
if there are two keys with the same name in the flow, we will update the display name of each one
|
if there are two keys with the same name in the flow, we will update the display name of each one
|
||||||
to show from which node it came from
|
to show from which node it came from
|
||||||
|
|
@ -569,14 +571,17 @@ export function mergeNodeTemplates({
|
||||||
node.data.node!.flow!.name + " - " + nodeTemplate[key].name;
|
node.data.node!.flow!.name + " - " + nodeTemplate[key].name;
|
||||||
} else {
|
} else {
|
||||||
template[key + "_" + node.id].display_name =
|
template[key + "_" + node.id].display_name =
|
||||||
node.data.type + " - " + nodeTemplate[key].name;
|
node.data.node!.display_name + " - " + (nodeTemplate[key].display_name
|
||||||
|
? nodeTemplate[key].display_name
|
||||||
|
: nodeTemplate[key].name
|
||||||
|
? toTitleCase(nodeTemplate[key].name)
|
||||||
|
: toTitleCase(key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
// TODO UPDATE TO NEW HANDLE FORMAT
|
|
||||||
function isHandleConnected(
|
function isHandleConnected(
|
||||||
edges: Edge[],
|
edges: Edge[],
|
||||||
key: string,
|
key: string,
|
||||||
|
|
@ -591,23 +596,14 @@ function isHandleConnected(
|
||||||
edges.some(
|
edges.some(
|
||||||
(e) =>
|
(e) =>
|
||||||
e.targetHandle ===
|
e.targetHandle ===
|
||||||
field.type +
|
customStringify({type:field.type,fieldName:key,id:nodeId,proxy:{id:field.proxy!.id,field:field.proxy!.field}}) )
|
||||||
"|" +
|
|
||||||
key +
|
|
||||||
"|" +
|
|
||||||
nodeId +
|
|
||||||
"|" +
|
|
||||||
field.proxy.id +
|
|
||||||
"|" +
|
|
||||||
field.proxy.field
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
edges.some(
|
edges.some(
|
||||||
(e) => e.targetHandle === field.type + "|" + key + "|" + nodeId
|
(e) => e.targetHandle === customStringify({type:field.type,fieldName:key,id:nodeId})
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -650,7 +646,7 @@ export function generateNodeFromFlow(flow: FlowType): NodeType {
|
||||||
},
|
},
|
||||||
id: data.id,
|
id: data.id,
|
||||||
position,
|
position,
|
||||||
type: "groupNode",
|
type: "genericNode",
|
||||||
};
|
};
|
||||||
return newGroupNode;
|
return newGroupNode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue