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

feat(annotations): add ftux cursor logic #1281

Merged
merged 16 commits into from
Nov 10, 2020

Conversation

ChenCodes
Copy link
Contributor

@ChenCodes ChenCodes commented Nov 3, 2020

Changes in this PR:

  • add logic to hide popup cursor after the first time that the user explicitly clicks the create region button
  • hide cursor using styles

Todo:

  • add tests

Demo:
ezgif com-gif-maker (3)

src/lib/viewers/image/ImageViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/image/ImageViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/image/ImageViewer.js Outdated Show resolved Hide resolved
if (!this.cache.get(IMAGE_FTUX_CURSOR_DISABLED_KEY)) {
this.cache.set(IMAGE_FTUX_CURSOR_DISABLED_KEY, true, true /* useLocalStorage */);
} else {
this.annotator.emit('annotations_image_explicit_create_toggled');
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we're both passing in options to the annotator and emitting events to it. Are they related? Can this be simplified?

Copy link
Contributor Author

@ChenCodes ChenCodes Nov 3, 2020

Choose a reason for hiding this comment

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

They are related:

  • On a fresh reload of the page, we want to pass the ftux cursor flag via options to the annotator. That will need to be done within initAnnotations. That logic can't be done here because this method is for handling the user click event on the Create Region button.
  • The first time that the the user clicks on the Create Region button, we want to update the flag within localStorage. The second time that they click on the Create Region button, we no longer want to update the flag (it's already set), but we do want to emit an event that would cause a rerender of RegionCreator.

I'm not aware of how this could be simplified but would be open to suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer need to pass in options to the annotator after implementing the css approach.

src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
@ChenCodes ChenCodes force-pushed the ftux-cursor-experience branch from 676eb8d to de18983 Compare November 3, 2020 21:56
@ChenCodes ChenCodes marked this pull request as ready for review November 4, 2020 18:22
@ChenCodes ChenCodes requested a review from a team as a code owner November 4, 2020 18:22
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
@@ -1596,6 +1596,11 @@ class DocBaseViewer extends BaseViewer {

handleAnnotationControlsClick({ mode }) {
const nextMode = this.annotationControlsFSM.transition(AnnotationInput.CLICK, mode);

if (nextMode === AnnotationMode.REGION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

annotationControlsFSM currently subscribes to the transition changes but calls updateDiscoverabilityResinTag directly, perhaps we could introduce a handler that also checks for this condition and applies the class there.

Also it seems like we would want to update localStorage on the transition from REGION to NONE, or even to REGION but only trigger the logic to apply the class on any subsequent transition to REGION

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline that since the transition changes only happen when the user clicks, we're okay with not needing the handler.

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 debating whether this should be moved out to a fsm callback. This method is pretty mode agnostic so I'm wary of cluttering it with some region specific code. Let's do the callback because that'll be easier to strip out eventually too since it'll be it's own separate function. Something like:

this.annotationControlsFSM.subscribe(this.applyCursorFtux);

src/lib/viewers/doc/_docBase.scss Outdated Show resolved Hide resolved
*/
handleFtuxCursorToggle(key) {
if (!this.cache.get(key)) {
this.cache.set(key, true, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, should we perform this ftux on a per user id basis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After doing some digging, it looks like we don't need to do it on a per user id basis because localStorage sessions are different for unique users.

@@ -162,13 +167,15 @@ class BaseViewer extends EventEmitter {
this.mobileZoomEndHandler = this.mobileZoomEndHandler.bind(this);
this.handleAnnotatorEvents = this.handleAnnotatorEvents.bind(this);
this.handleAnnotationControlsEscape = this.handleAnnotationControlsEscape.bind(this);
this.applyCursorFtux = this.applyCursorFtux.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.

Are these binds required? and L178

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They weren't required previously, but with the addition of the subscribe call, they are now required.

src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
@@ -1596,6 +1596,11 @@ class DocBaseViewer extends BaseViewer {

handleAnnotationControlsClick({ mode }) {
const nextMode = this.annotationControlsFSM.transition(AnnotationInput.CLICK, mode);

if (nextMode === AnnotationMode.REGION) {
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 debating whether this should be moved out to a fsm callback. This method is pretty mode agnostic so I'm wary of cluttering it with some region specific code. Let's do the callback because that'll be easier to strip out eventually too since it'll be it's own separate function. Something like:

this.annotationControlsFSM.subscribe(this.applyCursorFtux);


.bp-content {
&.bp-annotations-ftux-image-cursor-seen {
.bp-image {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the .bp-image a needed specificity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is required.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about if we did &.bp-annotations--create-region.bp-annotations-ftux-image-cursor-seen?

src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/BaseViewer.js Outdated Show resolved Hide resolved
@ChenCodes
Copy link
Contributor Author

ChenCodes commented Nov 9, 2020

#1281 (comment)

Yes it's needed.

src/lib/viewers/doc/DocBaseViewer.js Outdated Show resolved Hide resolved
src/lib/viewers/doc/DocBaseViewer.js Outdated Show resolved Hide resolved
@@ -370,6 +370,12 @@ $thumbnail-sidebar-width: 226px;
}
}

&.bp-annotations-ftux-document-cursor-seen {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be moved into &.bp-annotations-create--region above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep this works as well.


.bp-content {
&.bp-annotations-ftux-image-cursor-seen {
.bp-image {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about if we did &.bp-annotations--create-region.bp-annotations-ftux-image-cursor-seen?

@ChenCodes ChenCodes dismissed jstoffan’s stale review November 10, 2020 23:07

Dismissing as this PR has been approved

@ChenCodes ChenCodes merged commit b1a47b4 into box:master Nov 10, 2020
@ChenCodes ChenCodes deleted the ftux-cursor-experience branch November 10, 2020 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants