feat: workflow new nodes (#4683)
Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Patryk Garstecki <patryk20120@yahoo.pl> Co-authored-by: Sebastian.W <thiner@gmail.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: takatost <takatost@users.noreply.github.com> Co-authored-by: rechardwang <wh_goodjob@163.com> Co-authored-by: Nite Knite <nkCoding@gmail.com> Co-authored-by: Chenhe Gu <guchenhe@gmail.com> Co-authored-by: Joshua <138381132+joshua20231026@users.noreply.github.com> Co-authored-by: Weaxs <459312872@qq.com> Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com> Co-authored-by: leejoo0 <81673835+leejoo0@users.noreply.github.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Vikey Chen <vikeytk@gmail.com> Co-authored-by: wanghl <Wang-HL@users.noreply.github.com> Co-authored-by: Haolin Wang-汪皓临 <haolin.wang@atlaslovestravel.com> Co-authored-by: Zixuan Cheng <61724187+Theysua@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Bowen Liang <bowenliang@apache.org> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: fanghongtai <42790567+fanghongtai@users.noreply.github.com> Co-authored-by: wxfanghongtai <wxfanghongtai@gf.com.cn> Co-authored-by: Matri <qjp@bithuman.io> Co-authored-by: Benjamin <benjaminx@gmail.com>
This commit is contained in:
@@ -4,9 +4,12 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import cn from 'classnames'
|
||||
import { useBoolean } from 'ahooks'
|
||||
import { BlockEnum } from '../types'
|
||||
import OutputPanel from './output-panel'
|
||||
import ResultPanel from './result-panel'
|
||||
import TracingPanel from './tracing-panel'
|
||||
import IterationResultPanel from './iteration-result-panel'
|
||||
import { ToastContext } from '@/app/components/base/toast'
|
||||
import Loading from '@/app/components/base/loading'
|
||||
import { fetchRunDetail, fetchTracingList } from '@/service/log'
|
||||
@@ -19,9 +22,10 @@ export type RunProps = {
|
||||
activeTab?: 'RESULT' | 'DETAIL' | 'TRACING'
|
||||
runID: string
|
||||
getResultCallback?: (result: WorkflowRunDetailResponse) => void
|
||||
onShowIterationDetail: (detail: NodeTracing[][]) => void
|
||||
}
|
||||
|
||||
const RunPanel: FC<RunProps> = ({ hideResult, activeTab = 'RESULT', runID, getResultCallback }) => {
|
||||
const RunPanel: FC<RunProps> = ({ hideResult, activeTab = 'RESULT', runID, getResultCallback, onShowIterationDetail }) => {
|
||||
const { t } = useTranslation()
|
||||
const { notify } = useContext(ToastContext)
|
||||
const [currentTab, setCurrentTab] = useState<string>(activeTab)
|
||||
@@ -56,12 +60,76 @@ const RunPanel: FC<RunProps> = ({ hideResult, activeTab = 'RESULT', runID, getRe
|
||||
}
|
||||
}, [notify, getResultCallback])
|
||||
|
||||
const formatNodeList = useCallback((list: NodeTracing[]) => {
|
||||
const allItems = list.reverse()
|
||||
const result: NodeTracing[] = []
|
||||
let iterationIndexInfos: {
|
||||
start: number
|
||||
end: number
|
||||
}[] = []
|
||||
allItems.forEach((item) => {
|
||||
const { node_type, index, execution_metadata } = item
|
||||
if (node_type !== BlockEnum.Iteration) {
|
||||
let isInIteration = false
|
||||
let isIterationFirstNode = false
|
||||
iterationIndexInfos.forEach(({ start, end }) => {
|
||||
if (index >= start && index < end) {
|
||||
if (index === start)
|
||||
isIterationFirstNode = true
|
||||
|
||||
isInIteration = true
|
||||
}
|
||||
})
|
||||
if (isInIteration) {
|
||||
const iterationDetails = result[result.length - 1].details!
|
||||
if (isIterationFirstNode)
|
||||
iterationDetails!.push([item])
|
||||
|
||||
else
|
||||
iterationDetails[iterationDetails.length - 1].push(item)
|
||||
|
||||
return
|
||||
}
|
||||
// not in iteration
|
||||
result.push(item)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const { steps_boundary } = execution_metadata
|
||||
iterationIndexInfos = []
|
||||
steps_boundary.forEach((boundary, index) => {
|
||||
if (index === 0) {
|
||||
iterationIndexInfos.push({
|
||||
start: boundary,
|
||||
end: 0,
|
||||
})
|
||||
}
|
||||
else if (index === steps_boundary.length - 1) {
|
||||
iterationIndexInfos[iterationIndexInfos.length - 1].end = boundary
|
||||
}
|
||||
else {
|
||||
iterationIndexInfos[iterationIndexInfos.length - 1].end = boundary
|
||||
iterationIndexInfos.push({
|
||||
start: boundary,
|
||||
end: 0,
|
||||
})
|
||||
}
|
||||
})
|
||||
result.push({
|
||||
...item,
|
||||
details: [],
|
||||
})
|
||||
})
|
||||
return result
|
||||
}, [])
|
||||
|
||||
const getTracingList = useCallback(async (appID: string, runID: string) => {
|
||||
try {
|
||||
const { data: nodeList } = await fetchTracingList({
|
||||
url: `/apps/${appID}/workflow-runs/${runID}/node-executions`,
|
||||
})
|
||||
setList(nodeList.reverse())
|
||||
setList(formatNodeList(nodeList))
|
||||
}
|
||||
catch (err) {
|
||||
notify({
|
||||
@@ -103,6 +171,29 @@ const RunPanel: FC<RunProps> = ({ hideResult, activeTab = 'RESULT', runID, getRe
|
||||
adjustResultHeight()
|
||||
}, [loading])
|
||||
|
||||
const [iterationRunResult, setIterationRunResult] = useState<NodeTracing[][]>([])
|
||||
const [isShowIterationDetail, {
|
||||
setTrue: doShowIterationDetail,
|
||||
setFalse: doHideIterationDetail,
|
||||
}] = useBoolean(false)
|
||||
|
||||
const handleShowIterationDetail = useCallback((detail: NodeTracing[][]) => {
|
||||
setIterationRunResult(detail)
|
||||
doShowIterationDetail()
|
||||
}, [doShowIterationDetail])
|
||||
|
||||
if (isShowIterationDetail) {
|
||||
return (
|
||||
<div className='grow relative flex flex-col'>
|
||||
<IterationResultPanel
|
||||
list={iterationRunResult}
|
||||
onHide={doHideIterationDetail}
|
||||
onBack={doHideIterationDetail}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='grow relative flex flex-col'>
|
||||
{/* tab */}
|
||||
@@ -161,6 +252,7 @@ const RunPanel: FC<RunProps> = ({ hideResult, activeTab = 'RESULT', runID, getRe
|
||||
{!loading && currentTab === 'TRACING' && (
|
||||
<TracingPanel
|
||||
list={list}
|
||||
onShowIterationDetail={handleShowIterationDetail}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user