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

Annotation deletion popup (bug 1899731) #18900

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ryzokuken
Copy link

This PR adds a simple popup/snackbar setup and wires it up for annotation removal, so when a user deletes any number of annotations, they get a message about it alongside an undo button that allows them to quickly undo the deletion.

Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

This will need tests in the various editors, in https://github.com/mozilla/pdf.js/tree/master/test/integration, or maybe its own new test file that tests that the toast is properly shown in the various cases.

src/display/editor/tools.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Is this perhaps related to https://bugzilla.mozilla.org/show_bug.cgi?id=1899731, since there seems to be no mention of that bug here?

Please note that we'll need a "full" design specification before implementing this, and given its current state the code will also require a fair amount of work here (as far as I can tell).

web/message_bar.css Outdated Show resolved Hide resolved
@marco-c marco-c changed the title Annotation deletion popup Bug 1899731 - Annotation deletion popup Oct 14, 2024
@marco-c marco-c changed the title Bug 1899731 - Annotation deletion popup Annotation deletion popup (bug 1899731) Oct 14, 2024
@marco-c
Copy link
Contributor

marco-c commented Oct 14, 2024

Is this perhaps related to https://bugzilla.mozilla.org/show_bug.cgi?id=1899731, since there seems to be no mention of that bug here?

Please note that we'll need a "full" design specification before implementing this, and given its current state the code will also require a fair amount of work here (as far as I can tell).

I added a link to the Figma specs in the bug. It should be accessible to all of you (let me know if you don't have access, and I'll get you added).

web/viewer.html Outdated Show resolved Hide resolved
web/message_bar.css Show resolved Hide resolved
web/message_bar.css Outdated Show resolved Hide resolved
web/pdf_viewer.css Outdated Show resolved Hide resolved
bottom: 100px;
left: 50%;
transform: translateX(-50%);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test that everything is rendering fine when switching to HCM mode on Windows ?

@nicolo-ribaudo
Copy link
Contributor

nicolo-ribaudo commented Oct 14, 2024

@calixteman @Snuffleupagus Please wait to review until when this PR is marked as ready -- I am giving some feedback to @ryzokuken to make sure that it matches correctly what is defined in the figma doc :)

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Leaving just a few high-level comments regarding things/patterns that should be improved.

l10n/en-US/viewer.ftl Outdated Show resolved Hide resolved
this.#toastManager.show(
undo,
editors.length > 1
? `${editors.length} annotations`
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Oct 14, 2024

Choose a reason for hiding this comment

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

This won't be possible to localize properly, since it hard-codes the word "annotations".

Comment on lines 124 to 127
--message-bar-icon-color: #0060DF;
--message-bar-bg-color: #deeafc;
--message-bar-fg-color: #15141a;
--text-primary-color: #15141a;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not be using different colours depending on light/dark/HCM mode?

web/pdf_viewer.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/viewer.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
ryzokuken added a commit to ryzokuken/pdf.js that referenced this pull request Oct 14, 2024
This is a temporary commit on this branch that aims to address some of the review comments from the PR at mozilla#18900.
@ryzokuken
Copy link
Author

First off, thanks everyone for all the comments it's nice to have a stronger sense of direction as to where I need to take this patch. I addressed some of the comments y'all made and marked the appropriate suggestions as "resolved" although please feel free to re-raise anything.

To respond to the questions:

Is this perhaps related to bugzilla.mozilla.org/show_bug.cgi?id=1899731, since there seems to be no mention of that bug here?

Please note that we'll need a "full" design specification before implementing this, and given its current state the code will also require a fair amount of work here (as far as I can tell).

Yes it is! Thanks @marco-c for the clarification and sharing the spec. Regarding the code, I hope the bigger pain points have either already been addressed or I'd be hacking on them shortly.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Based on looking at the code, I believe that there's various cases where the notification won't be closed immediately as I believe is intended when:

  • Restoring the editor with Ctrl+Z (i.e. using the keyboard).
  • Toggling editing-mode off.
  • The entire editorLayer is being destroyed (i.e. when closing the current PDF document).

web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/viewer.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
web/toast_manager.js Outdated Show resolved Hide resolved
@ryzokuken
Copy link
Author

@Snuffleupagus

(I don't know what setInterval has to do with this, since that's not related to the issue I mentioned above.)

Apologies, I misunderstood your comment at first. Applied the fix that you'd ultimately suggested.

