Restore component catalog with requirement-based instantiation
This commit is contained in:
@@ -387,6 +387,48 @@ export const formatStructurePreview = (structure: any) => {
|
||||
return segments.join(' • ')
|
||||
}
|
||||
|
||||
export interface DefinitionOverridePayload {
|
||||
name?: string
|
||||
reference?: string
|
||||
constructeurId?: string | null
|
||||
prix?: number
|
||||
}
|
||||
|
||||
export const sanitizeDefinitionOverrides = (definition: any): DefinitionOverridePayload | null => {
|
||||
if (!definition || typeof definition !== 'object') {
|
||||
return null
|
||||
}
|
||||
|
||||
const payload: DefinitionOverridePayload = {}
|
||||
|
||||
if (typeof definition.name === 'string') {
|
||||
const name = definition.name.trim()
|
||||
if (name.length > 0) {
|
||||
payload.name = name
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof definition.reference === 'string') {
|
||||
const reference = definition.reference.trim()
|
||||
if (reference.length > 0) {
|
||||
payload.reference = reference
|
||||
}
|
||||
}
|
||||
|
||||
if (definition.constructeurId !== undefined && definition.constructeurId !== null && definition.constructeurId !== '') {
|
||||
payload.constructeurId = definition.constructeurId
|
||||
}
|
||||
|
||||
if (definition.prix !== undefined && definition.prix !== null && definition.prix !== '') {
|
||||
const parsed = Number(definition.prix)
|
||||
if (!Number.isNaN(parsed)) {
|
||||
payload.prix = parsed
|
||||
}
|
||||
}
|
||||
|
||||
return Object.keys(payload).length ? payload : null
|
||||
}
|
||||
|
||||
export const defaultPieceStructure = (): PieceModelStructure => ({
|
||||
...createEmptyPieceModelStructure(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user