From 7d67e6a276d516a5bbe71d0f816b9253684315a5 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 20 May 2020 12:36:26 +0100 Subject: [PATCH] [outliner] handle items being added out-of-order Closes #2573 --- .../src/js/ui/tab-info-outliner.js | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info-outliner.js b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info-outliner.js index abee2569c..55111151c 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info-outliner.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info-outliner.js @@ -9,6 +9,7 @@ RED.sidebar.info.outliner = (function() { var globalConfigNodes; var objects = {}; + var missingParents = {}; function getFlowData() { var flowData = [ @@ -288,11 +289,17 @@ RED.sidebar.info.outliner = (function() { objects[ws.id] = { id: ws.id, element: getFlowLabel(ws), - children:[getEmptyItem(ws.id)], + children:[], deferBuild: true, icon: "red-ui-icons red-ui-icons-flow", gutter: getGutter(ws) } + if (missingParents[ws.id]) { + objects[ws.id].children = missingParents[ws.id]; + delete missingParents[ws.id] + } else { + objects[ws.id].children.push(getEmptyItem(ws.id)); + } flowList.treeList.addChild(objects[ws.id]) objects[ws.id].element.toggleClass("red-ui-info-outline-item-disabled", !!ws.disabled) objects[ws.id].treeList.container.toggleClass("red-ui-info-outline-item-disabled", !!ws.disabled) @@ -327,10 +334,16 @@ RED.sidebar.info.outliner = (function() { objects[sf.id] = { id: sf.id, element: getNodeLabel(sf), - children:[getEmptyItem(sf.id)], + children:[], deferBuild: true, gutter: getGutter(sf) } + if (missingParents[sf.id]) { + objects[sf.id].children = missingParents[sf.id]; + delete missingParents[sf.id] + } else { + objects[sf.id].children.push(getEmptyItem(sf.id)); + } subflowList.treeList.addChild(objects[sf.id]) } function onSubflowChange(sf) { @@ -397,6 +410,10 @@ RED.sidebar.info.outliner = (function() { if (n.type === "group") { objects[n.id].children = []; objects[n.id].deferBuild = true; + if (missingParents[n.id]) { + objects[n.id].children = missingParents[n.id]; + delete missingParents[n.id] + } } var parent = n.g||n.z; if (parent) { @@ -405,10 +422,14 @@ RED.sidebar.info.outliner = (function() { empties[parent].treeList.remove(); delete empties[parent]; } - objects[parent].treeList.addChild(objects[n.id]) + if (objects[parent].treeList) { + objects[parent].treeList.addChild(objects[n.id]); + } else { + objects[parent].children.push(objects[n.id]) + } } else { - // The parent hasn't been added yet - console.log("missing",parent) + missingParents[parent] = missingParents[parent]||[]; + missingParents[parent].push(objects[n.id]) } } else { // No parent - add to Global flow list