-
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: thread save incorrectly rejects when no dialogue exists #247
Conversation
The line |
ImageAnnotator uses -1 to indicate that it is a single paged image. I have a separate PR (#249) to change page -1 to page 1 for images. Having -1 pages was just how it was implemented beforehand to indicate that we didn't care for pages in images, but that definitely changed once we added the multi-page image annotations. |
After @pramodsum and @minhhnguyen's discussion, is this still a valid PR? |
@JustinHoldstock |
LGTM but someone with more annotations expertise should verify |
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.
Can you write a test for this?
tests incoming |
|
||
if (this.dialog) { | ||
// Add thread number to associated dialog and thread | ||
if (this.dialog.element && this.dialog.element.dataset) { | ||
this.dialog.element.dataset.threadNumber = this.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.
This will be setting the dialog thread number to null
this.dialog.element.dataset.threadNumber = this.threadNumber;
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.
fixed
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.
@pramodsum tests in and variable name updated
this.saveAnnotationToThread(savedAnnotation); | ||
} else { | ||
// Otherwise, replace temporary annotation with annotation saved to server | ||
this.annotations[tempIdx] = savedAnnotation; |
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 that this.annotations[-1]
would have tempAnnotation
in it? Would we need to replace it with the correct one no matter what?
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.
See comment above about setting the dialog thread number
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.
Just some small cleanup and looks good to me!
* @param {Annotation} localAnnotation - The temporary annotation holding place of the server validated annotation | ||
* @return {void} | ||
*/ | ||
updateLocalAnnotationFromServer(serverAnnotation, localAnnotation) { |
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.
Thanks for moving this out and writing tests! 👍
this.dialog.removeAnnotation(tempAnnotationID); | ||
} | ||
}) | ||
.then((savedAnnotation) => this.updateLocalAnnotationFromServer(savedAnnotation, tempAnnotation)) |
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'd like to keep the naming consistent. Can we make this method either updateTempAnnotation(...) or change tempAnnotation, tempIdx, and other temp variables to localAnnotation, etc?
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.
changing all localAnnotation variable names to tempAnnotation
* | ||
* @private | ||
* @param {Annotation} serverAnnotation - The annotation returned by the backend. Use this as the source of truth | ||
* @param {Annotation} localAnnotation - The temporary annotation holding place of the server validated annotation |
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.
The temporary annotation stored locally holding place of the server validated annotation
* @return {void} | ||
*/ | ||
updateLocalAnnotationFromServer(serverAnnotation, localAnnotation) { | ||
const tempIdx = this.annotations.indexOf(localAnnotation); |
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.
choose temp or local
this.dialog.element.dataset.threadNumber = this.threadNumber; | ||
} | ||
|
||
this.dialog.addAnnotation(serverAnnotation); |
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.
// Removes temporary/local annotation and replaces it with the annotation saved to server
stubs.saveAnnotationToThread = sandbox.stub(thread, 'saveAnnotationToThread'); | ||
thread.annotations.push(serverAnnotation) | ||
thread.updateLocalAnnotationFromServer(replacementAnnotation, serverAnnotation); | ||
thread.on('annotationcreateerror', () => { |
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.
Not sure the check on 'annotationcreateerror'
needs to be in the unit tests for updateLocalAnnotationFromServer()
. Might make sense to move the portion of code called in the catch block into it's own method and move this check there.
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.
Good point, I've removed this portion from the tests.
Just make sure you test this thoroughly with all the different annotation types just to be sure 👍 |
I'll go through a quick sanity check prior to merging this |
Promise would reject upon successful creation of annotation on the backend due to attempted dereferences on null/undefined objects.
Might have future issues with
this.thread = this.thread || savedAnnotation.thread;
if create(annotationData) returns a null annotation object.
This is not likely, I just haven't read through all of AnnotationService.
For
this.annotations[tempIdx] = savedAnnotation;
,let me know if this.annotations[-1] is actually intentional. I saw that ImageAnnotator uses threads.page[-1] as a valid index.