From a6bbcaf6d14ef392136c749f0c8536c99073b1ce Mon Sep 17 00:00:00 2001 From: r-dev Date: Mon, 6 Apr 2026 17:09:40 +0200 Subject: [PATCH] fix(custom-fields) : masquer les champs machineContextOnly hors vue machine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajoute context: 'standalone' aux appels useCustomFieldInputs dans les vues composant, pièce et produit (création et édition) pour filtrer les champs perso réservés au contexte machine. Exclut également ces champs de la formule de référence automatique dans le ReferenceFormulaBuilder des catégories. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../app/components/model-types/ModelTypeForm.vue | 13 +++++++------ frontend/app/composables/useComponentCreate.ts | 1 + frontend/app/composables/useComponentEdit.ts | 2 ++ frontend/app/composables/usePieceEdit.ts | 2 ++ frontend/app/pages/pieces/create.vue | 8 ++++++++ frontend/app/pages/product/[id]/index.vue | 8 ++++++-- frontend/app/pages/product/create.vue | 7 ++++++- 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/frontend/app/components/model-types/ModelTypeForm.vue b/frontend/app/components/model-types/ModelTypeForm.vue index 83c365c..25987ab 100644 --- a/frontend/app/components/model-types/ModelTypeForm.vue +++ b/frontend/app/components/model-types/ModelTypeForm.vue @@ -194,15 +194,16 @@ const form = reactive({ }) const formulaBuilderCustomFields = computed(() => { + let fields: any[] = [] if (form.category === 'PIECE') { - const fields = pieceStructure.value?.customFields - return Array.isArray(fields) ? fields : [] + const raw = pieceStructure.value?.customFields + fields = Array.isArray(raw) ? raw : [] } - if (form.category === 'COMPONENT') { - const fields = componentStructure.value?.customFields - return Array.isArray(fields) ? fields : [] + else if (form.category === 'COMPONENT') { + const raw = componentStructure.value?.customFields + fields = Array.isArray(raw) ? raw : [] } - return [] + return fields.filter((f: any) => !f.machineContextOnly) }) const extractFormulaFields = (formula: string | null | undefined): string[] => { diff --git a/frontend/app/composables/useComponentCreate.ts b/frontend/app/composables/useComponentCreate.ts index cfd3d92..499c2fe 100644 --- a/frontend/app/composables/useComponentCreate.ts +++ b/frontend/app/composables/useComponentCreate.ts @@ -151,6 +151,7 @@ export function useComponentCreate() { values: computed(() => []), entityType: 'composant', entityId: createdComponentId, + context: 'standalone', }) const structureHasRequirements = computed(() => diff --git a/frontend/app/composables/useComponentEdit.ts b/frontend/app/composables/useComponentEdit.ts index f24db16..104d4f8 100644 --- a/frontend/app/composables/useComponentEdit.ts +++ b/frontend/app/composables/useComponentEdit.ts @@ -209,6 +209,7 @@ export function useComponentEdit(componentId: string) { values: computed(() => component.value?.customFieldValues ?? []), entityType: 'composant', entityId: computed(() => component.value?.id ?? null), + context: 'standalone', onValueCreated: (newValue) => { if (component.value && Array.isArray(component.value.customFieldValues)) { component.value.customFieldValues.push(newValue) @@ -556,6 +557,7 @@ export function useComponentEdit(componentId: string) { originalConstructeurLinks, constructeurIdsFromForm, customFieldInputs, + requiredCustomFieldsFilled, historyFieldLabels, // Computed diff --git a/frontend/app/composables/usePieceEdit.ts b/frontend/app/composables/usePieceEdit.ts index b5ad95b..5b49d1c 100644 --- a/frontend/app/composables/usePieceEdit.ts +++ b/frontend/app/composables/usePieceEdit.ts @@ -99,6 +99,7 @@ export function usePieceEdit(pieceId: string) { values: computed(() => piece.value?.customFieldValues ?? []), entityType: 'piece', entityId: computed(() => piece.value?.id ?? null), + context: 'standalone', onValueCreated: (newValue) => { if (piece.value && Array.isArray(piece.value.customFieldValues)) { piece.value.customFieldValues.push(newValue) @@ -435,6 +436,7 @@ export function usePieceEdit(pieceId: string) { constructeurIdsFromForm, productSelections, customFieldInputs, + requiredCustomFieldsFilled, canEdit, // Computed diff --git a/frontend/app/pages/pieces/create.vue b/frontend/app/pages/pieces/create.vue index 9013a2d..c0780f8 100644 --- a/frontend/app/pages/pieces/create.vue +++ b/frontend/app/pages/pieces/create.vue @@ -218,6 +218,9 @@

+

+ Certains champs personnalisés sont obligatoires. Veuillez les renseigner avant de valider. +

+

+ Merci de renseigner tous les champs personnalisés obligatoires avant de créer la pièce. +

@@ -311,7 +317,9 @@ const { fields: customFieldInputs, requiredFilled: requiredCustomFieldsFilled, s values: [] as any[], entityType: 'piece' as CustomFieldEntityType, entityId: createdEntityId, + context: 'standalone', }) +const hasRequiredCustomFields = computed(() => customFieldInputs.value.some(f => f.required)) const selectedDocuments = ref([]) const uploadingDocuments = ref(false) diff --git a/frontend/app/pages/product/[id]/index.vue b/frontend/app/pages/product/[id]/index.vue index 2099ae1..1ba844c 100644 --- a/frontend/app/pages/product/[id]/index.vue +++ b/frontend/app/pages/product/[id]/index.vue @@ -274,6 +274,9 @@