Skip to content

Commit 70fbc26

Browse files
authored
Flow to xml inconsistencies (#426)
1 parent fff3a6f commit 70fbc26

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

src/main/frontend/app/routes/studio/flow-to-xml-parser.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,24 @@ function generateXmlElement(
174174

175175
const childXml = children.map((child: ChildNode) => generateChildXml(child, 4)).join('\n')
176176

177-
const forwards = (edgeMap.get(node.id) || [])
178-
.map(({ label, targetId }) => {
179-
const forwardTarget = nodeMap.get(targetId)
180-
const targetName = (forwardTarget?.data as NodeData)?.name || ''
181-
if (targetName === '') {
182-
console.warn(`Target node with ID ${targetId} does not have a name attribute.`)
183-
return ''
184-
}
185-
// If saving from flow to xml, all edges will be considered explicit Forwards.
186-
return ` <Forward name="${escapeXml(label)}" path="${escapeXml(targetName)}" />`
187-
})
188-
.join('\n')
177+
const type = (node.data as NodeData).type?.toLowerCase()
178+
179+
const forwards =
180+
type === 'receiver'
181+
? '' // Receivers should never have a <Forward> element
182+
: (edgeMap.get(node.id) || [])
183+
.map(({ label, targetId }) => {
184+
const forwardTarget = nodeMap.get(targetId)
185+
const targetName = (forwardTarget?.data as NodeData)?.name || ''
186+
187+
if (targetName === '') {
188+
console.warn(`Target node with ID ${targetId} does not have a name attribute.`)
189+
return ''
190+
}
191+
192+
return ` <Forward name="${escapeXml(label)}" path="${escapeXml(targetName)}" />`
193+
})
194+
.join('\n')
189195

190196
const content = [childXml, forwards].filter(Boolean).join('\n')
191197
return content
@@ -219,6 +225,7 @@ ${spaces}</${child.subtype}>`
219225
function generateExitsXml(exitNodes: FlowNode[]): string {
220226
return exitNodes
221227
.map((node) => {
228+
const { name } = node.data as NodeData
222229
const data = node.data as NodeData
223230
const { x, y } = node.position
224231
const roundedX = Math.round(x)
@@ -229,23 +236,17 @@ function generateExitsXml(exitNodes: FlowNode[]): string {
229236
width = node.measured.width
230237
height = node.measured.height
231238
}
232-
const name = escapeXml(data.name)
233-
const state = getExitState(data)
239+
const attributes = data.attributes || {}
234240
const flowNamespaceString = `flow:y="${roundedY}" flow:x="${roundedX}" flow:width="${width}" flow:height="${height}"`
241+
const attributeString = ` name="${escapeXml(name)}"${Object.entries(attributes)
242+
.map(([key, value]) => ` ${key}="${escapeXml(value)}"`)
243+
.join('')}`
235244

236-
return ` <Exit name="${name}" state="${state}" ${flowNamespaceString} />`
245+
return ` <Exit ${attributeString} ${flowNamespaceString} />`
237246
})
238247
.join('\n')
239248
}
240249

241-
function getExitState(data: NodeData): string {
242-
const storedState = data.attributes?.state
243-
if (storedState) return storedState
244-
245-
const name = data.name.toLowerCase()
246-
return name.includes('bad') || name.includes('fail') ? 'error' : 'success'
247-
}
248-
249250
function generateFlowElementsXml(nodes: FlowNode[]): string {
250251
const stickyNotes = nodes.filter((node) => isStickyNote(node))
251252
const groupNodes = nodes.filter((node) => isGroupNode(node))

0 commit comments

Comments
 (0)