feat: multi step circle
This commit is contained in:
parent
0a30018330
commit
d9d42b2d8c
@ -133,14 +133,14 @@ export const multiStepsCircle = (() => {
|
|||||||
{ id: '2', parent_id: '1', label: 'Node 2' },
|
{ id: '2', parent_id: '1', label: 'Node 2' },
|
||||||
{ id: '3', parent_id: '1', label: 'Node 3' },
|
{ id: '3', parent_id: '1', label: 'Node 3' },
|
||||||
{ id: '4', parent_id: '2', label: 'Node 4' },
|
{ id: '4', parent_id: '2', label: 'Node 4' },
|
||||||
|
|
||||||
// Loop
|
// Loop
|
||||||
{ id: '1', parent_id: '1', label: 'Node 1' },
|
{ id: '1', parent_id: '4', label: 'Node 1' },
|
||||||
|
{ id: '2', parent_id: '1', label: 'Node 2' },
|
||||||
|
{ id: '4', parent_id: '2', label: 'Node 4' },
|
||||||
|
{ id: '1', parent_id: '4', label: 'Node 1' },
|
||||||
{ id: '2', parent_id: '1', label: 'Node 2' },
|
{ id: '2', parent_id: '1', label: 'Node 2' },
|
||||||
{ id: '4', parent_id: '2', label: 'Node 4' },
|
{ id: '4', parent_id: '2', label: 'Node 4' },
|
||||||
// { id: '1', parent_id: '1', label: 'Node 1' },
|
|
||||||
// { id: '2', parent_id: '1', label: 'Node 2' },
|
|
||||||
// { id: '4', parent_id: '2', label: 'Node 4' },
|
|
||||||
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ describe('agent', () => {
|
|||||||
|
|
||||||
test('list should remove circle log item', () => {
|
test('list should remove circle log item', () => {
|
||||||
// format(oneStepCircle.in as any)
|
// format(oneStepCircle.in as any)
|
||||||
console.log(JSON.stringify(format(multiStepsCircle.in as any)[0].agentLog))
|
expect(format(oneStepCircle.in as any)).toEqual(oneStepCircle.expect)
|
||||||
// expect(format(oneStepCircle.in as any)).toEqual(oneStepCircle.expect)
|
expect(format(multiStepsCircle.in as any)).toEqual(multiStepsCircle.expect)
|
||||||
// expect(format(multiStepsCircle.in as any)).toEqual(multiStepsCircle.expect)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -19,8 +19,24 @@ const remove = (node: AgentLogItemWithChildren, removeId: string) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removeRepeatedSiblings = (list: AgentLogItemWithChildren[]) => {
|
||||||
|
if (!list || list.length === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const result: AgentLogItemWithChildren[] = []
|
||||||
|
const addedItemIds: string[] = []
|
||||||
|
list.forEach((item) => {
|
||||||
|
if (!addedItemIds.includes(item.id)) {
|
||||||
|
result.push(item)
|
||||||
|
addedItemIds.push(item.id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
const removeCircleLogItem = (log: AgentLogItemWithChildren) => {
|
const removeCircleLogItem = (log: AgentLogItemWithChildren) => {
|
||||||
let newLog = cloneDeep(log)
|
let newLog = cloneDeep(log)
|
||||||
|
newLog.children = removeRepeatedSiblings(newLog.children)
|
||||||
let { id, children } = newLog
|
let { id, children } = newLog
|
||||||
if (!children || children.length === 0) {
|
if (!children || children.length === 0) {
|
||||||
return log
|
return log
|
||||||
@ -31,6 +47,7 @@ const removeCircleLogItem = (log: AgentLogItemWithChildren) => {
|
|||||||
newLog.hasCircle = true
|
newLog.hasCircle = true
|
||||||
newLog.children = newLog.children.filter(c => c.id !== id)
|
newLog.children = newLog.children.filter(c => c.id !== id)
|
||||||
children = newLog.children
|
children = newLog.children
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
children.forEach((child, index) => {
|
children.forEach((child, index) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user