refacto(F1.1) : wire [id].vue to use extracted modules and fix TS errors
Wire machine/[id].vue to import from extracted utility modules (customFieldUtils, productDisplayUtils, useMachineHierarchy, useMachinePrint). Remove ~1400 LOC of inline functions replaced by imports. Fix TypeScript errors in extracted composables (AnyRecord/ConstructeurSummary boundary casts, Map generics, optional chaining on unknown). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { resolveIdentifier, resolveProductReference, getProductDisplay } from '~/shared/utils/productDisplayUtils'
|
import { resolveIdentifier, resolveProductReference, getProductDisplay } from '~/shared/utils/productDisplayUtils'
|
||||||
import { resolveConstructeurs, uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
import { resolveConstructeurs, uniqueConstructeurIds, type ConstructeurSummary } from '~/shared/constructeurUtils'
|
||||||
|
|
||||||
type AnyRecord = Record<string, unknown>
|
type AnyRecord = Record<string, unknown>
|
||||||
|
|
||||||
@@ -28,7 +28,9 @@ const collectConstructeurs = (
|
|||||||
})
|
})
|
||||||
.filter(Boolean) as AnyRecord[][]
|
.filter(Boolean) as AnyRecord[][]
|
||||||
|
|
||||||
return resolveConstructeurs(ids, ...pools, allConstructeurs)
|
// ConstructeurSummary and AnyRecord are structurally compatible at runtime
|
||||||
|
const allPools = [...pools, allConstructeurs] as unknown as Array<ConstructeurSummary[]>
|
||||||
|
return resolveConstructeurs(ids, ...allPools) as unknown as AnyRecord[]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -56,7 +58,7 @@ export function mergePieceLists(existing: AnyRecord[] = [], updates: AnyRecord[]
|
|||||||
return existing.map((piece) => ({ ...piece, constructeurs: piece.constructeurs || [] }))
|
return existing.map((piece) => ({ ...piece, constructeurs: piece.constructeurs || [] }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateMap = new Map(
|
const updateMap = new Map<unknown, AnyRecord>(
|
||||||
updates.map((piece) => [piece.id, { ...piece, constructeurs: piece.constructeurs || [] }]),
|
updates.map((piece) => [piece.id, { ...piece, constructeurs: piece.constructeurs || [] }]),
|
||||||
)
|
)
|
||||||
const merged = existing.map((piece) => {
|
const merged = existing.map((piece) => {
|
||||||
@@ -86,7 +88,7 @@ export function mergeComponentTrees(existing: AnyRecord[] = [], updates: AnyReco
|
|||||||
}
|
}
|
||||||
if (!updates.length) return existing
|
if (!updates.length) return existing
|
||||||
|
|
||||||
const updateMap = new Map(
|
const updateMap = new Map<unknown, AnyRecord>(
|
||||||
updates.map((component) => [
|
updates.map((component) => [
|
||||||
component.id,
|
component.id,
|
||||||
{
|
{
|
||||||
@@ -100,7 +102,7 @@ export function mergeComponentTrees(existing: AnyRecord[] = [], updates: AnyReco
|
|||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
const merged = existing.map((component) => {
|
const merged: AnyRecord[] = existing.map((component) => {
|
||||||
const update = updateMap.get(component.id)
|
const update = updateMap.get(component.id)
|
||||||
if (!update) {
|
if (!update) {
|
||||||
return {
|
return {
|
||||||
@@ -156,13 +158,15 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
const machinePieceLinkId = normalizePieceLinkId(link)
|
const machinePieceLinkId = normalizePieceLinkId(link)
|
||||||
const pieceId = resolveIdentifier(appliedPiece.id, appliedPiece.pieceId, link.pieceId)
|
const pieceId = resolveIdentifier(appliedPiece.id, appliedPiece.pieceId, link.pieceId)
|
||||||
|
|
||||||
|
const overrides = (link.overrides || null) as AnyRecord | null
|
||||||
|
|
||||||
const basePiece: AnyRecord = {
|
const basePiece: AnyRecord = {
|
||||||
...appliedPiece,
|
...appliedPiece,
|
||||||
id: appliedPiece.id || pieceId || machinePieceLinkId || `piece-${machinePieceLinkId}`,
|
id: appliedPiece.id || pieceId || machinePieceLinkId || `piece-${machinePieceLinkId}`,
|
||||||
pieceId,
|
pieceId,
|
||||||
name: link.overrides?.name || appliedPiece.name || (appliedPiece.definition as AnyRecord)?.name || (appliedPiece.definition as AnyRecord)?.role || originalPiece?.name || 'Pièce',
|
name: overrides?.name || appliedPiece.name || (appliedPiece.definition as AnyRecord)?.name || (appliedPiece.definition as AnyRecord)?.role || originalPiece?.name || 'Pièce',
|
||||||
reference: link.overrides?.reference || appliedPiece.reference || (appliedPiece.definition as AnyRecord)?.reference || originalPiece?.reference || null,
|
reference: overrides?.reference || appliedPiece.reference || (appliedPiece.definition as AnyRecord)?.reference || originalPiece?.reference || null,
|
||||||
prix: link.overrides?.prix ?? appliedPiece.prix ?? originalPiece?.prix ?? null,
|
prix: overrides?.prix ?? appliedPiece.prix ?? originalPiece?.prix ?? null,
|
||||||
constructeur: appliedPiece.constructeur || originalPiece?.constructeur || null,
|
constructeur: appliedPiece.constructeur || originalPiece?.constructeur || null,
|
||||||
constructeurId: appliedPiece.constructeurId || (appliedPiece.constructeur as AnyRecord)?.id || originalPiece?.constructeurId || null,
|
constructeurId: appliedPiece.constructeurId || (appliedPiece.constructeur as AnyRecord)?.id || originalPiece?.constructeurId || null,
|
||||||
documents: Array.isArray(appliedPiece.documents) ? appliedPiece.documents : Array.isArray(originalPiece?.documents) ? originalPiece!.documents : [],
|
documents: Array.isArray(appliedPiece.documents) ? appliedPiece.documents : Array.isArray(originalPiece?.documents) ? originalPiece!.documents : [],
|
||||||
@@ -171,7 +175,7 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
typeMachinePieceRequirement: requirement,
|
typeMachinePieceRequirement: requirement,
|
||||||
typeMachinePieceRequirementId: requirement?.id || null,
|
typeMachinePieceRequirementId: requirement?.id || null,
|
||||||
requirementId: requirement?.id || null,
|
requirementId: requirement?.id || null,
|
||||||
overrides: link.overrides || null,
|
overrides,
|
||||||
originalPiece,
|
originalPiece,
|
||||||
machinePieceLink: link,
|
machinePieceLink: link,
|
||||||
machinePieceLinkId,
|
machinePieceLinkId,
|
||||||
@@ -216,7 +220,9 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
const machineComponentLinkId = normalizeComponentLinkId(link)
|
const machineComponentLinkId = normalizeComponentLinkId(link)
|
||||||
const composantId = resolveIdentifier(appliedComponent.id, appliedComponent.composantId, link.composantId)
|
const composantId = resolveIdentifier(appliedComponent.id, appliedComponent.composantId, link.composantId)
|
||||||
|
|
||||||
const componentName = (link.overrides?.name || appliedComponent.name || (appliedComponent.definition as AnyRecord)?.alias || (appliedComponent.definition as AnyRecord)?.name || originalComponent?.name || 'Composant') as string
|
const compOverrides = (link.overrides || null) as AnyRecord | null
|
||||||
|
|
||||||
|
const componentName = (compOverrides?.name || appliedComponent.name || (appliedComponent.definition as AnyRecord)?.alias || (appliedComponent.definition as AnyRecord)?.name || originalComponent?.name || 'Composant') as string
|
||||||
|
|
||||||
const pieces = Array.isArray(link.pieceLinks)
|
const pieces = Array.isArray(link.pieceLinks)
|
||||||
? (link.pieceLinks as AnyRecord[]).map((pl) => createPieceNode(pl, componentName)).filter(Boolean) as AnyRecord[]
|
? (link.pieceLinks as AnyRecord[]).map((pl) => createPieceNode(pl, componentName)).filter(Boolean) as AnyRecord[]
|
||||||
@@ -234,8 +240,8 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
id: appliedComponent.id || composantId || machineComponentLinkId || `component-${machineComponentLinkId}`,
|
id: appliedComponent.id || composantId || machineComponentLinkId || `component-${machineComponentLinkId}`,
|
||||||
composantId,
|
composantId,
|
||||||
name: componentName,
|
name: componentName,
|
||||||
reference: link.overrides?.reference || appliedComponent.reference || (appliedComponent.definition as AnyRecord)?.reference || originalComponent?.reference || null,
|
reference: compOverrides?.reference || appliedComponent.reference || (appliedComponent.definition as AnyRecord)?.reference || originalComponent?.reference || null,
|
||||||
prix: link.overrides?.prix ?? appliedComponent.prix ?? originalComponent?.prix ?? null,
|
prix: compOverrides?.prix ?? appliedComponent.prix ?? originalComponent?.prix ?? null,
|
||||||
constructeur: appliedComponent.constructeur || originalComponent?.constructeur || null,
|
constructeur: appliedComponent.constructeur || originalComponent?.constructeur || null,
|
||||||
constructeurId: appliedComponent.constructeurId || (appliedComponent.constructeur as AnyRecord)?.id || originalComponent?.constructeurId || null,
|
constructeurId: appliedComponent.constructeurId || (appliedComponent.constructeur as AnyRecord)?.id || originalComponent?.constructeurId || null,
|
||||||
documents: Array.isArray(appliedComponent.documents) ? appliedComponent.documents : Array.isArray(originalComponent?.documents) ? originalComponent!.documents : [],
|
documents: Array.isArray(appliedComponent.documents) ? appliedComponent.documents : Array.isArray(originalComponent?.documents) ? originalComponent!.documents : [],
|
||||||
@@ -244,9 +250,9 @@ export const buildMachineHierarchyFromLinks = (
|
|||||||
typeMachineComponentRequirement: requirement,
|
typeMachineComponentRequirement: requirement,
|
||||||
typeMachineComponentRequirementId: requirement?.id || null,
|
typeMachineComponentRequirementId: requirement?.id || null,
|
||||||
requirementId: requirement?.id || null,
|
requirementId: requirement?.id || null,
|
||||||
overrides: link.overrides || null,
|
overrides: compOverrides,
|
||||||
machineComponentLinkOverrides: link.overrides || null,
|
machineComponentLinkOverrides: compOverrides,
|
||||||
definitionOverrides: link.overrides || null,
|
definitionOverrides: compOverrides,
|
||||||
originalComposant: originalComponent,
|
originalComposant: originalComponent,
|
||||||
machineComponentLink: link,
|
machineComponentLink: link,
|
||||||
machineComponentLinkId,
|
machineComponentLinkId,
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ export function useMachinePrint() {
|
|||||||
) => {
|
) => {
|
||||||
if (typeof window === 'undefined') return
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
const context = buildMachinePrintContext({
|
// machineReport.js has no type annotations; cast to avoid inferred never[] params
|
||||||
|
const context = (buildMachinePrintContext as unknown as (config: Record<string, unknown>) => Record<string, unknown>)({
|
||||||
machine,
|
machine,
|
||||||
machineName,
|
machineName,
|
||||||
machineReference,
|
machineReference,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user