Skip to content

Conversation

@pheus
Copy link
Contributor

@pheus pheus commented Oct 17, 2025

Fixes: #20301

Add a “Dismiss all” action to the bell dropdown that clears all unread notifications for the current user via a GET endpoint. The dropdown continues to show up to the most recent 10 unread items, and now includes a clear, i18n’d confirmation message that shows the total number of unread notifications affected.

Summary of changes

  • New view: NotificationDismissAllView registered with @register_model_view(Notification, name='dismiss_all', path='dismiss-all', detail=False); deletes unread notifications for request.user.

    • HTMX requests: if invoked from the Notifications page, return an HX-Redirect to repaint the page; otherwise return the existing dropdown partial.
    • Non‑HTMX requests: redirect to the Notifications page.
  • Dropdown partial context: Now passes only the top 10 unread notifications plus counts:
    notifications = request.user.notifications.unread()[:10],
    total_count = request.user.notifications.count(),
    unread_count = request.user.notifications.unread().count(). :contentReference[oaicite:1]{index=1}

  • Template update (htmx/notifications.html):
    Adds a “Dismiss all” button in the dropdown header when there are unread items, with a pluralized confirmation that shows the total unread count (e.g., “Dismiss 37 unread notifications?”).

  • HTMX utility helpers:
    Introduce htmx_current_url() and htmx_maybe_redirect_current_page() to detect the current page (via HX-Current-URL) and issue an HX-Redirect when appropriate. Both are now used by the single‑item dismiss view and the new dismiss-all view to avoid stale rows on the Notifications page. :contentReference[oaicite:3]{index=3}

Screenshots

Screenshots (notifications present)

Screenshot 2025-10-22 at 14-10-59 Subscriptions NetBox Screenshot 2025-10-22 at 14-10-41 Subscriptions NetBox

Screenshots (no notifications)

Screenshot 2025-10-17 at 00-36-58 Home NetBox Screenshot 2025-10-17 at 00-37-04 Home NetBox

Notes for reviewers

  • The button label uses “Dismiss all” to align with the route name (dismiss-all).

@jeremystretch jeremystretch requested review from a team and bctiemann and removed request for a team October 17, 2025 20:47
Copy link
Contributor

@bctiemann bctiemann left a comment

Choose a reason for hiding this comment

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

@pheus This works well and after a lot of thought about whether "Clear" was the right terminology (as opposed to "Mark Read" or "Dismiss"), I think probably "Clear" is clear enough, though maybe "Dismiss" is a little more consistent. The issue I have is that our existing terminology isn't very consistent — we use "Delete Selected" for the bulk delete button, and "dismiss" for the URL path, and then we muddle things up with the "read" path for when you click on the notification to view the object it pertains to, which makes it no longer "new" (a dirty badge), but doesn't remove it from your list of notifications, but also doesn't have any differentiator between it and an "unread" notification (well, it's shown in a slightly dimmed gray). "Clear" is a new terminology that has no precedent, but then most other terminology we have is implicit at best. So I'm okay with "Clear" because it obviously does "the right thing" as far as what the user is most likely to want.

I did notice one funny corner case: if you are viewing the Notifications page and you use the "Clear All" button to dismiss all unread notifications, those notifications stay in the list (because the action was done through HTMX and does not repaint the page). Then if you click on the trash can icon for any of the now-deleted notifications, or use the "Delete Selected" button, you get a 404 error.

Could you please give that some thought and see if there's a simple way to avoid that behavior, maybe by forcing a refresh if you're viewing the Notifications page? Or maybe the right answer is it isn't worth trying to prevent that, depending on how much effort it involves.

Thanks!

@pheus
Copy link
Contributor Author

pheus commented Oct 20, 2025

Thanks for the thoughtful review!

Terminology
I’ll think this through, but your points have me leaning toward “Dismiss all” to match the existing dismiss-all route and view. “Clear all” came from the issue text, but I agree we shouldn’t introduce another term.

Corner case
I’ve seen the same behavior when using the ❌ in the dropdown while the notifications table is open. I’ll think it through and report back; if it turns out non‑trivial or brittle, I’m comfortable keeping the current behavior.

Thanks again!

@pheus
Copy link
Contributor Author

pheus commented Oct 21, 2025

Quick design question about the dropdown UX:

The bell dropdown shows up to 10 unread items, but the new “Dismiss all” currently clears all unread notifications for the user. To avoid surprises, what’s your preference?

  • A. Keep “Dismiss all” but show the total unread count and a clear confirm (e.g., “Dismiss all 37 unread?”).
  • B. Scope the action to only the visible 10.
  • C. Offer both: “Dismiss shown (10)” and “Dismiss all (N)”.

Happy to implement whichever aligns best with NetBox’s UX. Thanks!

@jeremystretch
Copy link
Member

I would prefer option A. Seems like the most common use case IMO.

Introduce a view to allow users to dismiss all unread notifications with
a single action. Update the notifications' template to include a
"Dismiss all" button for enhanced usability. This addition streamlines
notification management and improves the user experience.

Fixes netbox-community#20301
@pheus pheus force-pushed the 20301-add-clear-all-option-to-user-notifications-dropdown branch from d8627e7 to 8eaff9d Compare October 22, 2025 12:00
@pheus pheus changed the title Closes #20301: Add "Clear all" action to notifications dropdown Closes #20301: Add "Dismiss all" action to notifications dropdown Oct 22, 2025
Comment on lines -7 to 8
from django.db.models import Count, Q
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse, Http404
from django.shortcuts import get_object_or_404, redirect, render
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This is an unrelated fix. Http404 is used, but not imported.

Comment on lines -521 to 522
return render(request, 'htmx/notifications.html', {
'notifications': request.user.notifications.unread(),
'notifications': request.user.notifications.unread()[:10],
'total_count': request.user.notifications.count(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

During manual testing, I've noticed that the dropdown menu does not actually limit the notification.

@pheus
Copy link
Contributor Author

pheus commented Oct 22, 2025

Thanks again for the thoughtful review!

What I changed based on your feedback

  • Terminology: Switched the UI copy to “Dismiss all” to align with the existing dismiss-all route and keep wording consistent.
  • Scope clarity: The confirm now includes the unread count (e.g., “Dismiss all 37 unread notifications?”) so it’s clear the action may affect more than the 10 items shown in the dropdown.

Stale-list fix

  • To address the Notifications page corner case, I added a small HTMX helper that returns HX-Redirect when the action originates from account:notifications. That fully repaints the page; elsewhere the dropdown still refreshes in place.

Optional UI tweak

  • While testing, I tried an icon‑only version of the button to match the existing delete actions. Screenshots are below. If you prefer that look, I’m happy to update the PR.

Open to any tweaks on copy, placement, or behavior—thanks again for the thoughtful guidance!

Icon-Only Design:

Screenshot 2025-10-22 at 14-11-25 Subscriptions NetBox Screenshot 2025-10-22 at 14-11-51 Subscriptions NetBox

@pheus pheus requested a review from bctiemann October 22, 2025 12:26
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.

Add a "clear all" option to the user notifications dropdown

3 participants