Skip to content
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

Merged
merged 7 commits into from
Apr 25, 2017

Conversation

daniilsavchuk
Copy link
Collaborator

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:

  1. Empty Ports
    empty-view

  2. Available to connect ports (during link dragging)
    available-view

Changes

  1. Visualizer.js - override the Paper validateConnection method to take into account the workflow binding
  2. pipeline.scss - added styles for empty and available ports
  3. Paper.js - switched on the markAvailable JointJS feature and updated the port validation condition
  4. VisualStep.js - changed update method to support port style switching in case of situation

@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.703% when pulling 3b68ddd on multiple-link-fix into fa591e4 on dev.

Copy link
Contributor

@voidest voidest left a 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.

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)) {
Copy link
Contributor

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.

Copy link
Collaborator Author

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

@@ -86,6 +86,20 @@ export default class Visualizer {
this._timer = null;
this._step = null;
this.clear();

this.paperDefaultValidateConnectionMethod = this.paper.options.validateConnection;
Copy link
Contributor

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?

Copy link
Collaborator Author

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

if (port.group === 'out') {
isEmpty = isEmpty && (_.size(step.o[port.id].inputs) === 0 && _.size(step.o[port.id].outputs) === 0);
}

Copy link
Contributor

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.

Copy link
Collaborator Author

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

@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.703% when pulling 3571b0a on multiple-link-fix into fa591e4 on dev.

Copy link
Member

@paulsmirnov paulsmirnov left a 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.

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') ||
Copy link
Member

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.

Copy link
Collaborator Author

@daniilsavchuk daniilsavchuk Apr 21, 2017

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!

@@ -86,6 +86,20 @@ export default class Visualizer {
this._timer = null;
this._step = null;
this.clear();

const paperDefaultValidateConnectionMethod = this.paper.options.validateConnection;
Copy link
Member

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?

Copy link
Collaborator Author

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

@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.703% when pulling dc6f291 on multiple-link-fix into fa591e4 on dev.

Copy link
Contributor

@voidest voidest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Copy link
Member

@paulsmirnov paulsmirnov left a 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);
});
Copy link
Member

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 :)

Copy link
Collaborator Author

@daniilsavchuk daniilsavchuk Apr 24, 2017

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)

@sidoruka sidoruka merged commit 9d7b41f into dev Apr 25, 2017
@sidoruka sidoruka deleted the multiple-link-fix branch April 25, 2017 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants