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

Correctly hide/show quota notifications per project #2222

Merged
merged 1 commit into from
Oct 6, 2017

Conversation

dtaylor113
Copy link
Contributor

@dtaylor113 dtaylor113 commented Oct 5, 2017

Addresses issues when switching between projects and viewing and hiding/clearing quota notifications.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1495455#c4

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 5, 2017
Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

My worry is that this doesn't fix the problem for other notifications that don't include the project name in the ID.

@dtaylor113 If you prepend the project name to the uid the notification drawer assigns, does it just work?

https://github.com/openshift/origin-web-console/blob/master/app/scripts/directives/notifications/notificationDrawerWrapper.js#L187

This might be a one line fix without needing the common changes?

@@ -74,7 +74,8 @@ angular.module("openshiftConsole")
var setQuotaNotifications = function(quotas, clusterQuotas, projectName) {
var notifications = QuotaService.getQuotaNotifications(quotas, clusterQuotas, projectName);
_.each(notifications, function(notification) {
if(!NotificationsService.isNotificationPermanentlyHidden(notification)) {
// Only add a quota notification if it wasn't specifically set to be hidden by user
if(!NotificationsService.isNotificationHidden(notification)) {
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 this should be necessary since the drawer tracks what was cleared in session storage. I think the drawer should know whether to show or hide the notification already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My worry is that this doesn't fix the problem for other notifications that don't include the project name in the ID.

That's why I was working in namespace into the common NotificationsService 😄

@dtaylor113 If you prepend the project name to the uid the notification drawer assigns, does it just work?

https://github.com/openshift/origin-web-console/blob/master/app/scripts/directives/notifications/notificationDrawerWrapper.js#L187

This might be a one line fix without needing the common changes?

I'll have to test after removing the isNotificationHidden(..) call in resourceAlerts.js. The drawer currently uses EventsService.isCleared() for filtering the APIEvents; I need to add the EventsService.isCleared() call to the notifications callback.

@openshift-ci-robot openshift-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 5, 2017
@dtaylor113
Copy link
Contributor Author

Until namespace is built into NotificationsService.isNotificationVisible(), I'll need to add projectName to the quota notification id. Setting the uid happens after NotificationsService.addNotification(...)

@dtaylor113 dtaylor113 changed the title [DO NOT MERGE] [WIP] Correctly hide/show quota notifications per project Correctly hide/show quota notifications per project Oct 5, 2017
@dtaylor113
Copy link
Contributor Author

dtaylor113 commented Oct 6, 2017

My worry is that this doesn't fix the problem for other notifications that don't include the project name in the ID.

I had to add projectName into the notification id in order for the NotificationsService to process it correctly. I added a conditional for the uid to include the project name if it isn't already in the id.

@@ -184,7 +185,7 @@
// using uid to match API events and have one filed to pass
// to EventsService for read/cleared, etc
trackByID: notification.trackByID,
uid: id,
uid: _.includes(id, project) ? id : project + "/" + id,
Copy link
Member

Choose a reason for hiding this comment

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

I think we should always prepend project rather than trying to check if it's in id. There's no harm and it makes things simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, fixed -thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree on keeping it simpler. If the id is being created on line 180, can we keep all the id manipulation logic there? Manipulating it in a couple spots might open doors to bugs...

@spadgett
Copy link
Member

spadgett commented Oct 6, 2017

Thanks @dtaylor113. I understand your point now about the memory leak in NotificationsService. I'm good with this change (with one small comment), and I think we should tackle the other problem separately.

@@ -99,6 +99,7 @@
_.each(drawer.notificationGroups, function(group) {
_.remove(group.notifications, { uid: notification.uid, namespace: notification.namespace });
});
delete notificationsMap[$routeParams.project][notification.uid];
Copy link
Member

Choose a reason for hiding this comment

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

@benjaminapetersen Is this a bug in remove? It seems like the _.each above should take care of 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.

The notificationsMap is different from the group.notifications. notificationsMap actually generates the group.notifications when switching projects, so it needs to be cleared in the map as well

Copy link
Member

Choose a reason for hiding this comment

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

I understand, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would think so as well, looking.

@@ -184,7 +185,7 @@
// using uid to match API events and have one filed to pass
// to EventsService for read/cleared, etc
trackByID: notification.trackByID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to keep all the id generation/manipulation together on line 180? I'd tend to think it should always be the same value if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might not be relevant, reviewing again, we have id, trackById, and uid. Bleh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either way, I addressed this particular comment. -thanks

@@ -172,7 +173,7 @@
};

var notificationWatchCallback = function(event, notification) {
if(!notification.showInDrawer) {
if(!notification.showInDrawer || EventsService.isCleared(notification.id)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we be using notification.uid for cleared? We seem to use that in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The notification in this callback doesn't have the uid; the uid is set if it gets past this check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that relates to my comment above. Should always be consistent in the drawer. Think I settled on uid originally because of apiEvents first.

Copy link
Member

Choose a reason for hiding this comment

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

But I don't think we're not checking the right ID.... If we're clearing uid but checking id, isn't this check just wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, addressed this logic issue.

var project = notification.namespace || $routeParams.project;
var id = notification.id ? project + "/" + notification.id : _.uniqueId('notification_') + Date.now();

if(!notification.showInDrawer || EventsService.isCleared(id)) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @dtaylor113, this looks better

@@ -99,6 +99,7 @@
_.each(drawer.notificationGroups, function(group) {
_.remove(group.notifications, { uid: notification.uid, namespace: notification.namespace });
});
delete notificationsMap[$routeParams.project][notification.uid];
Copy link
Member

Choose a reason for hiding this comment

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

I understand, thanks.

@spadgett
Copy link
Member

spadgett commented Oct 6, 2017

[merge]

@openshift-bot
Copy link

Evaluated for origin web console merge up to 033fe62

@openshift-bot
Copy link

openshift-bot commented Oct 6, 2017

Origin Web Console Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin_web_console/320/) (Base Commit: b642a34) (PR Branch Commit: 033fe62)

@openshift-bot openshift-bot merged commit ec0a953 into openshift:master Oct 6, 2017
@dtaylor113
Copy link
Contributor Author

Follow up issue openshift/origin-web-common#220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants