Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: validate checklist before publishing workflow (#24104)

-LAN-4445460eca7e
diff --git a/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx b/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx
index c7455f1b1b4..9ad2a3334e5 100644
--- a/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx
+++ b/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx
@@ -3,7 +3,7 @@ import {
useCallback,
useMemo,
} from 'react'
-import { useStore as useReactflowStore } from 'reactflow'
+import { useEdges, useNodes, useStore as useReactflowStore } from 'reactflow'
import { RiApps2AddLine } from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import {
@@ -11,6 +11,7 @@ import {
useWorkflowStore,
} from '@/app/components/workflow/store'
import {
+ useChecklist,
useChecklistBeforePublish,
useNodesReadOnly,
useNodesSyncDraft,
@@ -18,6 +19,10 @@ import {
import Button from '@/app/components/base/button'
import AppPublisher from '@/app/components/app/app-publisher'
import { useFeatures } from '@/app/components/base/features/hooks'
+import type {
+ CommonEdgeType,
+ CommonNodeType,
+} from '@/app/components/workflow/types'
import {
BlockEnum,
InputVarType,
@@ -92,8 +97,19 @@ const FeaturesTrigger = () => {
}
}, [appID, setAppDetail])
const { mutateAsync: publishWorkflow } = usePublishWorkflow(appID!)
+ const nodes = useNodes<CommonNodeType>()
+ const edges = useEdges<CommonEdgeType>()
+ const needWarningNodes = useChecklist(nodes, edges)
+
const updatePublishedWorkflow = useInvalidateAppWorkflow()
const onPublish = useCallback(async (params?: PublishWorkflowParams) => {
+ // First check if there are any items in the checklist
+ if (needWarningNodes.length > 0) {
+ notify({ type: 'error', message: t('workflow.panel.checklistTip') })
+ throw new Error('Checklist has unresolved items')
+ }
+
+ // Then perform the detailed validation
if (await handleCheckBeforePublish()) {
const res = await publishWorkflow({
title: params?.title || '',
@@ -111,7 +127,7 @@ const FeaturesTrigger = () => {
else {
throw new Error('Checklist failed')
}
- }, [handleCheckBeforePublish, publishWorkflow, notify, t, updatePublishedWorkflow, appID, updateAppDetail, workflowStore, resetWorkflowVersionHistory])
+ }, [needWarningNodes, handleCheckBeforePublish, publishWorkflow, notify, t, updatePublishedWorkflow, appID, updateAppDetail, workflowStore, resetWorkflowVersionHistory])
const onPublisherToggle = useCallback((state: boolean) => {
if (state)