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

New updates toast message only when button is displayed #5306

Merged
merged 6 commits into from
Mar 15, 2023

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Mar 9, 2023

This PR changes the logic introduced in #5305 to make sure the message is toasted only when pending updates goes from 0 to a value greater than zero, which effectively means it is toasted when the button to refresh notifications is displayed.

If for any reason the pending notifications are increased before the notifications are refreshed, this prevents the message to be toasted again, which might be overwhelming on documents with a lot of activity.

Testing steps:

  1. Change to this branch on your local client instance.
  2. Open it using your local network address (192.168.x.x:3000), not localhost:3000.
  3. Make sure you are logged in and the sidebar is "focused".
  4. Run a screen reader service.
  5. Open the same network address on a different device which is on the same network (I have been testing it with my mobile phone).
  6. Login and add an annotation on the second device: The screen reader on the first device should announce that there's a new annotation available.
  7. Before clicking on the refresh button, add another annotation from the second device: The screen reader should not announce anything.
  8. Click on refresh annotations on the first device.
  9. Add another annotation from the second device: The screen reader should announce that there are new annotations available.

@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Merging #5306 (5e64dc2) into main (ffdc0b3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #5306   +/-   ##
=======================================
  Coverage   99.17%   99.17%           
=======================================
  Files         235      236    +1     
  Lines        9345     9354    +9     
  Branches     2241     2241           
=======================================
+ Hits         9268     9277    +9     
  Misses         77       77           
Impacted Files Coverage Δ
src/sidebar/components/TopBar.tsx 100.00% <ø> (ø)
src/sidebar/components/PendingUpdatesButton.tsx 100.00% <100.00%> (ø)
src/sidebar/store/modules/real-time-updates.js 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@lyzadanger lyzadanger left a comment

Choose a reason for hiding this comment

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

Getting real close here, I think!

I had a couple of suggestions...

useEffect(() => {
if (hasPendingUpdates) {
toastMessenger.success(
`There are ${pendingUpdateCount} new annotations.`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Because we will only announce once and not again until any additional annotations are loaded in, I think we might consider not announcing the specific count, as it may not be accurate by the time the user loads in the annotations.

Suggested change
`There are ${pendingUpdateCount} new annotations.`,
`New annotations are available`,

This will read better when it can be followed with "Press (whatever) to load these annotations". And even better down the line when we can confirm with "X new annotations loaded".

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I see now why you were a little ambivalent about adding a hasPendingUpdates selector, since this component also needs pendingUpdateCount. But I still think it's fine...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, I see now why you were a little ambivalent about adding a hasPendingUpdates selector, since this component also needs pendingUpdateCount. But I still think it's fine...

Yes. I mean, we could have a locally memoized flag which depends on the amount. Something in these lines:

const hasPendingUpdates = useMemo(() => pendingUpdateCount > 0, [pendingUpdateCount]);

But if we are going to do that we may as well have the selector, which is easier to reason about and can be used somewhere else if needed.

}`}
/>
)}
<PendingUpdatesButton onClick={applyPendingUpdates} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that PendingUpdatesButton is already pretty self sufficient and makes use of the toastMessengerService, I wonder if you might go ahead and inject the streamer service into it, and free TopBar from having to know about streamer. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

Comment on lines 32 to 34
// We only want this effect to trigger when changing from no-updates to at
// least one update, not every time the amount changes
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may be out of date. Can you check the dependencies here?

@acelaya
Copy link
Contributor Author

acelaya commented Mar 10, 2023

Thanks @lyzadanger! All suggestions pushed.

@acelaya acelaya requested a review from lyzadanger March 10, 2023 08:35
@lyzadanger
Copy link
Contributor

lyzadanger commented Mar 10, 2023

@acelaya In the hopes that this will make your testing strategy easier: you don't have to use different devices to test this feature. All you need is a separate session (browser profile, different browser, e.g.). For example, here is a screen shot of me using:

  • localhost in both cases
  • Chrome, logged in as devdata_admin (this is a user you get for free with devdata)
  • Safari, logged in as another user (I created this one at some point). With this user, I create a new annotation. My Chrome session (open on the same document) then sees the "pending-annotations" button

I hope this makes your life a little easier?

image

(Safari here is on top of the Chrome session)

Edited: Oh wait, I think I get it. It's not possible to retain focus on the iframe that would announce the pending update in this setup. Disregard!

@acelaya
Copy link
Contributor Author

acelaya commented Mar 10, 2023

Oh wait, I think I get it. It's not possible to retain focus on the iframe that would announce the pending update in this setup. Disregard!

Exactly 😅.

I used this approach at first, but I had to end up adding a small timeout to dispatching the reduce action so that I had time to go back to the main window before it got actually dispatched, otherwise the screen reader would not announce anything.

At some point it became cumbersome to have to remember which file needed to be excluded from commits, plus I realized I was not testing the real behavior and thought I might miss something. That's when I moved to use two devices.

Copy link
Contributor

@lyzadanger lyzadanger left a comment

Choose a reason for hiding this comment

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

SO so so so so so close! Looking good! There is one thing I'd like to address: ToastMessageItem will prefix success or error toast messages with the word Success: or Error: respectively. If you set the message as a notice type, it shouldn't do that prefixing (right now, the word Success: is announced as part of the message: let's get rid of that). I think these are "notice" type messages, anyway.

Everything else is working great...let's get this done!

toastMessenger: ToastMessengerService;
streamer: StreamerService;
Copy link
Contributor

Choose a reason for hiding this comment

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

World's teensiest nit: I tend to alphabetize injected service props.

@@ -217,6 +217,17 @@ function hasPendingDeletion(state, id) {
return hasOwn(state.pendingDeletions, id);
}

/**
* Return true if an annotation has been created on the server, but it has not
* yet been applied.
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording "applied" is somewhat vague. I imagine you derived this comment from elsewhere: don't worry about it for now, and I can see why applied could make sense (I mean, the annotations are loaded already in a sense...). This makes me realize that I should familiarize myself with the flow of "pending" annotations a little better: then I might be able to provide a suggestion...

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, I kept "applied" for consistency with other comments, but it was not super obvious to me neither, to be honest. I wouldn't mind finding a better wording.

@acelaya acelaya changed the base branch from new-annotations-toast to main March 10, 2023 13:40
@acelaya acelaya force-pushed the new-annotations-toast-throttle branch from c74451f to ac096f8 Compare March 10, 2023 13:49
@acelaya
Copy link
Contributor Author

acelaya commented Mar 10, 2023

@lyzadanger changed to use notice toast messages instead of success ones, and ordered the injected services.

@acelaya acelaya force-pushed the new-annotations-toast-throttle branch from 61b34e7 to 5e64dc2 Compare March 15, 2023 11:41
Copy link
Contributor

@lyzadanger lyzadanger left a comment

Choose a reason for hiding this comment

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

All righty, let's get this landed!

@acelaya acelaya merged commit 63897c3 into main Mar 15, 2023
@acelaya acelaya deleted the new-annotations-toast-throttle branch March 15, 2023 13:08
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.

Screen reader does not announce when new/updated annotations are available
2 participants