fix: validate checklist before publishing workflow (#24104)

This commit is contained in:
-LAN-
2025-08-18 16:46:22 +08:00
committed by GitHub
parent 8288b1dcab
commit 4445460eca

View File

@@ -3,7 +3,7 @@ import {
useCallback, useCallback,
useMemo, useMemo,
} from 'react' } from 'react'
import { useStore as useReactflowStore } from 'reactflow' import { useEdges, useNodes, useStore as useReactflowStore } from 'reactflow'
import { RiApps2AddLine } from '@remixicon/react' import { RiApps2AddLine } from '@remixicon/react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { import {
@@ -11,6 +11,7 @@ import {
useWorkflowStore, useWorkflowStore,
} from '@/app/components/workflow/store' } from '@/app/components/workflow/store'
import { import {
useChecklist,
useChecklistBeforePublish, useChecklistBeforePublish,
useNodesReadOnly, useNodesReadOnly,
useNodesSyncDraft, useNodesSyncDraft,
@@ -18,6 +19,10 @@ import {
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import AppPublisher from '@/app/components/app/app-publisher' import AppPublisher from '@/app/components/app/app-publisher'
import { useFeatures } from '@/app/components/base/features/hooks' import { useFeatures } from '@/app/components/base/features/hooks'
import type {
CommonEdgeType,
CommonNodeType,
} from '@/app/components/workflow/types'
import { import {
BlockEnum, BlockEnum,
InputVarType, InputVarType,
@@ -92,8 +97,19 @@ const FeaturesTrigger = () => {
} }
}, [appID, setAppDetail]) }, [appID, setAppDetail])
const { mutateAsync: publishWorkflow } = usePublishWorkflow(appID!) const { mutateAsync: publishWorkflow } = usePublishWorkflow(appID!)
const nodes = useNodes<CommonNodeType>()
const edges = useEdges<CommonEdgeType>()
const needWarningNodes = useChecklist(nodes, edges)
const updatePublishedWorkflow = useInvalidateAppWorkflow() const updatePublishedWorkflow = useInvalidateAppWorkflow()
const onPublish = useCallback(async (params?: PublishWorkflowParams) => { 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()) { if (await handleCheckBeforePublish()) {
const res = await publishWorkflow({ const res = await publishWorkflow({
title: params?.title || '', title: params?.title || '',
@@ -111,7 +127,7 @@ const FeaturesTrigger = () => {
else { else {
throw new Error('Checklist failed') 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) => { const onPublisherToggle = useCallback((state: boolean) => {
if (state) if (state)