(doc: PersistedFullWorkflow, widgets: Widgets)
| 207 | } |
| 208 | |
| 209 | export function parseSubflow(doc: PersistedFullWorkflow, widgets: Widgets): SubflowNodeRenderingInfo { |
| 210 | if (!doc || !doc.snapshot.controlboard?.shareAsSubflowConfig) { |
| 211 | return { |
| 212 | doc, |
| 213 | nodesWithControlInfo: [], |
| 214 | inputs: [], |
| 215 | outputs: [] , |
| 216 | params: [], |
| 217 | title: "Subflow", |
| 218 | description: "" |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | const allNodes = Object.values(doc.snapshot.nodes); |
| 223 | const shareAsSubflowConfig = doc.snapshot.controlboard?.shareAsSubflowConfig; |
| 224 | const { title, description, nodes } = shareAsSubflowConfig; |
| 225 | |
| 226 | const nodesWithControlInfo = nodes.map(node => { |
| 227 | // @TODO: 这里需要考虑节点又是 subflow 的情况,不过暂时可以不考虑它,也就是说不能将 subflow 放在 controlboard 中当做参数 |
| 228 | const id = node.id; |
| 229 | const perssitedNode = allNodes.find(n => n.id === id) as PersistedWorkflowNode; |
| 230 | const widget = widgets[perssitedNode.value.widget]; |
| 231 | const { inputs, outputs, title, params } = getNodeRenderInfo(perssitedNode.value, widgets[perssitedNode.value.widget]); |
| 232 | |
| 233 | const paramsToRender = params.filter(param => { |
| 234 | if (!node.fields) { |
| 235 | return; |
| 236 | } |
| 237 | return node.fields.includes(param.property); |
| 238 | }); |
| 239 | |
| 240 | const inputsToRender = inputs.filter(input => { |
| 241 | if (!node.inputs) { |
| 242 | return; |
| 243 | } |
| 244 | return node.inputs.includes(input.name); |
| 245 | }); |
| 246 | |
| 247 | const outputsToRender = outputs.filter(output => { |
| 248 | if (!node.outputs) { |
| 249 | return; |
| 250 | } |
| 251 | return node.outputs.includes(output.name); |
| 252 | }); |
| 253 | |
| 254 | return { |
| 255 | id, |
| 256 | sdnode: perssitedNode?.value, |
| 257 | title, |
| 258 | nodeControl: node, |
| 259 | params: paramsToRender, |
| 260 | inputs: inputsToRender, |
| 261 | outputs: outputsToRender, |
| 262 | widget |
| 263 | } as SubflowNodeWithControl |
| 264 | }); |
| 265 | |
| 266 | const allInputs = nodesWithControlInfo.reduce((acc, { inputs, sdnode, widget, title, id }) => { |
no test coverage detected