| 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 { | ||||
| useWorkflowStore, | useWorkflowStore, | ||||
| } from '@/app/components/workflow/store' | } from '@/app/components/workflow/store' | ||||
| import { | import { | ||||
| useChecklist, | |||||
| useChecklistBeforePublish, | useChecklistBeforePublish, | ||||
| useNodesReadOnly, | useNodesReadOnly, | ||||
| useNodesSyncDraft, | useNodesSyncDraft, | ||||
| 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, | ||||
| } | } | ||||
| }, [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 || '', | ||||
| 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) |