fix(custom-fields) : preserve CustomField ID in piece structure payload

Prevents data loss when saving ModelType: the frontend now sends existing
CustomField IDs so the backend can match them instead of deleting and recreating.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-17 19:07:37 +01:00
parent 53530dc16d
commit db630e315b
3 changed files with 11 additions and 0 deletions

View File

@@ -158,6 +158,13 @@ const buildPayload = (
orderIndex: index,
}
if (field.id) {
payload.id = field.id
}
if (field.customFieldId) {
payload.customFieldId = field.customFieldId
}
if (type === 'select') {
const options = normalizeLineEndings(field.optionsText)
.split('\n')

View File

@@ -125,6 +125,8 @@ const hydratePieceCustomFields = (fields: any[]): PieceModelStructureEditorField
? field.options.join('\n')
: '',
orderIndex: typeof field?.orderIndex === 'number' ? field.orderIndex : index,
...(field?.id ? { id: field.id } : {}),
...(field?.customFieldId ? { customFieldId: field.customFieldId } : {}),
}))
}

View File

@@ -61,6 +61,8 @@ export interface PieceModelCustomField {
key?: string
value?: unknown
defaultValue?: string | null
id?: string
customFieldId?: string
}
export interface PieceModelProduct {