feat(workflow): enhance validation by integrating warning nodes into last run checks.

This commit is contained in:
zhsama 2025-10-29 01:28:31 +08:00
parent 5c95c77604
commit 66cb963df3
3 changed files with 43 additions and 4 deletions

View File

@ -409,5 +409,6 @@ export const useWorkflowRunValidation = () => {
return {
validateBeforeRun,
hasValidationErrors: needWarningNodes.length > 0,
warningNodes: needWarningNodes,
}
}

View File

@ -22,6 +22,7 @@ import useVariableAssignerSingleRunFormParams from '@/app/components/workflow/no
import useKnowledgeBaseSingleRunFormParams from '@/app/components/workflow/nodes/knowledge-base/use-single-run-form-params'
import useToolGetDataForCheckMore from '@/app/components/workflow/nodes/tool/use-get-data-for-check-more'
import useTriggerPluginGetDataForCheckMore from '@/app/components/workflow/nodes/trigger-plugin/use-check-params'
import { VALUE_SELECTOR_DELIMITER as DELIMITER } from '@/config'
// import
@ -35,6 +36,7 @@ import useInspectVarsCrud from '@/app/components/workflow/hooks/use-inspect-vars
import { useInvalidLastRun } from '@/service/use-workflow'
import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
import { isSupportCustomRunForm } from '@/app/components/workflow/utils'
import Toast from '@/app/components/base/toast'
const singleRunFormParamsHooks: Record<BlockEnum, any> = {
[BlockEnum.LLM]: useLLMSingleRunFormParams,
@ -103,7 +105,7 @@ const getDataForCheckMoreHooks: Record<BlockEnum, any> = {
[BlockEnum.KnowledgeBase]: undefined,
[BlockEnum.TriggerWebhook]: undefined,
[BlockEnum.TriggerSchedule]: undefined,
[BlockEnum.TriggerPlugin]: undefined,
[BlockEnum.TriggerPlugin]: useTriggerPluginGetDataForCheckMore,
}
const useGetDataForCheckMoreHooks = <T>(nodeType: BlockEnum) => {
@ -146,7 +148,16 @@ const useLastRun = <T>({
isRunAfterSingleRun,
})
const { validateBeforeRun } = useWorkflowRunValidation()
const { warningNodes } = useWorkflowRunValidation()
const blockIfChecklistFailed = useCallback(() => {
const warningForNode = warningNodes.find(item => item.id === id)
if (!warningForNode)
return false
const message = warningForNode.errorMessage || 'This node has unresolved checklist issues'
Toast.notify({ type: 'error', message })
return true
}, [warningNodes, id])
const {
hideSingleRun,
@ -220,7 +231,7 @@ const useLastRun = <T>({
const invalidLastRun = useInvalidLastRun(flowType, flowId, id)
const handleRunWithParams = async (data: Record<string, any>) => {
if (!validateBeforeRun())
if (blockIfChecklistFailed())
return
const { isValid } = checkValid()
if (!isValid)
@ -320,7 +331,7 @@ const useLastRun = <T>({
}
const handleSingleRun = () => {
if (!validateBeforeRun())
if (blockIfChecklistFailed())
return
const { isValid } = checkValid()
if (!isValid)

View File

@ -0,0 +1,27 @@
import { useCallback } from 'react'
import type { PluginTriggerNodeType } from './types'
import { useAllTriggerPlugins } from '@/service/use-triggers'
import { useGetLanguage } from '@/context/i18n'
import { getTriggerCheckParams } from '@/app/components/workflow/utils/trigger'
type Params = {
id: string
payload: PluginTriggerNodeType
}
const useGetDataForCheckMore = ({
payload,
}: Params) => {
const { data: triggerPlugins } = useAllTriggerPlugins()
const language = useGetLanguage()
const getData = useCallback(() => {
return getTriggerCheckParams(payload, triggerPlugins, language)
}, [payload, triggerPlugins, language])
return {
getData,
}
}
export default useGetDataForCheckMore