diff --git a/Inventory_frontend b/Inventory_frontend index dbf8c88..6bed715 160000 --- a/Inventory_frontend +++ b/Inventory_frontend @@ -1 +1 @@ -Subproject commit dbf8c8856b1468d7285d51c1edd59a064b07d71f +Subproject commit 6bed715b7f5ec9aec171c623b6587e285fd41ed7 diff --git a/VERSION b/VERSION index 9c6d629..fdd3be6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1 +1.6.2 diff --git a/src/Controller/MachineSkeletonController.php b/src/Controller/MachineSkeletonController.php index edfd680..a16697d 100644 --- a/src/Controller/MachineSkeletonController.php +++ b/src/Controller/MachineSkeletonController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Controller; use App\Entity\Composant; +use App\Entity\CustomField; use App\Entity\Machine; use App\Entity\MachineComponentLink; use App\Entity\MachinePieceLink; @@ -341,21 +342,28 @@ class MachineSkeletonController extends AbstractController $componentIndex = $this->indexNormalizedLinks($normalizedComponentLinks); $normalizedPieceLinks = $this->normalizePieceLinks($pieceLinks); - // Build component hierarchy - foreach ($normalizedComponentLinks as &$link) { + // Build component hierarchy – track which IDs are children + $childIds = []; + foreach ($normalizedComponentLinks as $link) { $parentId = $link['parentComponentLinkId'] ?? null; if ($parentId && isset($componentIndex[$parentId])) { - $componentIndex[$parentId]['childLinks'][] = &$link; + $componentIndex[$parentId]['childLinks'][] = $link; + $childIds[$link['id']] = true; } } - unset($link); // Add pieces to components recursively $this->attachPiecesToComponents($componentIndex, $normalizedPieceLinks); + // Only return root-level components (exclude children already nested) + $rootComponents = array_filter( + $componentIndex, + static fn (array $link) => !isset($childIds[$link['id']]), + ); + return [ 'machine' => $this->normalizeMachine($machine), - 'componentLinks' => array_values($componentIndex), + 'componentLinks' => array_values($rootComponents), 'pieceLinks' => $normalizedPieceLinks, 'productLinks' => $this->normalizeProductLinks($productLinks), ];