feat(ui): streamline skeleton model selection and toast display
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="px-4 py-4 space-y-5">
|
<div class="px-4 py-4 space-y-5">
|
||||||
<section class="space-y-3">
|
<section v-if="isRoot" class="space-y-3">
|
||||||
<div class="flex items-center justify-between gap-2">
|
<div class="flex items-center justify-between gap-2">
|
||||||
<h4 :class="headingClass">
|
<h4 :class="headingClass">
|
||||||
{{ isRoot ? 'Champs personnalisés du composant' : 'Champs personnalisés' }}
|
{{ isRoot ? 'Champs personnalisés du composant' : 'Champs personnalisés' }}
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="space-y-3">
|
<section v-if="isRoot" class="space-y-3">
|
||||||
<div class="flex items-center justify-between gap-2">
|
<div class="flex items-center justify-between gap-2">
|
||||||
<h4 :class="headingClass">
|
<h4 :class="headingClass">
|
||||||
{{ isRoot ? 'Pièces incluses par défaut' : 'Pièces' }}
|
{{ isRoot ? 'Pièces incluses par défaut' : 'Pièces' }}
|
||||||
@@ -160,6 +160,9 @@
|
|||||||
Ajouter
|
Ajouter
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<p v-if="!isRoot" class="text-[11px] text-gray-500">
|
||||||
|
Sélectionnez uniquement la famille de ce sous-composant ; il sera configuré via son propre modèle.
|
||||||
|
</p>
|
||||||
<p v-if="!(node.subComponents?.length)" class="text-xs text-gray-500">
|
<p v-if="!(node.subComponents?.length)" class="text-xs text-gray-500">
|
||||||
Aucun sous-composant défini.
|
Aucun sous-composant défini.
|
||||||
</p>
|
</p>
|
||||||
@@ -397,9 +400,6 @@ const addSubComponent = () => {
|
|||||||
name: '',
|
name: '',
|
||||||
typeComposantId: '',
|
typeComposantId: '',
|
||||||
typeComposantLabel: '',
|
typeComposantLabel: '',
|
||||||
customFields: [],
|
|
||||||
pieces: [],
|
|
||||||
subComponents: [],
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1090,6 +1090,7 @@ const normalizePieceNode = (source, context = {}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const normalizeComponentNode = (source, context = {}) => {
|
const normalizeComponentNode = (source, context = {}) => {
|
||||||
|
const isRoot = context.isRoot ?? false
|
||||||
const typeComposantId = source?.typeComposantId
|
const typeComposantId = source?.typeComposantId
|
||||||
|| source?.typeComposant?.id
|
|| source?.typeComposant?.id
|
||||||
|| context.typeComposantId
|
|| context.typeComposantId
|
||||||
@@ -1110,10 +1111,10 @@ const normalizeComponentNode = (source, context = {}) => {
|
|||||||
?? context.componentModelId
|
?? context.componentModelId
|
||||||
?? null,
|
?? null,
|
||||||
__requirementId: source?.__requirementId ?? context.requirementId ?? null,
|
__requirementId: source?.__requirementId ?? context.requirementId ?? null,
|
||||||
customFields: Array.isArray(source?.customFields)
|
customFields: isRoot && Array.isArray(source?.customFields)
|
||||||
? cloneStructure(source.customFields)
|
? cloneStructure(source.customFields)
|
||||||
: [],
|
: [],
|
||||||
pieces: Array.isArray(source?.pieces)
|
pieces: isRoot && Array.isArray(source?.pieces)
|
||||||
? source.pieces.map((piece) => normalizePieceNode(piece))
|
? source.pieces.map((piece) => normalizePieceNode(piece))
|
||||||
: [],
|
: [],
|
||||||
subComponents: Array.isArray(source?.subComponents || source?.sousComposants)
|
subComponents: Array.isArray(source?.subComponents || source?.sousComposants)
|
||||||
@@ -1127,6 +1128,8 @@ const normalizeComponentNode = (source, context = {}) => {
|
|||||||
?? sub?.composantModelId
|
?? sub?.composantModelId
|
||||||
?? sub?.composantModel?.id
|
?? sub?.composantModel?.id
|
||||||
?? null,
|
?? null,
|
||||||
|
requirementId: sub?.__requirementId ?? null,
|
||||||
|
isRoot: false,
|
||||||
}))
|
}))
|
||||||
: [],
|
: [],
|
||||||
}
|
}
|
||||||
@@ -1173,6 +1176,7 @@ const createEmptyComponentDefinition = (requirement) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
requirementId: requirement?.id || null,
|
requirementId: requirement?.id || null,
|
||||||
|
isRoot: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1188,6 +1192,7 @@ const createDefinitionFromModel = (model, requirement) => {
|
|||||||
const definition = normalizeComponentNode(structure, {
|
const definition = normalizeComponentNode(structure, {
|
||||||
requirementId: requirement?.id || null,
|
requirementId: requirement?.id || null,
|
||||||
componentModelId: model?.id || null,
|
componentModelId: model?.id || null,
|
||||||
|
isRoot: true,
|
||||||
})
|
})
|
||||||
definition.__componentModelId = model?.id || null
|
definition.__componentModelId = model?.id || null
|
||||||
return definition
|
return definition
|
||||||
@@ -1206,6 +1211,7 @@ const buildDefinitionFromComponent = (component, requirement) => {
|
|||||||
typeComposantLabel: requirement?.typeComposant?.name
|
typeComposantLabel: requirement?.typeComposant?.name
|
||||||
|| component?.typeComposant?.name
|
|| component?.typeComposant?.name
|
||||||
|| '',
|
|| '',
|
||||||
|
isRoot: true,
|
||||||
})
|
})
|
||||||
return definition
|
return definition
|
||||||
}
|
}
|
||||||
@@ -1224,7 +1230,7 @@ const applyDefinitionToNode = (target, definition) => {
|
|||||||
? definition.pieces.map((piece) => normalizePieceNode(piece))
|
? definition.pieces.map((piece) => normalizePieceNode(piece))
|
||||||
: []
|
: []
|
||||||
target.subComponents = Array.isArray(definition.subComponents)
|
target.subComponents = Array.isArray(definition.subComponents)
|
||||||
? definition.subComponents.map((sub) => normalizeComponentNode(sub))
|
? definition.subComponents.map((sub) => normalizeComponentNode(sub, { isRoot: false }))
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1255,6 +1261,7 @@ const handleNodeComponentModelChange = async (node, typeComposantId, modelId) =>
|
|||||||
await ensureModelsForNodeDefinition(node)
|
await ensureModelsForNodeDefinition(node)
|
||||||
} else {
|
} else {
|
||||||
node.__componentModelId = null
|
node.__componentModelId = null
|
||||||
|
node.customFields = []
|
||||||
node.pieces = []
|
node.pieces = []
|
||||||
node.subComponents = []
|
node.subComponents = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,15 +146,8 @@ const sanitizeSubComponents = (components: any[]): any[] => {
|
|||||||
const quantity = Number(component?.quantity)
|
const quantity = Number(component?.quantity)
|
||||||
const normalizedQuantity = Number.isFinite(quantity) && quantity > 0 ? quantity : undefined
|
const normalizedQuantity = Number.isFinite(quantity) && quantity > 0 ? quantity : undefined
|
||||||
|
|
||||||
const customFields = sanitizeCustomFields(component?.customFields)
|
|
||||||
const pieces = sanitizePieces(component?.pieces)
|
|
||||||
const subComponents = sanitizeSubComponents(component?.subComponents)
|
|
||||||
|
|
||||||
const result: Record<string, unknown> = {
|
const result: Record<string, unknown> = {
|
||||||
name,
|
name,
|
||||||
customFields,
|
|
||||||
pieces,
|
|
||||||
subComponents,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description !== undefined) {
|
if (description !== undefined) {
|
||||||
@@ -170,6 +163,14 @@ const sanitizeSubComponents = (components: any[]): any[] => {
|
|||||||
result.typeComposantLabel = typeComposantLabel
|
result.typeComposantLabel = typeComposantLabel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nestedSubComponents = sanitizeSubComponents(component?.subComponents)
|
||||||
|
if (nestedSubComponents.length > 0) {
|
||||||
|
result.subComponents = nestedSubComponents
|
||||||
|
} else {
|
||||||
|
result.subComponents = []
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sub components only carry structural info (they will be resolved via their own models)
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
@@ -224,8 +225,8 @@ const hydrateSubComponents = (components: any[]): any[] => {
|
|||||||
quantity: component?.quantity ?? component?.quantite ?? undefined,
|
quantity: component?.quantity ?? component?.quantite ?? undefined,
|
||||||
typeComposantId: component?.typeComposantId ?? component?.typeComposant?.id ?? '',
|
typeComposantId: component?.typeComposantId ?? component?.typeComposant?.id ?? '',
|
||||||
typeComposantLabel: component?.typeComposantLabel ?? component?.typeComposant?.name ?? '',
|
typeComposantLabel: component?.typeComposantLabel ?? component?.typeComposant?.name ?? '',
|
||||||
customFields: hydrateCustomFields(component?.customFields),
|
customFields: [],
|
||||||
pieces: hydratePieces(component?.pieces),
|
pieces: [],
|
||||||
subComponents: hydrateSubComponents(component?.subComponents),
|
subComponents: hydrateSubComponents(component?.subComponents),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -285,8 +286,8 @@ const mapSubComponents = (components: any[]): any[] => {
|
|||||||
quantity: component?.quantity ?? component?.quantite ?? undefined,
|
quantity: component?.quantity ?? component?.quantite ?? undefined,
|
||||||
typeComposantId: component?.typeComposantId ?? component?.typeComposant?.id ?? '',
|
typeComposantId: component?.typeComposantId ?? component?.typeComposant?.id ?? '',
|
||||||
typeComposantLabel: component?.typeComposantLabel ?? component?.typeComposant?.name ?? '',
|
typeComposantLabel: component?.typeComposantLabel ?? component?.typeComposant?.name ?? '',
|
||||||
customFields: mapComponentCustomFields(component?.customFields),
|
customFields: [],
|
||||||
pieces: mapComponentPieces(component?.pieces),
|
pieces: [],
|
||||||
subComponents: mapSubComponents(component?.subComponents),
|
subComponents: mapSubComponents(component?.subComponents),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user