node collapse

This commit is contained in:
JzoNg 2024-03-19 14:46:47 +08:00
parent 67de047122
commit 0b7cdd1e5d
3 changed files with 8 additions and 24 deletions

View File

@ -4,7 +4,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { useContext } from 'use-context-selector'
import { useTranslation } from 'react-i18next'
import cn from 'classnames'
import produce from 'immer'
import ResultPanel from './result-panel'
import TracingPanel from './tracing-panel'
import { ToastContext } from '@/app/components/base/toast'
@ -27,7 +26,6 @@ const RunPanel: FC<RunProps> = ({ activeTab = 'RESULT', runID }) => {
const [loading, setLoading] = useState<boolean>(true)
const [runDetail, setRunDetail] = useState<WorkflowRunDetailResponse>()
const [list, setList] = useState<NodeTracing[]>([])
const [collapseState, setCollapseState] = useState<boolean[]>([])
const executor = useMemo(() => {
if (runDetail?.created_by_role === 'account')
@ -37,13 +35,6 @@ const RunPanel: FC<RunProps> = ({ activeTab = 'RESULT', runID }) => {
return 'N/A'
}, [runDetail])
const collapseStateChange = (index: number) => {
const newCollapseState = produce(collapseState, (draft: boolean[]) => {
draft[index] = !draft[index]
})
setCollapseState(newCollapseState)
}
const getResult = useCallback(async (appID: string, runID: string) => {
try {
const res = await fetchRunDetail({
@ -65,9 +56,7 @@ const RunPanel: FC<RunProps> = ({ activeTab = 'RESULT', runID }) => {
const { data: nodeList } = await fetchTracingList({
url: `/apps/${appID}/workflow-runs/${runID}/node-executions`,
})
const collapseState = nodeList.map(node => node.status === 'succeeded')
setList(nodeList.reverse())
setCollapseState(collapseState)
}
catch (err) {
notify({
@ -139,8 +128,6 @@ const RunPanel: FC<RunProps> = ({ activeTab = 'RESULT', runID }) => {
{!loading && currentTab === 'TRACING' && (
<TracingPanel
list={list}
collapseState={collapseState}
collapseHandle={collapseStateChange}
/>
)}
</div>

View File

@ -1,6 +1,7 @@
'use client'
import { useTranslation } from 'react-i18next'
import type { FC } from 'react'
import { useState } from 'react'
import cn from 'classnames'
import BlockIcon from '../block-icon'
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
@ -12,11 +13,11 @@ import type { NodeTracing } from '@/types/workflow'
type Props = {
nodeInfo: NodeTracing
collapsed: boolean
collapseHandle: () => void
collapsed?: boolean
}
const NodePanel: FC<Props> = ({ nodeInfo, collapsed, collapseHandle }) => {
const NodePanel: FC<Props> = ({ nodeInfo, collapsed = true }) => {
const [collapseState, setCollapseState] = useState<boolean>(collapsed)
const { t } = useTranslation()
const getTime = (time: number) => {
@ -44,7 +45,7 @@ const NodePanel: FC<Props> = ({ nodeInfo, collapsed, collapseHandle }) => {
'flex items-center pl-[6px] py-3 pr-3 cursor-pointer',
!collapsed && 'pb-2',
)}
onClick={collapseHandle}
onClick={() => setCollapseState(!collapseState)}
>
<ChevronRight
className={cn(
@ -71,7 +72,7 @@ const NodePanel: FC<Props> = ({ nodeInfo, collapsed, collapseHandle }) => {
</div>
)}
</div>
{!collapsed && (
{!collapseState && (
<div className='pb-2'>
<div className='px-[10px] py-1'>
{nodeInfo.status === 'stopped' && (

View File

@ -5,19 +5,15 @@ import type { NodeTracing } from '@/types/workflow'
type TracingPanelProps = {
list: NodeTracing[]
collapseState: boolean[]
collapseHandle: (index: number) => void
}
const TracingPanel: FC<TracingPanelProps> = ({ list, collapseState, collapseHandle }) => {
const TracingPanel: FC<TracingPanelProps> = ({ list }) => {
return (
<div className='bg-gray-50 py-2'>
{list.map((node, index) => (
{list.map(node => (
<NodePanel
key={node.id}
nodeInfo={node}
collapsed={collapseState[index]}
collapseHandle={() => collapseHandle(index)}
/>
))}
</div>