Skip to content

Commit

Permalink
fix(ui): unique ids for nested rows on row duplicate to prevent error…
Browse files Browse the repository at this point in the history
…s with postgres (#8790)

Fixes #8784

This works for any deep level, both arrays and blocks.
  • Loading branch information
r1tsuu committed Oct 21, 2024
1 parent e5d6cda commit 1ed66aa
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ export function fieldReducer(state: Fields, action: FieldAction): Fields {
const duplicateRowState = deepCopyObject(rows[rowIndex])
if (duplicateRowState.id) duplicateRowState.id = new ObjectID().toHexString()

for (const key of Object.keys(duplicateRowState).filter((key) => key.endsWith('.id'))) {
const idState = duplicateRowState[key]

if (idState && typeof idState.value === 'string' && ObjectId.isValid(idState.value)) {
duplicateRowState[key].value = new ObjectId().toHexString()
duplicateRowState[key].initialValue = new ObjectId().toHexString()
}
}

// If there are subfields
if (Object.keys(duplicateRowState).length > 0) {
// Add new object containing subfield names to unflattenedRows array
Expand Down

0 comments on commit 1ed66aa

Please sign in to comment.