From c4d732ff77bf8c40cbc106fc3545ceb4868c8ae8 Mon Sep 17 00:00:00 2001 From: Joe Pavitt Date: Sun, 30 Jun 2024 16:47:07 +0100 Subject: [PATCH] Fix: better handling of id replacement --- index.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index c8d0746..60567b2 100644 --- a/index.js +++ b/index.js @@ -45,26 +45,14 @@ const MigrateDashboard = { migratedFlow.push(node) }) - console.log(idMap) - // loop ovr all nodes in thw flow and ensure we have updated references: - - migratedFlow.forEach(node => { - if (node.wires && node.wires.length) { - node.wires = node.wires.map(wire => { - return wire.map(id => { - return idMap[id] || id - }) - }) - } - if (node.group) { - node.group = idMap[node.group] || node.group - } - if (node.page) { - node.page = idMap[node.page] || node.page - } - }) - - return migratedFlow + // work smart, not hard + let strJson = JSON.stringify(migratedFlow) + // loop over idMap + for (const key in idMap) { + // replace all instances of the old ID with the new ID + strJson = strJson.replaceAll(key, idMap[key]) + } + return JSON.parse(strJson) } }