Skip to content

Commit 6a69521

Browse files
authored
Merge pull request #56 from daveseah/dev-bl/fix-network-edge-update
Fix Network Edge Updates Clobbering Edge Edits Kalani confirmed fixed Issue #54
2 parents b14b4ed + 8d43596 commit 6a69521

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ class EdgeEditor extends UNISYS.Component {
365365
isEditable: true
366366
});
367367

368+
this.AppCall('EDGEEDIT_LOCK', { edgeID: this.props.edgeID });
369+
368370
} else {
369371

370372
// LOAD EXISTING EDGE
@@ -508,6 +510,7 @@ class EdgeEditor extends UNISYS.Component {
508510
isEditable: true
509511
});
510512
}
513+
this.AppCall('EDGEEDIT_LOCK', { edgeID: this.props.edgeID });
511514

512515
} // handleEdgeEdit
513516
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -537,8 +540,10 @@ class EdgeEditor extends UNISYS.Component {
537540
if (this.state.isEditable) {
538541
this.loadSourceAndTarget();
539542
this.setState({ isEditable: false, targetIsEditable: false });
543+
this.AppCall('EDGEEDIT_UNLOCK', { edgeID: this.props.edgeID });
540544
this.AppCall('AUTOCOMPLETE_SELECT',{id:'search'});
541545
}
546+
542547
} else {
543548
// expand, but don't set the autocomplete field, since we're not editing
544549
this.setState({ isExpanded: true });
@@ -548,12 +553,14 @@ class EdgeEditor extends UNISYS.Component {
548553
/*/
549554
/*/ onDeleteButtonClick () {
550555
this.clearForm();
556+
this.AppCall('EDGEEDIT_UNLOCK', { edgeID: this.props.edgeID });
551557
this.AppCall('DB_UPDATE',{edgeID:this.props.edgeID});
552558
}
553559
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
554560
/*/
555561
/*/ onEditButtonClick () {
556562
this.setState({ isEditable: true });
563+
this.AppCall('EDGEEDIT_LOCK', { edgeID: this.props.edgeID });
557564

558565
// Don't allow editing of the source or target fields.
559566
// If you want to change the edge, delete this one and create a new one.
@@ -662,6 +669,7 @@ class EdgeEditor extends UNISYS.Component {
662669
}
663670
if (DBG) console.group('EdgeEntry.onSubmit submitting',edge)
664671

672+
this.AppCall('EDGEEDIT_UNLOCK', { edgeID: this.props.edgeID });
665673
// pass currentAutoComplete back to nodeselector
666674
this.AppCall('AUTOCOMPLETE_SELECT',{id:'search'});
667675
this.setState({ isEditable: false, sourceIsEditable: false, targetIsEditable: false });

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class NodeSelector extends UNISYS.Component {
149149
isNewNode: true
150150
},
151151
edges: [],
152-
isLocked: true,
152+
isLocked: true,
153+
edgesAreLocked: false,
153154
sourceNodeIsLocked: false,
154155
isEditable: false,
155156
isValid: false,
@@ -223,20 +224,34 @@ class NodeSelector extends UNISYS.Component {
223224
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
224225
/*/ This will add any new edges that have links to the currently selected node
225226
to the list of edges in the NodeSelector.
227+
IMPORTANT: We ignore edge updates if an edge is currently being edited to
228+
prevent edge updates from clobbering the edit. The list of edges is
229+
updated after the edit is completed, so new edges are added then.
226230
/*/
227231
UDATA.HandleMessage("EDGE_UPDATE", (data) => {
228232
let currentNodeID = this.state.formData.id;
229233
let updatedNodeIDs = [data.edge.source.id, data.edge.target.id];
230-
if (updatedNodeIDs.includes(currentNodeID)) {
234+
if (updatedNodeIDs.includes(currentNodeID) && !this.state.edgesAreLocked) {
231235
UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [currentNodeID] });
232236
}
233237
});
238+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234239
// This handler is not necessary because SELECTION event clears the form
235240
// UDATA.HandleMessage("NODE_DELETE", (data) => {
236241
// });
237242
// This handler is not necessary because SELECTION event will update the edges
238243
// UDATA.HandleMessage("EDGE_DELETE", (data) => {
239244
// });
245+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
246+
/*/ This keeps track of whether an edge is being edited to prevent network
247+
updates from clobbering an in-process edit.
248+
/*/
249+
UDATA.HandleMessage("EDGEEDIT_LOCK", (data) => {
250+
this.setState({ edgesAreLocked: true });
251+
});
252+
UDATA.HandleMessage("EDGEEDIT_UNLOCK", (data) => {
253+
this.setState({ edgesAreLocked: false });
254+
});
240255

241256
} // constructor
242257

@@ -567,7 +582,7 @@ class NodeSelector extends UNISYS.Component {
567582
/*/
568583
onEditButtonClick(event) {
569584
event.preventDefault();
570-
585+
571586
// nodeID needs to be a Number. It should have been set in loadFormFromNode
572587
let nodeID = this.state.formData.id;
573588

0 commit comments

Comments
 (0)