(data: any)
| 784 | } |
| 785 | |
| 786 | const handleWorkflowUpdated = async (data: any) => { |
| 787 | const { workflowId } = data |
| 788 | logger.info(`Workflow ${workflowId} has been updated externally`) |
| 789 | |
| 790 | if (activeWorkflowId !== workflowId) return |
| 791 | |
| 792 | const diffStore = useWorkflowDiffStore.getState() |
| 793 | const { hasActiveDiff } = diffStore |
| 794 | if (hasActiveDiff) { |
| 795 | logger.info('Deferring workflow-updated: active diff in progress', { workflowId }) |
| 796 | diffStore.markExternalUpdatePending(workflowId) |
| 797 | return |
| 798 | } |
| 799 | |
| 800 | if (diffStore.reconcilingWorkflows[workflowId]) { |
| 801 | logger.info('Deferring workflow-updated: workflow reconciliation is in progress', { |
| 802 | workflowId, |
| 803 | }) |
| 804 | diffStore.markExternalUpdatePending(workflowId) |
| 805 | return |
| 806 | } |
| 807 | |
| 808 | const operationQueue = useOperationQueueStore.getState() |
| 809 | if (operationQueue.hasPendingOperations(workflowId)) { |
| 810 | logger.info('Deferring workflow-updated: local operations are still pending', { |
| 811 | workflowId, |
| 812 | }) |
| 813 | diffStore.markExternalUpdatePending(workflowId) |
| 814 | void operationQueue.waitForWorkflowOperations(workflowId).then((ready) => { |
| 815 | if (!ready) { |
| 816 | const latestQueue = useOperationQueueStore.getState() |
| 817 | if (latestQueue.hasPendingOperations(workflowId) && !latestQueue.hasOperationError) { |
| 818 | return |
| 819 | } |
| 820 | const diffStore = useWorkflowDiffStore.getState() |
| 821 | diffStore.clearExternalUpdatePending(workflowId) |
| 822 | diffStore.setWorkflowReconciliationError( |
| 823 | workflowId, |
| 824 | 'Failed to save local workflow changes before syncing external updates.' |
| 825 | ) |
| 826 | return |
| 827 | } |
| 828 | void replayPendingExternalUpdate(workflowId, 'deferred external update after local save') |
| 829 | }) |
| 830 | return |
| 831 | } |
| 832 | |
| 833 | diffStore.markRemoteUpdateSeen(workflowId) |
| 834 | try { |
| 835 | await reloadWorkflowFromApi(workflowId, 'external update') |
| 836 | } catch (error) { |
| 837 | logger.error('Error reloading workflow state after external update:', error) |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | const handleDiffSettled = async (event: Event) => { |
| 842 | const customEvent = event as CustomEvent<{ workflowId?: string }> |
nothing calls this directly
no test coverage detected