I've marked a number of your comments as resolved, please take a look and let me know if I missed something from my latest commit while I work on addressing the remaining issues. Thanks again for your patience.

web/viewer.html Outdated Show resolved Hide resolved
web/message_bar.css Outdated Show resolved Hide resolved
web/message_bar.css Outdated Show resolved Hide resolved
web/viewer.html Outdated Show resolved Hide resolved
web/viewer.html Outdated Show resolved Hide resolved
web/viewer.js Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
l10n/en-US/viewer.ftl Outdated Show resolved Hide resolved
@ryzokuken
Copy link
Author

@Snuffleupagus thanks for the last slew of suggestions especially, it taught me a lot about the code and fixed the l10n bug. The code should ideally look much more manageable now. While I make more improvements and add tests, please let me know if you have any further comments.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Another thing that I think should be supported is closing the undo-bar with the Esc key, and the easiest solution would be to (after implementing the comments below) also add the following code just after this existing code:

if (this.editorUndoBar?.isOpen) {
  this.editorUndoBar.hide();
  handled = true;
}

web/message_bar.css Outdated Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/editor_undo_bar.js Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
@ryzokuken
Copy link
Author

I added the ESC key dismiss thingie but note that it's not part of the Figma spec which says:

The message bar should persist on screen until:

  • User clicks “X” close
  • User creates a new annotation
  • User opens Print dialog
  • User opens Save dialog
  • User selects an option from the “more” menu
  • User closes tab
  • User closes session

Maybe we should get the ESC key condition added there.

@Snuffleupagus
Copy link
Collaborator

I added the ESC key dismiss thingie but note that it's not part of the Figma spec which says:

The message bar should persist on screen until:

[...]

Note also the other cases mentioned previously in #18900 (review), maybe those should be added to that list as well?

@ryzokuken
Copy link
Author

Absolutely, I'll mention this to the UX folks.

web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
web/editor_undo_bar.js Outdated Show resolved Hide resolved
@ryzokuken
Copy link
Author

Good point, I cleaned up the class fields and simplified the constructor a bit.

@nicolo-ribaudo
Copy link
Contributor

The first commit also (accidentally) fixes a bug in the existing .messageBar usage, where the X was not vertically aligned in the button:

image

web/app.js Outdated
Comment on lines 456 to 464
let editorUndoBar = null;
if (appConfig.editorUndoBar) {
editorUndoBar = new EditorUndoBar(
appConfig.editorUndoBar,
eventBus,
l10n
);
}
this.editorUndoBar = editorUndoBar;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can now be simplified, see also the next comment.

Suggested change
let editorUndoBar = null;
if (appConfig.editorUndoBar) {
editorUndoBar = new EditorUndoBar(
appConfig.editorUndoBar,
eventBus,
l10n
);
}
this.editorUndoBar = editorUndoBar;
if (appConfig.editorUndoBar) {
this.editorUndoBar = new EditorUndoBar(
appConfig.editorUndoBar,
eventBus
);
}

web/app.js Outdated
@@ -460,6 +472,7 @@ const PDFViewerApplication = {
linkService: pdfLinkService,
downloadManager,
altTextManager,
editorUndoBar,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
editorUndoBar,
editorUndoBar: this.editorUndoBar,

freetext: "pdfjs-editor-undo-bar-message-freetext",
stamp: "pdfjs-editor-undo-bar-message-stamp",
ink: "pdfjs-editor-undo-bar-message-ink",
__multiple: "pdfjs-editor-undo-bar-message-multiple",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't a single underscore suffice here?

Comment on lines 51 to 68
async show(undoAction, messageData) {
this.hide();
this.isOpen = true;
this.#controller = new AbortController();

this.#message.textContent =
typeof messageData === "string"
? await this.#l10n.get(EditorUndoBar.#l10nMessages[messageData])
: await this.#l10n.get(EditorUndoBar.#l10nMessages.__multiple, {
count: messageData,
});
this.#container.hidden = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to translate this "manually", since that should only be done as a last resort?
Also, the introduction of await here could lead to intermittent bugs with the bar reshowing after having been hidden elsewhere.

