From 6bed715b7f5ec9aec171c623b6587e285fd41ed7 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 18 Feb 2026 10:39:45 +0100 Subject: [PATCH] =?UTF-8?q?fix(machines):=20fix=20skeleton=20creation=20?= =?UTF-8?q?=E2=80=94=20load=20all=20items=20+=20atomic=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Load composants/pieces/products with itemsPerPage: 200 instead of 30 (root cause: only first 30 items were available in creation dropdowns) - Rollback machine if skeleton PATCH fails (delete orphaned machine) - Initialize custom fields after successful machine creation Co-Authored-By: Claude Opus 4.6 --- app/composables/useMachineCreatePage.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/composables/useMachineCreatePage.ts b/app/composables/useMachineCreatePage.ts index cd63389..89af5af 100644 --- a/app/composables/useMachineCreatePage.ts +++ b/app/composables/useMachineCreatePage.ts @@ -34,7 +34,7 @@ export function useMachineCreatePage() { // Composable calls // --------------------------------------------------------------------------- - const { createMachine, createMachineFromType, reconfigureSkeleton } = useMachines() + const { createMachine, createMachineFromType, reconfigureSkeleton, addMissingCustomFields, deleteMachine } = useMachines() const { sites, loadSites } = useSites() const { machineTypes, loadMachineTypes, loading: machineTypesLoading } = useMachineTypesApi() const { composants, loadComposants, loading: composantsLoading } = useComposants() @@ -340,17 +340,24 @@ export function useMachineCreatePage() { : await createMachineFromType(baseMachineData as any, type) if (result.success) { - if (hasRequirements && result.data?.id) { - const skeletonResult: any = await reconfigureSkeleton(result.data.id, { + const machineId = result.data?.id + if (hasRequirements && machineId) { + const skeletonResult: any = await reconfigureSkeleton(machineId, { componentLinks, pieceLinks, productLinks, } as any) if (!skeletonResult.success) { - toast.showError(skeletonResult.error || 'Impossible d\'enregistrer les pièces/composants') + // Rollback: delete the orphaned machine + await deleteMachine(machineId).catch(() => {}) + toast.showError(skeletonResult.error || 'Impossible d\'enregistrer les pièces/composants. La machine n\'a pas été créée.') return } } + // Initialize custom fields for the machine type + if (machineId) { + await addMissingCustomFields(machineId, { showToast: false }).catch(() => {}) + } newMachine.name = '' newMachine.siteId = '' newMachine.typeMachineId = '' @@ -386,9 +393,9 @@ export function useMachineCreatePage() { await Promise.all([ loadSites(), loadMachineTypes(), - loadComposants(), - loadPieces(), - loadProducts(), + loadComposants({ itemsPerPage: 200, force: true }), + loadPieces({ itemsPerPage: 200, force: true }), + loadProducts({ itemsPerPage: 200, force: true }), ]) })