Home / Function/ resolveEditCellConflicts() — supabase Function Reference

resolveEditCellConflicts() — supabase Function Reference

Architecture documentation for the resolveEditCellConflicts() function in queueConflictResolution.ts from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/studio/components/grid/utils/queueConflictResolution.ts lines 84–141

export function resolveEditCellConflicts(
  operations: readonly QueuedOperation[],
  editOperation: NewEditCellContentOperation
): EditConflictResult {
  const rowIdentifiers = editOperation.payload.rowIdentifiers

  // Check if this row is pending deletion
  const isPendingDeletion = operations.filter(isDeleteRowOperation).some((op) => {
    if (op.tableId === editOperation.tableId) {
      return Object.entries(op.payload.rowIdentifiers).every(
        ([key, value]) => rowIdentifiers[key] === value
      )
    }
    return false
  })

  if (isPendingDeletion) {
    return {
      action: 'reject',
      reason:
        'Cannot edit a cell on a row that is pending deletion. Remove the delete operation first.',
    }
  }

  // Check if this edit is on a newly added row (by tempId)
  const tempId = rowIdentifiers.__tempId
  if (tempId) {
    const addRowIndex = operations.findIndex((op) => {
      if (op.type === QueuedOperationType.ADD_ROW && op.tableId === editOperation.tableId) {
        return op.payload.tempId === tempId
      }
      return false
    })

    if (addRowIndex >= 0) {
      // Merge the edit into the ADD_ROW's rowData
      const updatedOperations = [...operations]
      const addOp = updatedOperations[addRowIndex]
      if (addOp.type === QueuedOperationType.ADD_ROW) {
        const addPayload = { ...addOp.payload }
        addPayload.rowData = {
          ...addPayload.rowData,
          [editOperation.payload.columnName]: editOperation.payload.newValue,
        }

        updatedOperations[addRowIndex] = {
          ...addOp,
          payload: addPayload,
          timestamp: Date.now(),
        }
      }

      return { action: 'merge', updatedOperations }
    }
  }

  return { action: 'add' }
}

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free