260228:1536 20260228:15:35 workflow update #5 Visual Builder Types
All checks were successful
Build and Deploy / deploy (push) Successful in 2m35s
All checks were successful
Build and Deploy / deploy (push) Successful in 2m35s
This commit is contained in:
@@ -69,10 +69,10 @@ function parseDSL(dsl: string): { nodes: Node[], edges: Edge[] } {
|
|||||||
const parsedDsl = JSON.parse(dsl);
|
const parsedDsl = JSON.parse(dsl);
|
||||||
const states = parsedDsl.states || [];
|
const states = parsedDsl.states || [];
|
||||||
|
|
||||||
states.forEach((state: { id: string, name: string, type: string, role?: string, transitions?: { event: string, to: string }[] }) => {
|
states.forEach((state: { id?: string, name: string, type?: string, role?: string, initial?: boolean, terminal?: boolean, on?: Record<string, { to: string }> }) => {
|
||||||
const isCondition = state.type === 'CONDITION';
|
const isCondition = state.type === 'CONDITION';
|
||||||
const isStart = state.type === 'START';
|
const isStart = state.initial === true || state.type === 'START';
|
||||||
const isEnd = state.type === 'END';
|
const isEnd = state.terminal === true || state.type === 'END';
|
||||||
|
|
||||||
let nodeType = 'default';
|
let nodeType = 'default';
|
||||||
let style = { ...nodeStyle };
|
let style = { ...nodeStyle };
|
||||||
@@ -88,7 +88,7 @@ function parseDSL(dsl: string): { nodes: Node[], edges: Edge[] } {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodes.push({
|
nodes.push({
|
||||||
id: state.id,
|
id: state.name || state.id || `node-${Date.now()}`,
|
||||||
type: nodeType,
|
type: nodeType,
|
||||||
data: {
|
data: {
|
||||||
label: isStart || isEnd ? state.name : `${state.name}\n(${state.role || 'No Role'})`,
|
label: isStart || isEnd ? state.name : `${state.name}\n(${state.role || 'No Role'})`,
|
||||||
@@ -100,15 +100,19 @@ function parseDSL(dsl: string): { nodes: Node[], edges: Edge[] } {
|
|||||||
style: style
|
style: style
|
||||||
});
|
});
|
||||||
|
|
||||||
if (state.transitions) {
|
if (state.on) {
|
||||||
state.transitions.forEach((trans: { event: string, to: string }) => {
|
const transitions = state.on;
|
||||||
edges.push({
|
Object.keys(transitions).forEach((eventName) => {
|
||||||
id: `e-${state.id}-${trans.to}`,
|
const trans = transitions[eventName];
|
||||||
source: state.id,
|
if (trans && trans.to) {
|
||||||
target: trans.to,
|
edges.push({
|
||||||
label: trans.event,
|
id: `e-${state.name || state.id || 'node'}-${trans.to}`,
|
||||||
markerEnd: { type: MarkerType.ArrowClosed }
|
source: state.name || state.id || 'node',
|
||||||
});
|
target: trans.to,
|
||||||
|
label: eventName,
|
||||||
|
markerEnd: { type: MarkerType.ArrowClosed }
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,23 +179,51 @@ function VisualWorkflowBuilderContent({ initialNodes: propNodes, initialEdges: p
|
|||||||
|
|
||||||
// Generate JSON DSL
|
// Generate JSON DSL
|
||||||
const generateDSL = () => {
|
const generateDSL = () => {
|
||||||
|
let hasStart = false;
|
||||||
const states = nodes.map(n => {
|
const states = nodes.map(n => {
|
||||||
const outgoingEdges = edges.filter(e => e.source === n.id);
|
const outgoingEdges = edges.filter(e => e.source === n.id);
|
||||||
const transitions = outgoingEdges.map(e => ({
|
const onConfig: Record<string, { to: string }> = {};
|
||||||
event: e.label || 'PROCEED',
|
|
||||||
to: e.target
|
|
||||||
}));
|
|
||||||
|
|
||||||
return {
|
outgoingEdges.forEach(e => {
|
||||||
id: n.id,
|
const eventName = e.label || 'PROCEED';
|
||||||
|
onConfig[eventName as string] = { to: e.target };
|
||||||
|
});
|
||||||
|
|
||||||
|
const isStartNode = n.type === 'input';
|
||||||
|
const isEndNode = n.type === 'output';
|
||||||
|
|
||||||
|
if (isStartNode) hasStart = true;
|
||||||
|
|
||||||
|
const stateObj: { name: string; type?: string; role?: string; initial?: boolean; terminal?: boolean; on?: Record<string, { to: string }> } = {
|
||||||
name: n.data.name || n.data.label.split('\n')[0],
|
name: n.data.name || n.data.label.split('\n')[0],
|
||||||
type: n.data.type || 'TASK',
|
|
||||||
role: n.data.role,
|
|
||||||
transitions: transitions
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (n.data.type && n.data.type !== 'START' && n.data.type !== 'END' && n.data.type !== 'TASK') {
|
||||||
|
stateObj.type = n.data.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n.data.role && !isStartNode && !isEndNode) {
|
||||||
|
stateObj.role = n.data.role;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isStartNode && !hasStart) {
|
||||||
|
stateObj.initial = true;
|
||||||
|
}
|
||||||
|
if (isEndNode) {
|
||||||
|
stateObj.terminal = true;
|
||||||
|
}
|
||||||
|
if (Object.keys(onConfig).length > 0) {
|
||||||
|
stateObj.on = onConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateObj;
|
||||||
});
|
});
|
||||||
|
|
||||||
const dslObj = { states };
|
const dslObj = {
|
||||||
|
workflow: "VISUAL_WORKFLOW",
|
||||||
|
version: 1,
|
||||||
|
states
|
||||||
|
};
|
||||||
const dsl = JSON.stringify(dslObj, null, 2);
|
const dsl = JSON.stringify(dslObj, null, 2);
|
||||||
|
|
||||||
console.log("Generated DSL:", dsl);
|
console.log("Generated DSL:", dsl);
|
||||||
|
|||||||
Reference in New Issue
Block a user