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

Improve notification id #174

Merged

Conversation

benjaminapetersen
Copy link
Contributor

  • _.uniqueId() is not sufficient since the ID is used to persist some data
    for notifications via session storage. The id generated starts at a low
    number & increments w/o randomness.
  • Using _.uniqueId() along with Date.now() adds a random value that cannot
    be replicated across sessions/refresh

Example: with uniqueIds like notification_1, notification_2 it is relatively easy for a notification to be marked read, but following a refresh having read be applied to a completely different notification.

Needed for Notification Drawer updates web console PR 2001.

@spadgett @jeff-phillips-18

- _.uniqueId() is not sufficient since the ID is used to persist some data
  for notifications via session storage.  The id generated starts at a low
  number & increments w/o randomness.
- Using _.uniqueId() along with Date.now() adds a random value that cannot
  be replicated across sessions/refresh
@spadgett spadgett merged commit f4e951e into openshift:master Sep 7, 2017
@benjaminapetersen benjaminapetersen deleted the bpeterse/notification-id branch September 7, 2017 03:17
@@ -18,7 +18,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
};

var addNotification = function (notification) {
notification.id = notification.id || _.uniqueId('notification-');
notification.id = notification.id || _.uniqueId('notification-') + Date.now();
Copy link
Member

Choose a reason for hiding this comment

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

@benjaminapetersen This has already merged, but I realize we can't use notification.id if set by the caller for track by because it won't always be unique. For some messages, we purposely reuse notification.id so they don't get toasted twice.

We probably need to always generated some of unique ID that is set by the service and is always unique. So this might need to be.

notification.uniqueID = _.uniqueId('notification-') + Date.now();

Then we can use that always for track by. This will also fix an animation issue I've noticed with the toast that the slide in animation is reset for already-visible items when new items are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the notification drawer only needs this uniqueID, correct?

I'm wondering if we can rename the filed that gets reused so we don't double toast. I feel like id and uniqueID is a bit confusing. I imagine this creates more work for us elsewhere.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to use it for track by in the toast notifications as well. We have some animation quirks with the toasts because track by isn't correct.

Copy link
Member

Choose a reason for hiding this comment

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

Renaming the field will touch dozens of files across all 3 repositories :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Boo...

So we provide uniqueID and always use that for track by. If the originator of the notification does not set id, we can safely still use the same generated random id for it (like here). So id and uniqueID can match if its irrelevant, correct?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's too terrible if we give the new field a very specific name, maybetrackByID, and a comment that it's there for uniqueness. What do you think?

Yeah, we should always use the unique ID for track by so avoid duplicates in a repeater error. I wouldn't worry about setting notification.id if the caller didn't set one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

works for me! i can open a quick PR to swap this again. 😄

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.

None yet

4 participants