* Drops a failed operation whose target entity no longer exists locally (e.g. it * was removed by a remote collaborator while the operation was in flight), so a * stale per-entity failure does not trip offline mode. Applies only to block-, * subblock-, subflow-, and variable-scoped operations; st
(operation: QueuedOperation)
| 80 | * to offline mode. Returns true when the operation was dropped. |
| 81 | */ |
| 82 | function dropOperationForMissingTarget(operation: QueuedOperation): boolean { |
| 83 | const { target, payload } = operation.operation |
| 84 | |
| 85 | const isVariableOperation = target === 'variable' |
| 86 | if (!isVariableOperation && !BLOCK_SCOPED_TARGETS.includes(target)) { |
| 87 | return false |
| 88 | } |
| 89 | |
| 90 | const targetId = isVariableOperation |
| 91 | ? payload?.variableId || payload?.id |
| 92 | : payload?.blockId || payload?.id |
| 93 | const targetStillPresent = isVariableOperation |
| 94 | ? isVariableStillPresent(targetId) |
| 95 | : isBlockStillPresent(targetId) |
| 96 | |
| 97 | if (!targetId || targetStillPresent) { |
| 98 | return false |
| 99 | } |
| 100 | |
| 101 | logger.debug( |
| 102 | isVariableOperation |
| 103 | ? 'Dropping failed operation for deleted variable' |
| 104 | : 'Dropping failed operation for deleted block', |
| 105 | { |
| 106 | operationId: operation.id, |
| 107 | targetId, |
| 108 | } |
| 109 | ) |
| 110 | useOperationQueueStore.setState((s) => ({ |
| 111 | operations: s.operations.filter((op) => op.id !== operation.id), |
| 112 | isProcessing: false, |
| 113 | })) |
| 114 | useOperationQueueStore.getState().processNextOperation() |
| 115 | return true |
| 116 | } |
| 117 | |
| 118 | export const useOperationQueueStore = create<OperationQueueState>((set, get) => ({ |
| 119 | operations: [], |
no test coverage detected