Skip to content

Commit fcc590c

Browse files
authored
improvement(deployed preview): fixed webhook config that was causing workflow failure in deployed state (#332)
* solved the error for deployed workflow * updated webhook-config to update DB upon webhook deletion
1 parent 01e9016 commit fcc590c

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

sim/app/w/[id]/components/workflow-block/components/sub-block/components/webhook/webhook-config.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { Button } from '@/components/ui/button'
1414
import { createLogger } from '@/lib/logs/console-logger'
1515
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
16+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1617
import { useSubBlockValue } from '../../hooks/use-sub-block-value'
1718
import { WebhookModal } from './components/webhook-modal'
1819

@@ -412,11 +413,36 @@ export function WebhookConfig({ blockId, subBlockId, isConnecting }: WebhookConf
412413
throw new Error(errorData.error || 'Failed to delete webhook')
413414
}
414415

415-
// Clear the webhook ID and actual provider
416+
// Reset the startWorkflow field to manual
417+
useSubBlockStore.getState().setValue(blockId, 'startWorkflow', 'manual')
418+
419+
// Remove webhook-specific fields from the block state
420+
const store = useSubBlockStore.getState()
421+
const workflowValues = store.workflowValues[workflowId] || {}
422+
const blockValues = { ...workflowValues[blockId] }
423+
424+
// Remove webhook-related fields
425+
delete blockValues.webhookProvider
426+
delete blockValues.providerConfig
427+
blockValues.webhookPath = ''
428+
429+
// Update the store with the cleaned block values
430+
store.setValue(blockId, 'startWorkflow', 'manual')
431+
useSubBlockStore.setState({
432+
workflowValues: {
433+
...workflowValues,
434+
[workflowId]: {
435+
...workflowValues,
436+
[blockId]: blockValues
437+
}
438+
}
439+
})
440+
441+
// Clear component state
416442
setWebhookId(null)
417443
setActualProvider(null)
418444

419-
// Set active webhook flag to false after deletion
445+
// Set active webhook flag to false
420446
setWebhookStatus(false)
421447
handleCloseModal()
422448

sim/app/w/components/workflow-preview/generic-workflow-preview.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ function PreviewSubBlock({ config }: { config: ExtendedSubBlockConfig }) {
134134
case 'short-input':
135135
return (
136136
<div className="h-7 rounded-md border border-input bg-background px-3 py-1.5 text-xs text-muted-foreground">
137-
{config.password ? '**********************' : (config.value || config.placeholder || 'Text input')}
137+
{config.password ? '**********************' :
138+
(config.id === 'providerConfig' && config.value && typeof config.value === 'object')
139+
? (Object.keys(config.value).length === 0 ? 'Webhook pending configuration' : 'Webhook configured')
140+
: (config.value || config.placeholder || 'Text input')
141+
}
138142
</div>
139143
)
140144
case 'long-input':

sim/stores/workflows/workflow/store.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,42 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
677677
loops: deployedState.loops,
678678
isDeployed: true,
679679
needsRedeployment: false,
680+
hasActiveWebhook: false // Reset webhook status
680681
}
681682

683+
// Update the main workflow state
682684
set(newState)
685+
686+
// Get the active workflow ID
687+
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
688+
if (!activeWorkflowId) return
689+
690+
// Initialize subblock store with values from deployed state
691+
const subBlockStore = useSubBlockStore.getState()
692+
const values: Record<string, Record<string, any>> = {}
693+
694+
// Extract subblock values from deployed blocks
695+
Object.entries(deployedState.blocks).forEach(([blockId, block]) => {
696+
values[blockId] = {}
697+
Object.entries(block.subBlocks || {}).forEach(([subBlockId, subBlock]) => {
698+
values[blockId][subBlockId] = subBlock.value
699+
})
700+
})
701+
702+
// Update subblock store with deployed values
703+
useSubBlockStore.setState({
704+
workflowValues: {
705+
...subBlockStore.workflowValues,
706+
[activeWorkflowId]: values
707+
}
708+
})
709+
710+
// Check if there's an active webhook in the deployed state
711+
const starterBlock = Object.values(deployedState.blocks).find(block => block.type === 'starter')
712+
if (starterBlock && starterBlock.subBlocks?.startWorkflow?.value === 'webhook') {
713+
set({ hasActiveWebhook: true })
714+
}
715+
683716
pushHistory(set, get, newState, 'Reverted to deployed state')
684717
get().updateLastSaved()
685718
workflowSync.sync()

0 commit comments

Comments
 (0)