feat(machine) : afficher quantité pièces + pièces incluses des composants
- MachinePiecesCard : passer isEditMode au PieceItem + forward event update - useMachineHierarchy : mapper quantity depuis le backend + construire les pièces de structure du composant en lecture seule - useMachineDetailUpdates : PATCH MachinePieceLink.quantity + fix reference null - ComponentItem : séparer pièces liées / pièces incluses par défaut - useEntityDocuments : skip chargement documents pour pièces de structure Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@ export interface UseMachineDetailUpdatesDeps {
|
||||
updateMachineApi: (id: string, data: any) => Promise<unknown>
|
||||
updateComposantApi: (id: string, data: any) => Promise<unknown>
|
||||
updatePieceApi: (id: string, data: any) => Promise<unknown>
|
||||
apiPatch: (endpoint: string, data?: unknown) => Promise<any>
|
||||
toast: { showInfo: (msg: string) => void }
|
||||
}
|
||||
|
||||
@@ -53,6 +54,7 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
||||
updateMachineApi,
|
||||
updateComposantApi,
|
||||
updatePieceApi,
|
||||
apiPatch,
|
||||
toast,
|
||||
} = deps
|
||||
|
||||
@@ -147,7 +149,7 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
||||
|
||||
const result: any = await updatePieceApi(updatedPiece.id as string, {
|
||||
name: updatedPiece.name,
|
||||
reference: updatedPiece.reference,
|
||||
reference: updatedPiece.reference || null,
|
||||
constructeurIds: cIds,
|
||||
prix: Number.isNaN(prix) ? null : prix,
|
||||
productId,
|
||||
@@ -187,6 +189,13 @@ export function useMachineDetailUpdates(deps: UseMachineDetailUpdatesDeps) {
|
||||
const updatePieceInfo = async (updatedPiece: AnyRecord) => {
|
||||
try {
|
||||
await _buildAndUpdatePiece(updatedPiece)
|
||||
|
||||
// Update link quantity if this is a direct machine piece
|
||||
const linkId = updatedPiece.linkId || updatedPiece.machinePieceLinkId
|
||||
const quantity = typeof updatedPiece.quantity === 'number' ? Math.max(1, updatedPiece.quantity) : null
|
||||
if (linkId && quantity !== null) {
|
||||
await apiPatch(`/machine_piece_links/${linkId}`, { quantity })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la mise à jour de la pièce:', error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user