Skip to content

Commit 67e42d5

Browse files
committed
dev: Add NodeSelector handlers for edge updates.
1 parent 4fefc70 commit 67e42d5

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

build/app/view/netcreate/components/NodeSelector.jsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,36 @@ class NodeSelector extends UNISYS.Component {
207207
/*/ If someone on the network updates a node or edge, SOURCE_UPDATE is broadcast.
208208
We catch it here and update the selection if the node we're displaying matches
209209
the updated node.
210-
NOTE: We do not currently update NodeSelector if a new edge has been added
211-
that references the currently selected node.
212-
/*/ UDATA.HandleMessage("SOURCE_UPDATE", (data) => {
213-
if (this.state.formData.id===data.node.id) UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [data.node.id] });
210+
This basically handles updated Node labels in both the main node and in related
211+
edges.
212+
/*/
213+
UDATA.HandleMessage("SOURCE_UPDATE", (data) => {
214+
let needsUpdate = false;
215+
let currentNodeID = this.state.formData.id;
216+
let updatedNodeID = data.node.id;
217+
if (currentNodeID === updatedNodeID) needsUpdate = true;
218+
this.state.edges.forEach(edge => {
219+
if ((edge.source.id === updatedNodeID) || (edge.target.id === updatedNodeID)) needsUpdate = true;
220+
})
221+
if (needsUpdate) UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [currentNodeID] });
222+
});
223+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
224+
/*/ This will add any new edges that have links to the currently selected node
225+
to the list of edges in the NodeSelector.
226+
/*/
227+
UDATA.HandleMessage("EDGE_UPDATE", (data) => {
228+
let currentNodeID = this.state.formData.id;
229+
let updatedNodeIDs = [data.edge.source.id, data.edge.target.id];
230+
if (updatedNodeIDs.includes(currentNodeID)) {
231+
UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [currentNodeID] });
232+
}
214233
});
234+
// This handler is not necessary because SELECTION event clears the form
235+
// UDATA.HandleMessage("NODE_DELETE", (data) => {
236+
// });
237+
// This handler is not necessary because SELECTION event will update the edges
238+
// UDATA.HandleMessage("EDGE_DELETE", (data) => {
239+
// });
215240

216241
} // constructor
217242

0 commit comments

Comments
 (0)