Skip to content

Chore: Store threads.annotations as an object by annotationID#5

Merged
pramodsum merged 8 commits intobox:masterfrom
pramodsum:refactor
Oct 31, 2017
Merged

Chore: Store threads.annotations as an object by annotationID#5
pramodsum merged 8 commits intobox:masterfrom
pramodsum:refactor

Conversation

@pramodsum
Copy link
Copy Markdown
Contributor

@pramodsum pramodsum force-pushed the master branch 19 times, most recently from b5efd2a to 3521db1 Compare October 25, 2017 02:47
Copy link
Copy Markdown
Contributor

@JustinHoldstock JustinHoldstock left a comment

Choose a reason for hiding this comment

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

I know it's painful to see all the getFirstAnnotation() comments, but I'm marking them as such so it's easier for you to find them.

Comment thread src/Annotator.js Outdated
this.bindCustomListenersOnThread(thread);

this.emit(ANNOTATOR_EVENT.fetch);
if (this.modeControllers[firstAnnotation.type]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you assign controller above the if, instead of doing a double lookup?

Comment thread src/doc/DocAnnotator.js Outdated
if (annotations.length > 0) {
threadParams.threadID = annotations[0].threadID;
threadParams.threadNumber = annotations[0].threadNumber;
if (Object.keys(annotations).length > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could circumvent having to check the length of annotations every time by having annotatorUtil.getFirstAnnotation() return null of the list is empty. Then you could just check
if (firstAnnotation)...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

Comment thread src/doc/DocDrawingDialog.js Outdated

if (annotations.length > 0) {
this.assignDrawingLabel(annotations[0]);
if (Object.keys(annotations).length > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See getFirstAnnotation() comment above

Comment thread src/doc/DocDrawingDialog.js Outdated
const canDelete = canCommit || (annotations[0].permissions && annotations[0].permissions.can_delete);
const canCommit = Object.keys(annotations).length === 0;
const firstAnnotation = annotatorUtil.getFirstAnnotation(annotations);
const canDelete = canCommit || (firstAnnotation.permissions && firstAnnotation.permissions.can_delete);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this blow up if first annotation doesn't exist?

Comment thread src/doc/DocHighlightDialog.js Outdated
// Determine if highlight buttons or comments dialog will display
if (annotations.length > 0) {
this.hasComments = annotations[0].text !== '' || annotations.length > 1;
if (Object.keys(annotations).length > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See getFirstAnnotation() comment above

const highlightButtons = this.highlightDialogEl.querySelector(constants.SELECTOR_HIGHLIGHT_BTNS);
annotatorUtil.hideElement(highlightButtons);
} else if (annotations[0].permissions && !annotations[0].permissions.can_delete) {
} else if (firstAnnotation.permissions && !firstAnnotation.permissions.can_delete) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How's this handle no firstAnnotation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a check in the if statement above to make sure firstAnnotation exists

Comment thread src/doc/DocHighlightThread.js Outdated
if (this.annotations.length && this.annotations[0].permissions && !this.annotations[0].permissions.can_delete) {
const firstAnnotation = annotatorUtil.getFirstAnnotation(this.annotations);
if (
Object.keys(this.annotations).length &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since first annotation cannot exist if this.annotations is empty, just check for firstAnnotation, and comments on getFirstAnnotation()?

Comment thread src/doc/DocHighlightThread.js Outdated
// Ensures that previously created annotations have the right type
if (this.annotations.length) {
if ((this.annotations[0].text !== '' || this.annotations.length > 1) && this.type === TYPES.highlight) {
if (Object.keys(this.annotations).length) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Above comment on getFirstAnnotation()

} else {
this.deleteAnnotation(this.annotations[0].annotationID);
const firstAnnotation = annotatorUtil.getFirstAnnotation(this.annotations);
this.deleteAnnotation(firstAnnotation.annotationID);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this behave if no first annotation?

Comment thread src/image/ImageAnnotator.js Outdated
if (annotations.length > 0) {
threadParams.threadID = annotations[0].threadID;
threadParams.threadNumber = annotations[0].threadNumber;
if (Object.keys(annotations).length > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getFirstAnnotation() comments above

Copy link
Copy Markdown
Contributor

@JustinHoldstock JustinHoldstock left a comment

Choose a reason for hiding this comment

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

Great stuff!

@pramodsum pramodsum merged commit 080c0f3 into box:master Oct 31, 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.

2 participants