diff --git a/web/app/components/rag-pipeline/components/rag-pipeline-header/index.tsx b/web/app/components/rag-pipeline/components/rag-pipeline-header/index.tsx index 02479e2198..d614ac8173 100644 --- a/web/app/components/rag-pipeline/components/rag-pipeline-header/index.tsx +++ b/web/app/components/rag-pipeline/components/rag-pipeline-header/index.tsx @@ -1,25 +1,35 @@ import { memo, + useCallback, useMemo, } from 'react' import type { HeaderProps } from '@/app/components/workflow/header' import Header from '@/app/components/workflow/header' 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 Publisher from './publisher' const RagPipelineHeader = () => { + const workflowStore = useWorkflowStore() const pipelineId = useStore(s => s.pipelineId) + const showDebugAndPreviewPanel = useStore(s => s.showDebugAndPreviewPanel) const viewHistoryProps = useMemo(() => { return { - historyUrl: '', - // historyUrl: `/rag/pipeline/${pipelineId}/workflow-runs`, + historyUrl: `/rag/pipelines/${pipelineId}/workflow-runs`, historyFetcher: fetchWorkflowRunHistory, } }, [pipelineId]) + const handleStopRun = useCallback(() => { + const { setShowDebugAndPreviewPanel } = workflowStore.getState() + setShowDebugAndPreviewPanel(false) + }, [workflowStore]) + const headerProps: HeaderProps = useMemo(() => { return { normal: { @@ -31,13 +41,15 @@ const RagPipelineHeader = () => { showRunButton: true, runButtonText: 'Test Run', viewHistoryProps, + isRunning: showDebugAndPreviewPanel, + onStopRun: handleStopRun, }, }, viewHistory: { viewHistoryProps, }, } - }, [viewHistoryProps]) + }, [viewHistoryProps, showDebugAndPreviewPanel, handleStopRun]) return (
diff --git a/web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.ts b/web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.ts index 798bda4dda..eb2a862be6 100644 --- a/web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.ts +++ b/web/app/components/rag-pipeline/hooks/use-nodes-sync-draft.ts @@ -93,8 +93,8 @@ export const useNodesSyncDraft = () => { ) => { if (getNodesReadOnly()) return - const postParams = getPostParams() + const postParams = getPostParams() if (postParams) { const { setSyncWorkflowDraftHash, diff --git a/web/app/components/rag-pipeline/hooks/use-pipeline-start-run.tsx b/web/app/components/rag-pipeline/hooks/use-pipeline-start-run.tsx index ea1add4233..38538109e4 100644 --- a/web/app/components/rag-pipeline/hooks/use-pipeline-start-run.tsx +++ b/web/app/components/rag-pipeline/hooks/use-pipeline-start-run.tsx @@ -1,21 +1,16 @@ import { useCallback } from 'react' -import { useStoreApi } from 'reactflow' import { useWorkflowStore } from '@/app/components/workflow/store' import { - BlockEnum, WorkflowRunningStatus, } from '@/app/components/workflow/types' import { useWorkflowInteractions } from '@/app/components/workflow/hooks' import { useNodesSyncDraft, - usePipelineRun, } from '.' export const usePipelineStartRun = () => { - const store = useStoreApi() const workflowStore = useWorkflowStore() const { handleCancelDebugAndPreviewPanel } = useWorkflowInteractions() - const { handleRun } = usePipelineRun() const { doSyncWorkflowDraft } = useNodesSyncDraft() const handleWorkflowStartRunInWorkflow = useCallback(async () => { @@ -26,13 +21,8 @@ export const usePipelineStartRun = () => { if (workflowRunningData?.result.status === WorkflowRunningStatus.Running) return - const { getNodes } = store.getState() - const nodes = getNodes() - const startNode = nodes.find(node => node.data.type === BlockEnum.Start) - const startVariables = startNode?.data.variables || [] const { showDebugAndPreviewPanel, - setShowInputsPanel, setShowEnvPanel, setShowDebugAndPreviewPanel, } = workflowStore.getState() @@ -44,17 +34,9 @@ export const usePipelineStartRun = () => { return } - if (!startVariables.length) { - await doSyncWorkflowDraft() - handleRun({ inputs: {}, files: [] }) - setShowDebugAndPreviewPanel(true) - setShowInputsPanel(false) - } - else { - setShowDebugAndPreviewPanel(true) - setShowInputsPanel(true) - } - }, [store, workflowStore, handleCancelDebugAndPreviewPanel, handleRun, doSyncWorkflowDraft]) + await doSyncWorkflowDraft() + setShowDebugAndPreviewPanel(true) + }, [workflowStore, handleCancelDebugAndPreviewPanel, doSyncWorkflowDraft]) const handleStartWorkflowRun = useCallback(() => { handleWorkflowStartRunInWorkflow() diff --git a/web/app/components/workflow/header/run-and-history.tsx b/web/app/components/workflow/header/run-and-history.tsx index cf894052e7..54704cbb30 100644 --- a/web/app/components/workflow/header/run-and-history.tsx +++ b/web/app/components/workflow/header/run-and-history.tsx @@ -21,30 +21,36 @@ import { type RunModeProps = { text?: string + isRunning?: boolean + onStopRun?: () => void } const RunMode = memo(({ text, + isRunning: running, + onStopRun, }: RunModeProps) => { const { t } = useTranslation() const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun() const { handleStopRun } = useWorkflowRun() const workflowRunningData = useStore(s => s.workflowRunningData) const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running + const mergedRunning = isRunning || running return ( <>
{ handleWorkflowStartRunInWorkflow() }} > { - isRunning + mergedRunning ? ( <> @@ -60,12 +66,14 @@ const RunMode = memo(({ }
{ - isRunning && ( + mergedRunning && (
handleStopRun(workflowRunningData?.task_id || '')} + className={cn( + '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 || '')} > - +
) } @@ -94,12 +102,16 @@ const PreviewMode = memo(() => { export type RunAndHistoryProps = { showRunButton?: boolean runButtonText?: string + isRunning?: boolean + onStopRun?: () => void showPreviewButton?: boolean viewHistoryProps?: ViewHistoryProps } const RunAndHistory = ({ showRunButton, runButtonText, + isRunning, + onStopRun, showPreviewButton, viewHistoryProps, }: RunAndHistoryProps) => { @@ -108,7 +120,7 @@ const RunAndHistory = ({ return (
{ - showRunButton && + showRunButton && } { showPreviewButton &&