Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apps/sim/app/w/[id]/hooks/use-workflow-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { useGeneralStore } from '@/stores/settings/general/store'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { mergeSubblockState } from '@/stores/workflows/utils'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
import { getBlock } from '@/blocks'
import { Executor } from '@/executor'
import { ExecutionResult } from '@/executor/types'
import { Serializer } from '@/serializer'
import { useSubBlockStore } from '@/stores/workflows'

const logger = createLogger('useWorkflowExecution')

Expand All @@ -27,6 +29,7 @@ export function useWorkflowExecution() {
const { getAllVariables } = useEnvironmentStore()
const { isDebugModeEnabled } = useGeneralStore()
const { getVariablesByWorkflowId, variables } = useVariablesStore()
const { getValue } = useSubBlockStore();
const {
isExecuting,
isDebugging,
Expand Down Expand Up @@ -100,10 +103,35 @@ export function useWorkflowExecution() {
}
}

const handleCheckRequiredFieldsOfAllBlocks = useCallback(() => {
for (const [blockKey, value] of Object.entries(blocks)) {
if(value.type === "starter") continue;

const currentBlockConfig = getBlock(value.type);
const currentBlockConfigInputs = currentBlockConfig?.inputs


for (const [key, val] of Object.entries(currentBlockConfigInputs || {})) {
const currVal = getValue(blockKey, key);

if (val.required && ((typeof(currVal) === "string") ? currVal.length === 0 : currVal === null)) {
const keySubBlock = currentBlockConfig?.subBlocks.find((sub) => sub.id == key);
addNotification('error', `"${keySubBlock?.title}" is required for "${value.name}" block.`, activeWorkflowId)
return false
}
}
}


return true;
}, [blocks, getBlock, getValue, addNotification, activeWorkflowId])

const handleRunWorkflow = useCallback(
async (workflowInput?: any) => {
if (!activeWorkflowId) return

if (!handleCheckRequiredFieldsOfAllBlocks()) return

// Reset execution result and set execution state
setExecutionResult(null)
setIsExecuting(true)
Expand Down