feat(web): 增加表单数据校验
This commit is contained in:
38
service-web/client/src/components/flow/Helper.tsx
Normal file
38
service-web/client/src/components/flow/Helper.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import {type Edge, getIncomers, type Node} from '@xyflow/react'
|
||||
import {find, has, isEqual, unique} from 'licia'
|
||||
import Queue from 'yocto-queue'
|
||||
|
||||
export const getAllIncomerNodeById: (id: string, nodes: Node[], edges: Edge[]) => string[] = (id, nodes, edges) => {
|
||||
let queue = new Queue<Node>()
|
||||
queue.enqueue(find(nodes, node => isEqual(node.id, id))!)
|
||||
let result: string[] = []
|
||||
while (queue.size !== 0) {
|
||||
let currentNode = queue.dequeue()!
|
||||
for (const incomer of getIncomers(currentNode, nodes, edges)) {
|
||||
result.push(incomer.id)
|
||||
queue.enqueue(incomer)
|
||||
}
|
||||
}
|
||||
return unique(result, (a, b) => isEqual(a, b))
|
||||
}
|
||||
|
||||
export const getAllIncomerNodeOutputVariables: (id: string, nodes: Node[], edges: Edge[], data: any) => {
|
||||
id: string,
|
||||
variable: string
|
||||
}[] = (id, nodes, edges, data) => {
|
||||
let incomerIds = getAllIncomerNodeById(id, nodes, edges)
|
||||
let incomerVariables: { id: string, variable: string }[] = []
|
||||
for (const incomerId of incomerIds) {
|
||||
let nodeData = data[incomerId] ?? {}
|
||||
if (has(nodeData, 'outputs')) {
|
||||
let outputs = nodeData?.outputs ?? []
|
||||
for (const output of Object.keys(outputs)) {
|
||||
incomerVariables.push({
|
||||
id: incomerId,
|
||||
variable: output,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return incomerVariables
|
||||
}
|
||||
Reference in New Issue
Block a user