Skip to content

Commit f530fb0

Browse files
authored
Merge pull request #71 from daveseah/dev-bl/edit-source-target
Allow edit target when source and target share the same parent node.
2 parents 23c80e3 + b80220a commit f530fb0

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ class AutoComplete extends UNISYS.Component {
336336
Check to see if it references a valid node, if so, select it
337337
/*/ onBlur (value) {
338338
// User selected an existing node in the suggestion list
339+
// or User clicked on d3 graph
340+
// or User clicked outside of field
341+
if (DBG) console.log('AutoComplete.onBlur',value);
339342
this.AppCall('SOURCE_SEARCH_AND_SELECT', { searchString: this.state.value } );
340343
}
341344

@@ -364,7 +367,7 @@ class AutoComplete extends UNISYS.Component {
364367
/*/ render () {
365368
const { value, suggestions } = this.state;
366369
const inputProps = {
367-
placeholder : "Type node name...",
370+
placeholder : this.props.placeholder || 'Type node name...',
368371
value : value,
369372
onChange : this.onInputChange,
370373
onBlur : this.onBlur

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ class EdgeEditor extends UNISYS.Component {
232232
sourceIsEditable:false, // Source ndoe field is only editable when source is not parent
233233
hasValidSource: false, // Used by SwapSourceAndTarget and the Change Source button
234234
targetIsEditable:false, // Target ndoe field is only editable when target is not parent
235-
hasValidTarget: false // Used by SwapSourceAndTarget and the Change Target button
235+
hasValidTarget: false, // Used by SwapSourceAndTarget and the Change Target button
236+
placeholder: undefined
236237
};
237238

238239
/// Initialize UNISYS DATA LINK for REACT
@@ -653,22 +654,26 @@ class EdgeEditor extends UNISYS.Component {
653654
/*/ onChangeSource () {
654655
this.setState({
655656
sourceIsEditable: true,
656-
hasValidSource: false
657+
hasValidSource: false,
658+
placeholder: this.state.sourceNode.label
657659
});
658660
this.AppCall('AUTOCOMPLETE_SELECT',{id:'edge'+this.props.edgeID+'source'});
659661
// Whenever we set the autocomplete to source, we have to update the label
660-
this.AppCall('SOURCE_SEARCH', { searchString: this.state.sourceNode.label });
662+
// Clear the AutoComplete field so that onBlur does not select the same node
663+
this.AppCall('SOURCE_SEARCH', { searchString: '' });
661664
}
662665
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
663666
/*/
664667
/*/ onChangeTarget () {
665668
this.setState({
666669
targetIsEditable: true,
667-
hasValidTarget: false
670+
hasValidTarget: false,
671+
placeholder: this.state.targetNode.label
668672
});
669673
this.AppCall('AUTOCOMPLETE_SELECT',{id:'edge'+this.props.edgeID+'target'});
670674
// Whenever we set the autocomplete to target, we have to update the label
671-
this.AppCall('SOURCE_SEARCH', { searchString: this.state.targetNode.label });
675+
// Clear the AutoComplete field so that onBlur does not select the same node
676+
this.AppCall('SOURCE_SEARCH', { searchString: '' });
672677
}
673678
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
674679
/*/
@@ -753,7 +758,10 @@ class EdgeEditor extends UNISYS.Component {
753758
/*/ render () {
754759
const { edgeID, parentNodeLabel } = this.props;
755760
const { formData, sourceNode, targetNode, edgePrompts } = this.state;
756-
const me = <span style={{color:"rgba(0,0,0,0.2)",fontStyle:"italic"}}>this node</span>;
761+
const me = <span style={{ color: "rgba(0,0,0,0.2)", fontStyle: "italic" }}>this node</span>;
762+
// special override to allow editing an edge that has the same parent node for both source and target
763+
let sameSourceAndTarget = (sourceNode.label === this.props.parentNodeLabel) &&
764+
(targetNode.label === this.props.parentNodeLabel);
757765
return (
758766
<div>
759767

@@ -782,6 +790,7 @@ class EdgeEditor extends UNISYS.Component {
782790
disabledValue={sourceNode.label}
783791
inactiveMode={parentNodeLabel===sourceNode.label ? 'static' : 'disabled'}
784792
shouldIgnoreSelection={!this.state.sourceIsEditable}
793+
placeholder={this.state.placeholder}
785794
/>
786795
<Button outline size="sm" className="float-right"
787796
hidden={ !(this.state.isEditable &&
@@ -816,13 +825,17 @@ class EdgeEditor extends UNISYS.Component {
816825
<AutoComplete
817826
identifier={'edge'+edgeID+'target'}
818827
disabledValue={targetNode.label}
819-
inactiveMode={parentNodeLabel===targetNode.label ? 'static' : 'disabled'}
828+
inactiveMode={ ( parentNodeLabel===targetNode.label && !sameSourceAndTarget ) ? 'static' : 'disabled'}
820829
shouldIgnoreSelection={!this.state.targetIsEditable}
830+
placeholder={this.state.placeholder}
821831
/>
822832
<Button outline size="sm" className="float-right"
823833
hidden={ !(this.state.isEditable &&
824834
this.state.hasValidTarget &&
825-
(targetNode.label!==this.props.parentNodeLabel)) }
835+
( (targetNode.label !== this.props.parentNodeLabel) ||
836+
sameSourceAndTarget )
837+
)
838+
}
826839
onClick={this.onChangeTarget}
827840
title="Select a different target node"
828841
>Change Target</Button>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ class NodeSelector extends UNISYS.Component {
217217
this.state.edges.forEach(edge => {
218218
if ((edge.source.id === updatedNodeID) || (edge.target.id === updatedNodeID)) needsUpdate = true;
219219
})
220-
if (needsUpdate) UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [currentNodeID] });
220+
if (needsUpdate) {
221+
if (DBG) console.log('NodeSelector.SOURCE_UPDATE triggering SOURCE_SELECT with', currentNodeID)
222+
UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [currentNodeID] });
223+
}
221224
});
222225
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223226
/*/ NODE_EDIT is usually requested by NodeTable.
@@ -364,7 +367,7 @@ class NodeSelector extends UNISYS.Component {
364367
if ( (activeAutoCompleteId!==thisIdentifier) &&
365368
(activeAutoCompleteId!=='search') ) return;
366369

367-
if (!this.state.isEditable) {
370+
if (!this.state.isEditable && !this.state.edgesAreLocked) {
368371
if (data.nodes && data.nodes.length>0) {
369372

370373
// A node was selected, so load it
@@ -730,6 +733,7 @@ class NodeSelector extends UNISYS.Component {
730733
isDuplicateNodeLabel: false
731734
}, () => {
732735
// Wait for the edit state to clear, then open up the original node
736+
if (DBG) console.log('NodeSelector.onEditOriginal triggering SOURCE_SELECT with', duplicateNodeID)
733737
UDATA.LocalCall('SOURCE_SELECT', { nodeIDs: [duplicateNodeID] });
734738
});
735739
this.AppCall('AUTOCOMPLETE_SELECT', { id: 'search' });

build/app/view/netcreate/nc-logic.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,13 @@ MOD.Hook("INITIALIZE", () => {
376376

377377
if (nodeID) {
378378
node = m_FindNodeById(nodeID); // Node IDs should be integers, not strings
379+
if (DBG) console.log(PR, "SOURCE_SELECT found by nodeID", nodeID, 'node:', node);
379380
} else if (nodeLabel) {
380381
node = m_FindMatchingNodesByLabel(nodeLabel).shift();
382+
if (DBG) console.log(PR, "SOURCE_SELECT found by nodeLabel", nodeLabel, "node:", node);
381383
} else {
382384
// No node selected, so deselect
385+
if (DBG) console.log(PR, "SOURCE_SELECT found no node", node);
383386
}
384387

385388
if (DBG) console.log(PR, "SOURCE_SELECT found", node);
@@ -435,7 +438,7 @@ MOD.Hook("INITIALIZE", () => {
435438
});
436439

437440
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inside hook
438-
/*/ SOURCE_SEARCH_AND_SELECT first searches for an exact mathcing node
441+
/*/ SOURCE_SEARCH_AND_SELECT first searches for an exact matching node
439442
and if found, selects it.
440443
This is called by AutoComplete onBlur in case we need to make an
441444
implicit selection.
@@ -444,6 +447,7 @@ MOD.Hook("INITIALIZE", () => {
444447
let { searchString } = data;
445448
let node = m_FindMatchingNodesByLabel(searchString).shift();
446449
if (node && (node.label === searchString)) {
450+
console.log(PR,'SOURCE_SEARCH_AND_SELECT about to trigger SOURCE_SELECT data was',data);
447451
m_sourceSelect({ nodeIDs: [node.id] });
448452
}
449453
});

0 commit comments

Comments
 (0)