feat: enrich piece assignment labels and document previews

This commit is contained in:
Matthieu
2025-10-23 09:01:38 +02:00
parent 553600c34b
commit 417b34b45e
11 changed files with 364 additions and 51 deletions

View File

@@ -228,16 +228,44 @@ watch(
const describePieceRequirement = (definition: ComponentModelPiece) => {
const parts: string[] = [];
if (definition.role) {
parts.push(definition.role);
const addPart = (value?: string | null) => {
const trimmed = typeof value === 'string' ? value.trim() : '';
if (trimmed && !parts.includes(trimmed)) {
parts.push(trimmed);
}
};
const options = getPieceOptions(definition);
const fallbackPiece = options[0] || null;
const fallbackType = fallbackPiece?.typePiece || null;
addPart(definition.role);
addPart(
definition.typePieceLabel ||
(definition as any).typePiece?.name ||
fallbackType?.name,
);
const family =
definition.familyCode ||
(definition as any).typePiece?.code ||
fallbackType?.code ||
null;
if (family) {
addPart(`Famille ${family}`);
}
if (definition.typePieceLabel) {
parts.push(definition.typePieceLabel);
} else if ((definition as any).typePiece?.name) {
parts.push((definition as any).typePiece.name);
} else if (definition.familyCode) {
parts.push(definition.familyCode);
if (parts.length === 0) {
addPart(fallbackType?.name);
if (fallbackType?.code) {
addPart(`Famille ${fallbackType.code}`);
}
}
if (parts.length === 0 && definition.typePieceId) {
addPart(`#${definition.typePieceId}`);
}
return parts.length ? parts.join(' • ') : 'Pièce du squelette';
};