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

Temp hide show ui for plain and comment highlights #348

Conversation

JustinHoldstock
Copy link
Contributor

This change hides UI elements in the CRUD process of Plain and Comment highlight annotations.

THIS IS A TEMPORARY CHANGE UNTIL WE CAN PROPERLY REFACTOR COMMENT AND PLAIN HIGHLIGHTS

As always, tests to come :)

@@ -7,7 +7,7 @@ const ANNOTATORS = [
NAME: 'Document',
CONSTRUCTOR: DocAnnotator,
VIEWER: ['Document', 'Presentation'],
TYPE: [TYPES.point, TYPES.highlight]
TYPE: [TYPES.point, TYPES.highlight, TYPES.highlight_comment]
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@@ -315,6 +312,39 @@ class CreateHighlightDialog extends EventEmitter {
* @return {HTMLElement} The element containing Highlight creation UI
*/
createElement() {
const caretTemplate = this.isMobile
Copy link
Contributor

Choose a reason for hiding this comment

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

should we move these templates out into constants somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would've made more sense than what I did :D DONE!

this.highlightCreateEl.addEventListener('click', this.onHighlightClick);

if (this.hasTouch) {
this.highlightCreateEl.addEventListener('touchstart', this.stopPropagation);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move the adding of these 2 event handlers into its own method? so you can just call it anywhere on w/e element you pass in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure this'd be valid for the touchend -> highlightClick event binding, as it only ever happens once. Would it be valid abstracting the binding for stopPropagation()?

Maybe instead of

element.addEventListener('event', this.stopPropagation);

We'd do

this.bindStopPropagation(element, event);

Though, after seeing it, I'm not sure what the benefit of that is

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm true. I guess it wouldn't really clean up too much.

if (this.commentHighlightEnabled) {
this.highlightCurrentSelection = this.highlightCurrentSelection.bind(this);
this.createHighlightDialog.addListener(CreateEvents.comment, this.highlightCurrentSelection);
this.createHighlightThread = this.createHighlightThread.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

new line before this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -390,7 +423,17 @@ class DocAnnotator extends Annotator {
// Scale existing canvases on re-render
this.scaleAnnotationCanvases(pageNum);

super.renderAnnotationsOnPage(pageNum);
if (this.threads && this.threads[pageNum]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually if you just leave the call to super.renderAnnotationsOnPage(pageNum)
We can modify annotator.renderAnnotationsOnPage() to this since w/e annotation types aren't supported will get filtered out w/ the call to this.isModeAnnotatable(thread.type)

    renderAnnotationsOnPage(pageNum) {
        if (this.threads && this.threads[pageNum]) {
            this.threads[pageNum].forEach((thread) => {
                if (!this.isModeAnnotatable(thread.type)) {
                    return;
                }
                
                thread.show();
            });
        }
    }

Plus then it'll be applicable to any other annotation types we don't want to render :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Check if there's anywhere else we can just make calls to isModeAnnotatable() to Annotator or AnnotationThread methods to clean up some of hackier logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll override the super call to do this, but I still have to not call it, as we're calling our butchered version of show() that takes in the flags for plain and comment highlights

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make a ticket for the cleanup, as I don't want this task to turn into a refactor/cleanup PR. Then we can do it, next

@@ -751,7 +800,7 @@ class DocAnnotator extends Annotator {
// hovered over at the same time, only the top-most highlight
// dialog will be displayed and the others will be hidden
// without delay
delayThreads.forEach(showFirstDialogFilter);
delayThreads.forEach(showFirstDialogFilter.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

is this able to be bound elsewhere?

Copy link
Contributor

@pramodsum pramodsum left a comment

Choose a reason for hiding this comment

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

There will be merge conflicts from #316 and #358. Let me know if you have any questions about those conflicts!

this.commentBox = new CommentBox(containerEl);
this.commentCreateEl = containerEl.querySelector(`.${constants.CLASS_ADD_HIGHLIGHT_COMMENT_BTN}`);
this.commentCreateEl.addEventListener('click', this.onCommentClick);
// Event listeners
Copy link
Contributor

Choose a reason for hiding this comment

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

new line above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// Event listeners
this.commentBox.addListener(CommentBox.CommentEvents.post, this.onCommentPost);
this.commentBox.addListener(CommentBox.CommentEvents.cancel, this.onCommentCancel);
// Hide comment box, by default
Copy link
Contributor

Choose a reason for hiding this comment

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

new line before comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -122,12 +149,19 @@ class DocAnnotator extends Annotator {
*/
destroy() {
super.destroy();
if (this.createHighlightDialog) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (!this.createHighlightDialog) {
  return;
}

@@ -485,7 +542,11 @@ class DocAnnotator extends Annotator {
this.highlightThrottleHandle = null;
}

if (this.hasTouch && this.isMobile) {
if (!this.canAnnotate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now stored as this.permissions.canAnnotate. Update this around the code! See https://github.com/box/box-content-preview/blob/master/src/lib/annotations/Annotator.js#L70

if (showPlain) {
annotatorUtil.showElement(plainButtonEl);
} else {
annotatorUtil.hideElement(plainButtonEl);
Copy link
Contributor

Choose a reason for hiding this comment

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

You wouldn't ever show the plain highlight dialog AND the comments dialog correct? Can we combine these 2 if/else statements?

Copy link
Contributor Author

@JustinHoldstock JustinHoldstock Sep 5, 2017

Choose a reason for hiding this comment

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

This code is for only showing/hiding the buttons

Copy link
Contributor

Choose a reason for hiding this comment

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

ah right not showing/hiding specific types of dialogs. got it

Copy link
Contributor

@pramodsum pramodsum left a comment

Choose a reason for hiding this comment

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

Need to sort through merge conflicts from #316 and #358.

@@ -485,6 +547,10 @@ class DocAnnotator extends Annotator {
this.highlightThrottleHandle = null;
}

if (!this.permissions.canAnnotate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say it's unnecessary to remove it, as we don't want to be removing event listeners that don't exist. I'm not sure what our standard is for that. @jeremypress @tonyjin @minhhnguyen Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's safe to remove event listeners that don't exist. I'd personally prefer fewer lines of code over adding a guard before removing event listeners but I don't think this is something we need to standardize on.

if (showPlain) {
annotatorUtil.showElement(plainButtonEl);
} else {
annotatorUtil.hideElement(plainButtonEl);
Copy link
Contributor

Choose a reason for hiding this comment

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

ah right not showing/hiding specific types of dialogs. got it

}

// TODO (@jholdstock|@spramod) remove this if statement, and make super call, upon refactor.
const pageThreads = this.getThreadsOnPage(pageNum);
Copy link
Contributor

Choose a reason for hiding this comment

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

at this point, isn't this the same as calling super.renderAnnotationsOnPage()? Since that also checks isModeAnnotatable(type) and that's essentially when this.plainHighlightEnabled and this.commentHighlightEnabled is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that the override is passing in the two flags, which are not done in the parent class

 thread.show(this.plainHighlightEnabled, this.commentHighlightEnabled);

@JustinHoldstock JustinHoldstock dismissed pramodsum’s stale review September 5, 2017 20:59

Conflicts were easy peasy!

…ew into Temp-hide-show-ui-for-plain-and-comment-highlights
@JustinHoldstock JustinHoldstock merged commit 3dbddbf into box:master Sep 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.

4 participants