-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValidateConnection method fixed to prevent multiple links into single input port. #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everithing seems OK for me; nonetheless, there I a copule of concerns I would like to clarify.
src/visual/Visualizer.js
Outdated
this.paper.options.validateConnection = (cellViewS, magnetS, cellViewT, magnetT, end, linkView) => { | ||
const args = [cellViewS, magnetS, cellViewT, magnetT, end, linkView]; | ||
|
||
if (this.paperDefaultValidateConnectionMethod.call(this.paper, ...args)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little bit concerned about the usage of the spread syntax here since there is an apply method which does not require dots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very strong notice and I followed this to make code seems more cleanly. Thank you very much.
Done in 3b68ddd commit
src/visual/Visualizer.js
Outdated
@@ -86,6 +86,20 @@ export default class Visualizer { | |||
this._timer = null; | |||
this._step = null; | |||
this.clear(); | |||
|
|||
this.paperDefaultValidateConnectionMethod = this.paper.options.validateConnection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to hold this value as a member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for the review, it is very valuable!
I have followed this recommendation and it has been done in b29a2e2 commit
src/visual/VisualStep.js
Outdated
if (port.group === 'out') { | ||
isEmpty = isEmpty && (_.size(step.o[port.id].inputs) === 0 && _.size(step.o[port.id].outputs) === 0); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain me the reason for putting isEmpty &&
in expressions above. As far as I understand, both if-conditions are mutually exclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So usefull advise thank you very much!
Done in dc9b29b commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid there's an opportunity for the bug to appear that's need to be addressed before merging the PR.
src/visual/Paper.js
Outdated
if (!magnetT || magnetT.getAttribute('class') !== 'port-body' || | ||
if (!magnetT || (magnetT.getAttribute('class') !== 'port-body' && | ||
magnetT.getAttribute('class') !== 'port-body-empty' && | ||
magnetT.getAttribute('class') !== 'port-body-empty available-magnet') || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to write the condition in a more compact and error-proof way? I'm a bit disappointed by multiple getAttribute()
calls and strict comparisons. What if there are two spaces between classes? different class order? one more (irrelevant) class that we decide to add later? The condition will be broken in this case and we'll waste our time on debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so for this comment. I thought about it when wrote a code upper, but it was moddified old variant (I did not change this condition paradigm). Anyway thank you very much. This method has been refactored, according to your advice and was pushed with the d9b5b6b commit!
src/visual/Visualizer.js
Outdated
@@ -86,6 +86,20 @@ export default class Visualizer { | |||
this._timer = null; | |||
this._step = null; | |||
this.clear(); | |||
|
|||
const paperDefaultValidateConnectionMethod = this.paper.options.validateConnection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't oldValidateConnection
or just validateConnection
be shorter and more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you it is a nice note. The second proposed variant was selected.
Done in 3571b0a commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thank you.
|
||
_.forEach(portClasses, (portClass) => { | ||
result = result && (availableClasses.indexOf(portClass) >= 0); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lodash has a great shortcut for such iterations:
result = _.some(portClasses, pc => availableClasses.indexOf(pc) >= 0);
Probably, it would be even better to swap arrays (shorter - first). Also, _.intersection()
is worth mentioning :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for this advise. I promise I will use it in future in suitable situations not only at this code snippet (I hope it will be refactored by me in the next PR)
General idea
Currently Pipeline Builder does not take into account the links to the global workflow ports during new connection validation.This allows to bind multiple links into single input port which results in code generation errors.
This pull request introduces improved ValidateConnection method:
Check the global port bindings (to prevent adding link if it is already bound to workflow port) and making Pipeline Builder able to show the available ports to bind while dragging the new link.
According to this new checking method it becomes untrivial to understand which port is available to be connected, by this way pull reques also introduce the GUI improvements as follow:
Empty Ports
![empty-view](https://camo.githubusercontent.com/1de6c3acdb52fc61627debf36a3e2a7d6aad164baa91cfd62cb5a36e0098db66/687474703a2f2f70622e6f70656e736f757263652e6570616d2e636f6d2f646174612f656d707479706f7274732e706e67)
Available to connect ports (during link dragging)
![available-view](https://camo.githubusercontent.com/b5a027325baf1847d948d39b79e47393643867b12291ffbfa8e260774a92d2a9/687474703a2f2f70622e6f70656e736f757263652e6570616d2e636f6d2f646174612f617661696c61626c65706f7274732e706e67)
Changes