feat(frontend): améliorer éditeurs de structure
This commit is contained in:
@@ -85,6 +85,20 @@ const sanitizePieces = (pieces: any[]): any[] => {
|
||||
const quantity = Number(piece?.quantity)
|
||||
const normalizedQuantity = Number.isFinite(quantity) && quantity > 0 ? quantity : undefined
|
||||
|
||||
const rawTypePieceId = typeof piece?.typePieceId === 'string'
|
||||
? piece.typePieceId.trim()
|
||||
: typeof piece?.typePiece?.id === 'string'
|
||||
? piece.typePiece.id.trim()
|
||||
: ''
|
||||
const typePieceId = rawTypePieceId.length > 0 ? rawTypePieceId : undefined
|
||||
|
||||
const rawTypePieceLabel = typeof piece?.typePieceLabel === 'string'
|
||||
? piece.typePieceLabel.trim()
|
||||
: typeof piece?.typePiece?.name === 'string'
|
||||
? piece.typePiece.name.trim()
|
||||
: ''
|
||||
const typePieceLabel = rawTypePieceLabel.length > 0 ? rawTypePieceLabel : undefined
|
||||
|
||||
const result: Record<string, unknown> = { name }
|
||||
if (reference !== undefined) {
|
||||
result.reference = reference
|
||||
@@ -92,6 +106,12 @@ const sanitizePieces = (pieces: any[]): any[] => {
|
||||
if (normalizedQuantity !== undefined) {
|
||||
result.quantity = normalizedQuantity
|
||||
}
|
||||
if (typePieceId) {
|
||||
result.typePieceId = typePieceId
|
||||
}
|
||||
if (typePieceLabel) {
|
||||
result.typePieceLabel = typePieceLabel
|
||||
}
|
||||
return result
|
||||
})
|
||||
.filter(Boolean)
|
||||
@@ -173,6 +193,8 @@ const hydratePieces = (pieces: any[]): any[] => {
|
||||
name: piece?.name ?? '',
|
||||
reference: piece?.reference ?? '',
|
||||
quantity: piece?.quantity ?? undefined,
|
||||
typePieceId: piece?.typePieceId ?? piece?.typePiece?.id ?? '',
|
||||
typePieceLabel: piece?.typePieceLabel ?? piece?.typePiece?.name ?? '',
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user