From c274153c7915eabfe88cb9deaa162026628dee5e Mon Sep 17 00:00:00 2001 From: Thaum Rystra <9525416+ThaumRystra@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:12:30 +0200 Subject: [PATCH] Duplicating properties now renews root sub-doc ids --- .../creature/creatureProperties/methods/duplicateProperty.js | 5 +++-- app/imports/api/library/methods/duplicateLibraryNode.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js b/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js index 25044a7d..88e2f900 100644 --- a/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js +++ b/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js @@ -77,7 +77,8 @@ const duplicateProperty = new ValidatedMethod({ }); // Give the docs new IDs without breaking internal references - renewDocIds({ docArray: nodes }); + const allNodes = [property, ...nodes]; + renewDocIds({ docArray: allNodes }); // Order the root node property.order += 0.5; @@ -86,7 +87,7 @@ const duplicateProperty = new ValidatedMethod({ property.dirty = true; // Insert the properties - CreatureProperties.batchInsert([property, ...nodes]); + CreatureProperties.batchInsert(allNodes); // Tree structure changed by inserts, reorder the tree reorderDocs({ diff --git a/app/imports/api/library/methods/duplicateLibraryNode.js b/app/imports/api/library/methods/duplicateLibraryNode.js index 43aa0a8a..eef9f10c 100644 --- a/app/imports/api/library/methods/duplicateLibraryNode.js +++ b/app/imports/api/library/methods/duplicateLibraryNode.js @@ -67,12 +67,13 @@ const duplicateLibraryNode = new ValidatedMethod({ }); // Give the docs new IDs without breaking internal references - renewDocIds({ docArray: nodes }); + const allNodes = [libraryNode, ...nodes]; + renewDocIds({ docArray: allNodes }); // Order the root node libraryNode.order += 0.5; - LibraryNodes.batchInsert([libraryNode, ...nodes]); + LibraryNodes.batchInsert(allNodes); // Tree structure changed by inserts, reorder the tree reorderDocs({