From d6af915ee458e2d2cc0da359d48d73b0210d2cf7 Mon Sep 17 00:00:00 2001 From: Jeremie Pardou <571533+jrmi@users.noreply.github.com> Date: Mon, 13 May 2024 16:01:28 +0200 Subject: [PATCH] Fix bug if missing linked item --- src/lib/board/Items/useItemActions.js | 5 ++--- src/lib/utils.js | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/lib/board/Items/useItemActions.js b/src/lib/board/Items/useItemActions.js index 2fdf4cd..b94fc97 100644 --- a/src/lib/board/Items/useItemActions.js +++ b/src/lib/board/Items/useItemActions.js @@ -292,10 +292,9 @@ const useItemActions = () => { }); insertItems(itemsWithPosition, beforeId); - - updateItemExtent(); + placeItems(itemsToInsert.map((item) => item.id)); }, - [getCenter, insertItems, updateItemExtent] + [getCenter, insertItems, placeItems] ); const pushItem = React.useCallback( diff --git a/src/lib/utils.js b/src/lib/utils.js index d59fcde..8631c0d 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -212,14 +212,19 @@ const getLinkedItemsRecursive = (itemMap, itemIds, alreadyMet = null) => { return []; } else { alreadyMet.add(itemId); - return [ - itemId, - ...getLinkedItemsRecursive( - itemMap, - itemMap[itemId].linkedItems, - alreadyMet - ), - ]; + if (itemMap[itemId]) { + // If the item has been removed but not from linked list + return [ + itemId, + ...getLinkedItemsRecursive( + itemMap, + itemMap[itemId].linkedItems, + alreadyMet + ), + ]; + } else { + return []; + } } }) .flat();