Suggested change
async show(undoAction, messageData) {
this.hide();
this.isOpen = true;
this.#controller = new AbortController();
this.#message.textContent =
typeof messageData === "string"
? await this.#l10n.get(EditorUndoBar.#l10nMessages[messageData])
: await this.#l10n.get(EditorUndoBar.#l10nMessages.__multiple, {
count: messageData,
});
this.#container.hidden = false;
show(undoAction, messageData) {
this.hide();
if (typeof messageData === "string") {
this.#message.setAttribute("data-l10n-id", EditorUndoBar.#l10nMessages[messageData]);
} else {
this.#message.setAttribute("data-l10n-id", EditorUndoBar.#l10nMessages._multiple)
this.#message.setAttribute("data-l10n-args", JSON.stringify({ count: messageData });
}
this.isOpen = true;
his.#container.hidden = false;
this.#controller = new AbortController();

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, thank you!

@nicolo-ribaudo nicolo-ribaudo force-pushed the popup-undo-annotation branch 2 times, most recently from a0c05d3 to a7b37b7 Compare October 18, 2024 10:57
@@ -404,6 +404,9 @@ class AnnotationEditorLayer {
// Do nothing on right click.
return;
}

this.#uiManager._eventBus.dispatch("annotationstart", { source: this });
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment applies elsewhere as well.

  • Is there possibly a more "central" spot where this can be done, since having this code in a bunch of places seems potentially error prone (since it's easy to miss adding a case)?
  • The event name isn't very specific, as far as I'm concerned. (But please see below.)
  • Ideally the undo-bar hiding would, in my opinion, be placed within the src/display/editor/-code as much as possible. (With events only used for features that are clearly outside of that folder.)
    With that in mind, could we change this to the following instead?
    Suggested change
    this.#uiManager._eventBus.dispatch("annotationstart", { source: this });
    this.#uiManager._editorUndoBar?.hide()

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there possibly a more "central" spot where this can be done, since having this code in a bunch of places seems potentially error prone (since it's easy to miss adding a case)?

We originally tried looking for a central place but couldn't find a good one. The problem is some of the editors are created when they are "enabled" by clicking on the toolbar (example: the ink one), while others are created only when the user actually starts writing in them (example: the freetext one).

@@ -804,6 +807,7 @@ class AnnotationEditorUIManager {
rotation: 0,
};
this.isShiftKeyDown = false;
this.#editorUndoBar = editorUndoBar;
Copy link
Collaborator

Choose a reason for hiding this comment

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

To support the suggestion above.

Suggested change
this.#editorUndoBar = editorUndoBar;
this._editorUndoBar = editorUndoBar;

eventBus._on("beforeprint", boundHide);
eventBus._on("download", boundHide);
eventBus._on("annotationstart", boundHide);
eventBus._on("secondarytoolbaraction", boundHide);
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this suggestion would be slight abuse of notation, do we really need a new event just for this or could we use the already existing one instead?

Suggested change
eventBus._on("secondarytoolbaraction", boundHide);
eventBus._on("reporttelemetry", evt => {
if (evt?.details?.type === "buttons") {
boundHide();
}
});

Copy link
Contributor

Choose a reason for hiding this comment

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

We originally considered this, but yeah it felt a bit too much abusing an event for something that's not meant to. Ideally an event called "reporttelemetry" should not have UI effects other than... reporting telemetry 😅.

Happy to change it if you feel strongly though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just add a click listener on the window (capture) and check if the target is under the toast bar ?
It's something we do in order to hide the secondary toolbar:
https://github.com/mozilla/pdf.js/blob/master/web/app.js#L2750-L2765

Copy link
Author

Choose a reason for hiding this comment

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

@calixteman about this one, does your comment imply that the toast should be over other UI elements like the toolbar? Or did you mean that we should dismiss the toast if the user clicks another element like in the case of the toolbar?

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

There's a few additional cases where the undo-bar should also be hidden (which should be possible to implement within the src/display/editor/-code):

  • When toggling editing off (i.e. setting AnnotationEditorType.NONE).
  • When destroying the editor.

test/integration/freetext_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/freetext_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/freetext_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/freetext_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/highlight_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/highlight_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/highlight_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/ink_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/stamp_editor_spec.mjs Outdated Show resolved Hide resolved
test/integration/freetext_editor_spec.mjs Outdated Show resolved Hide resolved
ryzokuken and others added 7 commits October 21, 2024 13:28
Move .messageBar out of .dialog into its own standalone class in order to reuse as much of it for the upcoming feature for an undo message for annotations.
When a user deletes any number of annotations, they are notified of the action
by a popup message with an undo button. Besides that, this change reuses the
existing messageBar CSS class from the new alt-text dialog as much as possible.
Fix colors in dark and high contrast modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants