From db630e315b2a5bd3ccd89abaa1c3bce1f9a78ef5 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 17 Mar 2026 19:07:37 +0100 Subject: [PATCH] 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) --- app/composables/usePieceStructureEditorLogic.ts | 7 +++++++ app/shared/model/pieceProductStructure.ts | 2 ++ app/shared/types/inventory.ts | 2 ++ 3 files changed, 11 insertions(+) diff --git a/app/composables/usePieceStructureEditorLogic.ts b/app/composables/usePieceStructureEditorLogic.ts index 3bb7a3f..4d610fe 100644 --- a/app/composables/usePieceStructureEditorLogic.ts +++ b/app/composables/usePieceStructureEditorLogic.ts @@ -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') diff --git a/app/shared/model/pieceProductStructure.ts b/app/shared/model/pieceProductStructure.ts index a7dff65..8e2368e 100644 --- a/app/shared/model/pieceProductStructure.ts +++ b/app/shared/model/pieceProductStructure.ts @@ -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 } : {}), })) } diff --git a/app/shared/types/inventory.ts b/app/shared/types/inventory.ts index e12549a..1a531d6 100644 --- a/app/shared/types/inventory.ts +++ b/app/shared/types/inventory.ts @@ -61,6 +61,8 @@ export interface PieceModelCustomField { key?: string value?: unknown defaultValue?: string | null + id?: string + customFieldId?: string } export interface PieceModelProduct {