-
Notifications
You must be signed in to change notification settings - Fork 113
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
Conversation
src/lib/Notification.js
Outdated
@@ -62,11 +62,14 @@ class Notification { | |||
|
|||
/** | |||
* Hides the notification message. | |||
* Does nothing if the notification is already hidden. |
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.
Nit-pick, but I wouldn't make this a second line - Continue the first line and wrap it at a reasonable breaking point.
src/lib/annotations/Annotator.js
Outdated
@@ -432,6 +451,13 @@ class Annotator extends EventEmitter { | |||
* @return {void} | |||
*/ | |||
addThreadToMap(thread) { | |||
if (!annotatorUtil.checkThreadValid(thread)) { |
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 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.
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.
Yea I just realized this was extra validation and removed the check here
src/lib/annotations/Annotator.js
Outdated
if (!annotatorUtil.checkThreadValid(thread)) { | ||
this.emit('annotationerror', { | ||
reason: 'validation' | ||
}); |
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 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.
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.
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
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.
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?
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.
@tonyjin added the check to Notification.js. Thoughts?
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.
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
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.
Added a handleValidationError() method which maintains whether a notification was already displayed once and displays the notification accordingly
I still don't think this approach is the right way, here are the main points:
We can discuss more in person tomorrow if needed. |
@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) { |
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 this always fire, since this.notificationEl
exists here? You could check to see if the class list contains the hidden class, and do nothing if it does
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.
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
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.
^ exactly why i added it!
No description provided.