mirror of
https://github.com/langgenius/dify.git
synced 2025-12-14 03:40:55 +00:00
run and history
This commit is contained in:
parent
8d4ced227e
commit
5199297f61
@ -1,25 +1,35 @@
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
|
useCallback,
|
||||||
useMemo,
|
useMemo,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import type { HeaderProps } from '@/app/components/workflow/header'
|
import type { HeaderProps } from '@/app/components/workflow/header'
|
||||||
import Header from '@/app/components/workflow/header'
|
import Header from '@/app/components/workflow/header'
|
||||||
import { fetchWorkflowRunHistory } from '@/service/workflow'
|
import { fetchWorkflowRunHistory } from '@/service/workflow'
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
import {
|
||||||
|
useStore,
|
||||||
|
useWorkflowStore,
|
||||||
|
} from '@/app/components/workflow/store'
|
||||||
import InputFieldButton from './input-field-button'
|
import InputFieldButton from './input-field-button'
|
||||||
import Publisher from './publisher'
|
import Publisher from './publisher'
|
||||||
|
|
||||||
const RagPipelineHeader = () => {
|
const RagPipelineHeader = () => {
|
||||||
|
const workflowStore = useWorkflowStore()
|
||||||
const pipelineId = useStore(s => s.pipelineId)
|
const pipelineId = useStore(s => s.pipelineId)
|
||||||
|
const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel)
|
||||||
|
|
||||||
const viewHistoryProps = useMemo(() => {
|
const viewHistoryProps = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
historyUrl: '',
|
historyUrl: `/rag/pipelines/${pipelineId}/workflow-runs`,
|
||||||
// historyUrl: `/rag/pipeline/${pipelineId}/workflow-runs`,
|
|
||||||
historyFetcher: fetchWorkflowRunHistory,
|
historyFetcher: fetchWorkflowRunHistory,
|
||||||
}
|
}
|
||||||
}, [pipelineId])
|
}, [pipelineId])
|
||||||
|
|
||||||
|
const handleStopRun = useCallback(() => {
|
||||||
|
const { setShowDebugAndPreviewPanel } = workflowStore.getState()
|
||||||
|
setShowDebugAndPreviewPanel(false)
|
||||||
|
}, [workflowStore])
|
||||||
|
|
||||||
const headerProps: HeaderProps = useMemo(() => {
|
const headerProps: HeaderProps = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
normal: {
|
normal: {
|
||||||
@ -31,13 +41,15 @@ const RagPipelineHeader = () => {
|
|||||||
showRunButton: true,
|
showRunButton: true,
|
||||||
runButtonText: 'Test Run',
|
runButtonText: 'Test Run',
|
||||||
viewHistoryProps,
|
viewHistoryProps,
|
||||||
|
isRunning: showDebugAndPreviewPanel,
|
||||||
|
onStopRun: handleStopRun,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
viewHistory: {
|
viewHistory: {
|
||||||
viewHistoryProps,
|
viewHistoryProps,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}, [viewHistoryProps])
|
}, [viewHistoryProps, showDebugAndPreviewPanel, handleStopRun])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Header {...headerProps} />
|
<Header {...headerProps} />
|
||||||
|
|||||||
@ -93,8 +93,8 @@ export const useNodesSyncDraft = () => {
|
|||||||
) => {
|
) => {
|
||||||
if (getNodesReadOnly())
|
if (getNodesReadOnly())
|
||||||
return
|
return
|
||||||
const postParams = getPostParams()
|
|
||||||
|
|
||||||
|
const postParams = getPostParams()
|
||||||
if (postParams) {
|
if (postParams) {
|
||||||
const {
|
const {
|
||||||
setSyncWorkflowDraftHash,
|
setSyncWorkflowDraftHash,
|
||||||
|
|||||||
@ -1,21 +1,16 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import { useStoreApi } from 'reactflow'
|
|
||||||
import { useWorkflowStore } from '@/app/components/workflow/store'
|
import { useWorkflowStore } from '@/app/components/workflow/store'
|
||||||
import {
|
import {
|
||||||
BlockEnum,
|
|
||||||
WorkflowRunningStatus,
|
WorkflowRunningStatus,
|
||||||
} from '@/app/components/workflow/types'
|
} from '@/app/components/workflow/types'
|
||||||
import { useWorkflowInteractions } from '@/app/components/workflow/hooks'
|
import { useWorkflowInteractions } from '@/app/components/workflow/hooks'
|
||||||
import {
|
import {
|
||||||
useNodesSyncDraft,
|
useNodesSyncDraft,
|
||||||
usePipelineRun,
|
|
||||||
} from '.'
|
} from '.'
|
||||||
|
|
||||||
export const usePipelineStartRun = () => {
|
export const usePipelineStartRun = () => {
|
||||||
const store = useStoreApi()
|
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions()
|
const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions()
|
||||||
const { handleRun } = usePipelineRun()
|
|
||||||
const { doSyncWorkflowDraft } = useNodesSyncDraft()
|
const { doSyncWorkflowDraft } = useNodesSyncDraft()
|
||||||
|
|
||||||
const handleWorkflowStartRunInWorkflow = useCallback(async () => {
|
const handleWorkflowStartRunInWorkflow = useCallback(async () => {
|
||||||
@ -26,13 +21,8 @@ export const usePipelineStartRun = () => {
|
|||||||
if (workflowRunningData?.result.status === WorkflowRunningStatus.Running)
|
if (workflowRunningData?.result.status === WorkflowRunningStatus.Running)
|
||||||
return
|
return
|
||||||
|
|
||||||
const { getNodes } = store.getState()
|
|
||||||
const nodes = getNodes()
|
|
||||||
const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
|
|
||||||
const startVariables = startNode?.data.variables || []
|
|
||||||
const {
|
const {
|
||||||
showDebugAndPreviewPanel,
|
showDebugAndPreviewPanel,
|
||||||
setShowInputsPanel,
|
|
||||||
setShowEnvPanel,
|
setShowEnvPanel,
|
||||||
setShowDebugAndPreviewPanel,
|
setShowDebugAndPreviewPanel,
|
||||||
} = workflowStore.getState()
|
} = workflowStore.getState()
|
||||||
@ -44,17 +34,9 @@ export const usePipelineStartRun = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!startVariables.length) {
|
|
||||||
await doSyncWorkflowDraft()
|
await doSyncWorkflowDraft()
|
||||||
handleRun({ inputs: {}, files: [] })
|
|
||||||
setShowDebugAndPreviewPanel(true)
|
setShowDebugAndPreviewPanel(true)
|
||||||
setShowInputsPanel(false)
|
}, [workflowStore, handleCancelDebugAndPreviewPanel, doSyncWorkflowDraft])
|
||||||
}
|
|
||||||
else {
|
|
||||||
setShowDebugAndPreviewPanel(true)
|
|
||||||
setShowInputsPanel(true)
|
|
||||||
}
|
|
||||||
}, [store, workflowStore, handleCancelDebugAndPreviewPanel, handleRun, doSyncWorkflowDraft])
|
|
||||||
|
|
||||||
const handleStartWorkflowRun = useCallback(() => {
|
const handleStartWorkflowRun = useCallback(() => {
|
||||||
handleWorkflowStartRunInWorkflow()
|
handleWorkflowStartRunInWorkflow()
|
||||||
|
|||||||
@ -21,30 +21,36 @@ import {
|
|||||||
|
|
||||||
type RunModeProps = {
|
type RunModeProps = {
|
||||||
text?: string
|
text?: string
|
||||||
|
isRunning?: boolean
|
||||||
|
onStopRun?: () => void
|
||||||
}
|
}
|
||||||
const RunMode = memo(({
|
const RunMode = memo(({
|
||||||
text,
|
text,
|
||||||
|
isRunning: running,
|
||||||
|
onStopRun,
|
||||||
}: RunModeProps) => {
|
}: RunModeProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun()
|
const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun()
|
||||||
const { handleStopRun } = useWorkflowRun()
|
const { handleStopRun } = useWorkflowRun()
|
||||||
const workflowRunningData = useStore(s => s.workflowRunningData)
|
const workflowRunningData = useStore(s => s.workflowRunningData)
|
||||||
const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running
|
const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running
|
||||||
|
const mergedRunning = isRunning || running
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex h-7 items-center rounded-md px-2.5 text-[13px] font-medium text-components-button-secondary-accent-text',
|
'flex h-7 items-center px-2.5 text-[13px] font-medium text-components-button-secondary-accent-text',
|
||||||
'cursor-pointer hover:bg-state-accent-hover',
|
'cursor-pointer hover:bg-state-accent-hover',
|
||||||
isRunning && '!cursor-not-allowed bg-state-accent-hover',
|
mergedRunning && 'cursor-not-allowed bg-state-accent-hover',
|
||||||
|
mergedRunning ? 'rounded-l-md' : 'rounded-md',
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleWorkflowStartRunInWorkflow()
|
handleWorkflowStartRunInWorkflow()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
isRunning
|
mergedRunning
|
||||||
? (
|
? (
|
||||||
<>
|
<>
|
||||||
<RiLoader2Line className='mr-1 h-4 w-4 animate-spin' />
|
<RiLoader2Line className='mr-1 h-4 w-4 animate-spin' />
|
||||||
@ -60,12 +66,14 @@ const RunMode = memo(({
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
isRunning && (
|
mergedRunning && (
|
||||||
<div
|
<div
|
||||||
className='ml-0.5 flex h-7 w-7 cursor-pointer items-center justify-center rounded-md hover:bg-black/5'
|
className={cn(
|
||||||
onClick={() => handleStopRun(workflowRunningData?.task_id || '')}
|
'ml-[1px] flex h-7 w-7 cursor-pointer items-center justify-center rounded-r-md bg-state-accent-active',
|
||||||
|
)}
|
||||||
|
onClick={() => onStopRun ? onStopRun() : handleStopRun(workflowRunningData?.task_id || '')}
|
||||||
>
|
>
|
||||||
<StopCircle className='h-4 w-4 text-components-button-ghost-text' />
|
<StopCircle className='h-4 w-4 text-text-accent' />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -94,12 +102,16 @@ const PreviewMode = memo(() => {
|
|||||||
export type RunAndHistoryProps = {
|
export type RunAndHistoryProps = {
|
||||||
showRunButton?: boolean
|
showRunButton?: boolean
|
||||||
runButtonText?: string
|
runButtonText?: string
|
||||||
|
isRunning?: boolean
|
||||||
|
onStopRun?: () => void
|
||||||
showPreviewButton?: boolean
|
showPreviewButton?: boolean
|
||||||
viewHistoryProps?: ViewHistoryProps
|
viewHistoryProps?: ViewHistoryProps
|
||||||
}
|
}
|
||||||
const RunAndHistory = ({
|
const RunAndHistory = ({
|
||||||
showRunButton,
|
showRunButton,
|
||||||
runButtonText,
|
runButtonText,
|
||||||
|
isRunning,
|
||||||
|
onStopRun,
|
||||||
showPreviewButton,
|
showPreviewButton,
|
||||||
viewHistoryProps,
|
viewHistoryProps,
|
||||||
}: RunAndHistoryProps) => {
|
}: RunAndHistoryProps) => {
|
||||||
@ -108,7 +120,7 @@ const RunAndHistory = ({
|
|||||||
return (
|
return (
|
||||||
<div className='flex h-8 items-center rounded-lg border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg px-0.5 shadow-xs'>
|
<div className='flex h-8 items-center rounded-lg border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg px-0.5 shadow-xs'>
|
||||||
{
|
{
|
||||||
showRunButton && <RunMode text={runButtonText} />
|
showRunButton && <RunMode text={runButtonText} isRunning={isRunning} onStopRun={onStopRun} />
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
showPreviewButton && <PreviewMode />
|
showPreviewButton && <PreviewMode />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user