fix output string of custom component and truncate long Ids on display name

This commit is contained in:
anovazzi1 2023-09-12 21:00:42 -03:00
commit 9d510e3e4b
3 changed files with 49 additions and 27 deletions

View file

@ -19,6 +19,7 @@ export type NodeDataType = {
type: string; type: string;
node?: APIClassType; node?: APIClassType;
id: string; id: string;
output_types?: string[];
}; };
// FlowStyleType is the type of the style object that is used to style the // FlowStyleType is the type of the style object that is used to style the
// Flow card with an emoji and a color. // Flow card with an emoji and a color.

View file

@ -8,6 +8,7 @@ import {
ReactFlowJsonObject, ReactFlowJsonObject,
XYPosition, XYPosition,
} from "reactflow"; } from "reactflow";
import ShortUniqueId from "short-unique-id";
import { specialCharsRegex } from "../constants/constants"; import { specialCharsRegex } from "../constants/constants";
import { APITemplateType, TemplateVariableType } from "../types/api"; import { APITemplateType, TemplateVariableType } from "../types/api";
import { import {
@ -23,8 +24,7 @@ import {
unselectAllNodesType, unselectAllNodesType,
updateEdgesHandleIdsType, updateEdgesHandleIdsType,
} from "../types/utils/reactflowUtils"; } from "../types/utils/reactflowUtils";
import { toNormalCase, toTitleCase } from "./utils"; import { toNormalCase, toTitleCase, truncateLongId } from "./utils";
import ShortUniqueId from "short-unique-id";
const uid = new ShortUniqueId({ length: 5 }); const uid = new ShortUniqueId({ length: 5 });
export function cleanEdges({ export function cleanEdges({
@ -455,10 +455,7 @@ export function filterFlow(
); );
} }
export function findLastNode({ export function findLastNode({ nodes, edges }: findLastNodeType) {
nodes,
edges,
}: findLastNodeType) {
/* /*
this function receives a flow and return the last node this function receives a flow and return the last node
*/ */
@ -531,12 +528,12 @@ function updateGroupNodeTemplate(template: APITemplateType) {
type === "prompt" || type === "prompt" ||
type === "file" || type === "file" ||
type === "int") && type === "int") &&
!template[key].required && !input_types !template[key].required &&
!input_types
) { ) {
template[key].advanced = true; template[key].advanced = true;
if(template[key].dynamic) if (template[key].dynamic) {
{ template[key].dynamic = false;
template[key].dynamic = false
} }
} }
}); });
@ -571,11 +568,14 @@ 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.node!.display_name + " - " + (nodeTemplate[key].display_name //data id already has the node name on it
? nodeTemplate[key].display_name truncateLongId(node.data.id) +
: nodeTemplate[key].name " - " +
? toTitleCase(nodeTemplate[key].name) (nodeTemplate[key].display_name
: toTitleCase(key)) ? nodeTemplate[key].display_name
: nodeTemplate[key].name
? toTitleCase(nodeTemplate[key].name)
: toTitleCase(key));
} }
} }
}); });
@ -596,14 +596,22 @@ function isHandleConnected(
edges.some( edges.some(
(e) => (e) =>
e.targetHandle === e.targetHandle ===
customStringify({type:field.type,fieldName:key,id:nodeId,proxy:{id:field.proxy!.id,field:field.proxy!.field}}) ) customStringify({
type: field.type,
fieldName: key,
id: nodeId,
proxy: { id: field.proxy!.id, field: field.proxy!.field },
})
)
) { ) {
return true; return true;
} }
} else { } else {
if ( if (
edges.some( edges.some(
(e) => e.targetHandle === customStringify({type:field.type,fieldName:key,id:nodeId}) (e) =>
e.targetHandle ===
customStringify({ type: field.type, fieldName: key, id: nodeId })
) )
) { ) {
return true; return true;
@ -624,7 +632,6 @@ export function generateNodeTemplate(Flow: FlowType) {
return template; return template;
} }
export function generateNodeFromFlow(flow: FlowType): NodeType { export function generateNodeFromFlow(flow: FlowType): NodeType {
const { nodes } = flow.data!; const { nodes } = flow.data!;
const outputNode = _.cloneDeep(findLastNode(flow.data!)); const outputNode = _.cloneDeep(findLastNode(flow.data!));
@ -634,9 +641,10 @@ export function generateNodeFromFlow(flow: FlowType): NodeType {
const newGroupNode: NodeType = { const newGroupNode: NodeType = {
data: { data: {
id: data.id, id: data.id,
type: outputNode!.data.type, type: outputNode?.data.type!,
node: { node: {
display_name:"group Node", output_types: outputNode!.data.node!.output_types,
display_name: "group Node",
documentation: "", documentation: "",
base_classes: outputNode!.data.node!.base_classes, base_classes: outputNode!.data.node!.base_classes,
description: "group Node", description: "group Node",
@ -690,11 +698,11 @@ export function connectedInputNodesOnHandle(
} }
export function ungroupNode( export function ungroupNode(
groupNode:NodeDataType, groupNode: NodeDataType,
BaseFlow: ReactFlowJsonObject, BaseFlow: ReactFlowJsonObject
) { ) {
const {template} = groupNode.node const { template } = groupNode.node;
const {flow} = groupNode.node; const { flow } = groupNode.node;
const gNodes: NodeType[] = flow.data.nodes; const gNodes: NodeType[] = flow.data.nodes;
const gEdges = flow.data.edges; const gEdges = flow.data.edges;
//redirect edges to correct proxy node //redirect edges to correct proxy node
@ -756,7 +764,10 @@ export function ungroupNode(
} }
}); });
const nodes = [...BaseFlow.nodes.filter((n) => n.id !== groupNode.id), ...gNodes]; const nodes = [
...BaseFlow.nodes.filter((n) => n.id !== groupNode.id),
...gNodes,
];
const edges = [ const edges = [
...BaseFlow.edges.filter( ...BaseFlow.edges.filter(
(e) => e.target !== groupNode.id && e.source !== groupNode.id (e) => e.target !== groupNode.id && e.source !== groupNode.id
@ -772,7 +783,7 @@ export function processFLow(FlowObject: ReactFlowJsonObject) {
let clonedFLow = _.cloneDeep(FlowObject); let clonedFLow = _.cloneDeep(FlowObject);
clonedFLow.nodes.forEach((node: NodeType) => { clonedFLow.nodes.forEach((node: NodeType) => {
if (node.type === "groupNode") { if (node.type === "groupNode") {
processFLow(node.data.node.flow.data); processFLow(node.data.node!.flow!.data!);
ungroupNode(node.data, clonedFLow); ungroupNode(node.data, clonedFLow);
} }
}); });

View file

@ -429,6 +429,16 @@ chat_input_field: Input key that you want the chat to send the user message with
></langflow-chat>`; ></langflow-chat>`;
} }
export function truncateLongId(id: string): string {
let [componentName,newId] = id.split("-");
if (componentName.length>15){
componentName = componentName.slice(0,10);
componentName += "...";
return componentName+"-"+newId;
}
return id;
}
export function tabsArray(codes: string[], method: number) { export function tabsArray(codes: string[], method: number) {
if (!method) return; if (!method) return;
if (method === 0) { if (method === 0) {