You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.7 KiB
TypeScript
80 lines
1.7 KiB
TypeScript
import { Node } from '@xyflow/react';
|
|
|
|
interface FlowNodeDefinition {
|
|
nodeName: string;
|
|
data: any;
|
|
id?: string;
|
|
flowHousVO?: {
|
|
id?: string;
|
|
};
|
|
}
|
|
|
|
type EventIdMode = 'id' | 'eventIdOptional';
|
|
|
|
export const createFlowNode = (
|
|
nodeType: string,
|
|
nodeDefinition: FlowNodeDefinition,
|
|
position: { x: number; y: number }
|
|
): Node => {
|
|
const node: any = {
|
|
id: `${nodeType}-${Date.now()}`,
|
|
type: nodeType,
|
|
position,
|
|
data: {
|
|
...nodeDefinition.data,
|
|
title: nodeDefinition.nodeName,
|
|
type: nodeType,
|
|
},
|
|
};
|
|
|
|
if (nodeDefinition.id || nodeDefinition?.flowHousVO?.id) {
|
|
node.data.compId = nodeDefinition.id || nodeDefinition?.flowHousVO?.id;
|
|
}
|
|
|
|
return node;
|
|
};
|
|
|
|
export const attachFlowNodeComponent = (
|
|
node: any,
|
|
nodeType: string,
|
|
nodeDefinition: FlowNodeDefinition,
|
|
eventList: any[],
|
|
eventIdMode: EventIdMode
|
|
) => {
|
|
if (nodeType === 'SWITCH') {
|
|
node.data.component = {
|
|
customDef: JSON.stringify({
|
|
apiOutIds: ['default'],
|
|
conditions: [],
|
|
}),
|
|
};
|
|
} else if (nodeType === 'SUB') {
|
|
node.data.component = {
|
|
type: nodeType,
|
|
compId: node.data.compId,
|
|
};
|
|
} else if (nodeType === 'EVENTSEND' || nodeType === 'EVENTLISTENE') {
|
|
const emptyEvent = eventList.find((item) =>
|
|
item.topic.includes('**empty**')
|
|
);
|
|
node.data.component = {
|
|
type: nodeType,
|
|
customDef: {
|
|
eventId:
|
|
eventIdMode === 'eventIdOptional'
|
|
? emptyEvent?.eventId ?? null
|
|
: emptyEvent.id,
|
|
name: emptyEvent.name,
|
|
topic: emptyEvent.topic,
|
|
},
|
|
};
|
|
} else {
|
|
node.data.component = {
|
|
type: nodeType,
|
|
compId: nodeDefinition.id,
|
|
};
|
|
}
|
|
|
|
return node;
|
|
};
|