Skip to content

Commit 2f31a47

Browse files
authored
Cleanup global Notifications code (#4431)
- Remove saas code for styling the global notification feed. - Update/fix the default view to show last 30 days activities. - Add support for quering the last 3 month activities - Remove unused 'notifications_dropdown.html' html and python code - update the admin bar to use the `adminbar` component.
1 parent 053feed commit 2f31a47

File tree

6 files changed

+42
-79
lines changed

6 files changed

+42
-79
lines changed

hypha/apply/activity/filters.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class NotificationFilter(django_filters.FilterSet):
1414
("yesterday", _("Yesterday")),
1515
("week", _("Past 7 days")),
1616
("month", _("This month")),
17+
("three_months", _("Last 3 months")),
1718
]
1819
timestamp_filters = {
1920
"today": lambda qs, name: qs.filter(
@@ -39,6 +40,12 @@ class NotificationFilter(django_filters.FilterSet):
3940
"month": lambda qs, name: qs.filter(
4041
**{"%s__year" % name: now().year, "%s__month" % name: now().month}
4142
),
43+
"three_months": lambda qs, name: qs.filter(
44+
**{
45+
"%s__gte" % name: _truncate(now() - timedelta(days=90)),
46+
"%s__lt" % name: _truncate(now() + timedelta(days=1)),
47+
}
48+
),
4249
}
4350

4451
date = DateRangeFilter(

hypha/apply/activity/templates/activity/include/notifications_dropdown.html

-15
This file was deleted.

hypha/apply/activity/templates/activity/notifications.html

+24-12
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@
33
{% block title %}{% trans "Notifications" %}{% endblock %}
44

55
{% block content %}
6-
<div class="admin-bar">
7-
<div class="admin-bar__inner">
8-
<div class="admin-bar__inner--with-button">
9-
<h1 class="gamma heading heading--no-margin heading--bold">{% trans "Notifications" %}</h1>
10-
<form class="form notifications__filters" method="get">
11-
{{ filter.form }}
12-
<button class="button button--primary" type="submit" value="Filter">{% trans "Filter" %}</button>
13-
</form>
14-
</div>
15-
</div>
16-
</div>
6+
7+
{% adminbar %}
8+
{% slot header %}{% trans "Notifications" %}{% endslot %}
9+
{% slot sub_heading %}
10+
{% if PROJECTS_ENABLED %}
11+
{% trans "Activity feed across all applications and projects" %}
12+
{% else %}
13+
{% trans "Activity feed across all the applications" %}
14+
{% endif %}
15+
{% endslot %}
16+
17+
<form
18+
class="[&>label]:sr-only text-black flex items-center justify-between gap-2"
19+
method="get"
20+
>
21+
{{ filter.form }}
22+
<button class="button button--primary" type="submit" value="Filter">
23+
{% trans "Filter" %}
24+
</button>
25+
</form>
26+
{% endadminbar %}
1727

1828
<div class="wrapper wrapper--large wrapper--outer-space-medium">
1929
<div class="border-b-2 border-b-slate-300">
@@ -82,7 +92,9 @@ <h1 class="gamma heading heading--no-margin heading--bold">{% trans "Notificatio
8292
</div>
8393

8494
{% if not object_list %}
85-
{% trans "No comments available" %}
95+
<p class="mb-8 text-xl">
96+
{% trans "No activities found, try updating your filters." %}
97+
</p>
8698
{% endif %}
8799
</section>
88100
</div>

hypha/apply/activity/views.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class ActivityContextMixin:
8989
def get_context_data(self, **kwargs):
9090
# Do not prefetch on the related_object__author as the models
9191
# are not homogeneous and this will fail
92-
user = self.request.user
9392
activities = services.get_related_activities_for_user(
9493
self.object, self.request.user
9594
)
@@ -100,7 +99,7 @@ def get_context_data(self, **kwargs):
10099
else:
101100
application_obj = self.object.submission
102101

103-
comments_count = services.get_comment_count(application_obj, user)
102+
comments_count = services.get_comment_count(application_obj, self.request.user)
104103

105104
extra = {"activities": activities, "comments_count": comments_count}
106105
return super().get_context_data(**extra, **kwargs)
@@ -167,23 +166,21 @@ class NotificationsView(ListView):
167166
template_name = "activity/notifications.html"
168167
filterset_class = NotificationFilter
169168

170-
def get_template_names(self):
171-
if self.request.htmx and self.request.GET.get("type") == "header_dropdown":
172-
return ["activity/include/notifications_dropdown.html"]
173-
return super().get_template_names()
174-
175169
def get_queryset(self):
176-
# List only last 30 days' activities
177170
queryset = Activity.objects.filter(current=True).latest()
178171

179-
self.filterset = self.filterset_class(self.request.GET, queryset=queryset)
180-
qs = self.filterset.qs.distinct().order_by("-timestamp", "source_object_id")
172+
# filter by one month by default
173+
date_filter = self.request.GET.get("date", "month")
181174

182-
if self.request.htmx and self.request.GET.get("type") == "header_dropdown":
183-
qs = qs[:5]
184-
return qs
175+
self.filterset = self.filterset_class(
176+
{"date": date_filter}
177+
if date_filter not in self.request.GET
178+
else self.request.GET,
179+
queryset=queryset,
180+
)
181+
return self.filterset.qs.distinct().order_by("-timestamp", "source_object_id")
185182

186183
def get_context_data(self, *, object_list=None, **kwargs):
187-
context = super(NotificationsView, self).get_context_data()
184+
context = super().get_context_data()
188185
context["filter"] = self.filterset
189186
return context

hypha/static_src/sass/components/_activity-notifications.scss

-37
This file was deleted.

hypha/static_src/sass/main.scss

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
@use "components/data-block";
4545
@use "components/invoice-block";
4646
@use "components/two-factor";
47-
@use "components/activity-notifications";
4847
@use "components/dropdown";
4948
@use "components/dashboard-table";
5049

0 commit comments

Comments
 (0)