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

Fix: Validating annotation thread params #17

Merged
merged 8 commits into from
Apr 5, 2017
Merged

Fix: Validating annotation thread params #17

merged 8 commits into from
Apr 5, 2017

Conversation

pramodsum
Copy link
Contributor

No description provided.

@@ -62,11 +62,14 @@ class Notification {

/**
* Hides the notification message.
* Does nothing if the notification is already hidden.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick, but I wouldn't make this a second line - Continue the first line and wrap it at a reasonable breaking point.

@@ -432,6 +451,13 @@ class Annotator extends EventEmitter {
* @return {void}
*/
addThreadToMap(thread) {
if (!annotatorUtil.checkThreadValid(thread)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're adding double validation here - move the check to the individual createAnnotationThread() implementations. It makes sense there since each individual annotator knows best about what sort of thread it considers valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I just realized this was extra validation and removed the check here

if (!annotatorUtil.checkThreadValid(thread)) {
this.emit('annotationerror', {
reason: 'validation'
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still iffy on this implementation since if there are multiple validation errors we'd essentially be showing multiple error messages "on top of each other" which doesn't feel great.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe have a private function in the annotator called handleLoadError() that then keeps track of whether we've already shown a notification or not for validation, and if not, show a notification error. We'd then call that function directly whenever we think there's an error (so call checkThreadValid() and handleLoadError() in the false case within the same function). I think it's okay to keep broadcasting the annotationerror event per validation failure, but let's not bind to an event within the same class and repeatedly show the error notification

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make sense to move a check like this into Notification.js to be something like is there a notification already showing which is for the same type of error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonyjin added the check to Notification.js. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

No I don't think adding that to Notification.js is a good idea. It should ideally be as dumb and maintain as little state as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a handleValidationError() method which maintains whether a notification was already displayed once and displays the notification accordingly

@tonyjin
Copy link
Contributor

tonyjin commented Mar 28, 2017

I still don't think this approach is the right way, here are the main points:

  • Emitting the error is fine in case anyone else wants to bind to it in the future, but since we are already within the Annotator class, just call this.handleValidationError() directly and move emitting the error to within that function. The reason we add listeners to the service for 'annotationerror' is because we should not call a Annotator function directly from within the service, but we can pass a message to the Annotator. In this case, we are already within the Annotator.
  • Don't double validate - you have validation when reading and validating when creating - just keep the validation you have using the params map inside createAnnotationThread() and remove checkThreadValid()
  • With the above changes, return null instead of thread when the validateThreadParams() check fails within createAnnotationThread

We can discuss more in person tomorrow if needed.

@pramodsum
Copy link
Contributor Author

@tjin fixed it according to your comments above. Sorry I think I misunderstood what you meant earlier.

- Also includes fix for thread locale to be correctly set for image
  point annotations
- Prevents multiple validation notifications from being triggered while
  another validation notification is already being displayed
… in Annotator

- Returns null when validateThreadParams() fails
*
* @return {void}
*/
hide() {
this.notificationEl.classList.add(CLASS_HIDDEN);
if (this.notificationEl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this always fire, since this.notificationElexists here? You could check to see if the class list contains the hidden class, and do nothing if it does

Copy link
Contributor

Choose a reason for hiding this comment

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

classList already has built in functionality to do nothing if there is already a CLASS_HIDDEN class. I think this is to guard against a situation where notification.hide() is called in a timeout or something after the notification is destroyed so notificationEl could not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

^ exactly why i added it!

@pramodsum pramodsum merged commit 6a357f7 into box:master Apr 5, 2017
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.

3 participants