Skip to content

Commit 0f7ae37

Browse files
committed
add sort and filtering
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 427d965 commit 0f7ae37

3 files changed

Lines changed: 60 additions & 21 deletions

File tree

product_portfolio/filters.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
from vulnerabilities.models import RISK_SCORE_RANGES
4444
from vulnerabilities.models import Vulnerability
4545
from vulnerabilities.models import VulnerabilityAnalysisMixin
46+
from vulnerabilities.triage.models import TriageAction
47+
from vulnerabilities.triage.models import TriageRecord
4648

4749

4850
class HasComplianceIssueFilter(django_filters.BooleanFilter):
@@ -584,3 +586,32 @@ class Meta:
584586
"is_pinned",
585587
"is_direct",
586588
]
589+
590+
591+
class TriageRecordFilterSet(DataspacedFilterSet):
592+
dropdown_fields = ["action"]
593+
594+
q = SearchFilter(
595+
label=_("Search"),
596+
search_fields=[
597+
"product_package__package__name",
598+
"product_package__package__namespace",
599+
"product_package__package__version",
600+
],
601+
)
602+
action = django_filters.ChoiceFilter(
603+
label=_("Action"),
604+
choices=TriageAction.choices,
605+
empty_label=_("All actions"),
606+
)
607+
sort = DefaultOrderingFilter(
608+
label=_("Sort"),
609+
fields=[
610+
("product_package__package__name", "package"),
611+
("detected_date", "detected_date"),
612+
],
613+
)
614+
615+
class Meta:
616+
model = TriageRecord
617+
fields = ["action"]

product_portfolio/templates/product_portfolio/tabs/tab_triage.html

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
{% load i18n %}
22

3-
<div class="d-flex justify-content-between align-items-center mb-3">
4-
<div class="text-body-secondary small">
5-
{{ total_count }} package{{ total_count|pluralize }} with pending triage action{{ total_count|pluralize }}
6-
</div>
7-
{% if page_obj.paginator.num_pages > 1 %}
8-
{% include 'pagination/object_list_pagination.html' with hx_target=tab_id_html %}
9-
{% endif %}
10-
</div>
3+
{% include 'tabs/pagination.html' with search_verbose_name="packages" %}
114

125
<table class="table table-bordered table-md text-break">
13-
<thead>
14-
<tr>
15-
<th style="width: 38%">{% trans "Package" %}</th>
16-
<th style="width: 22%">{% trans "Recommended action" %}</th>
17-
<th>{% trans "Vulnerability exposure" %}</th>
18-
<th style="width: 10%" class="text-nowrap">{% trans "Detected" %}</th>
19-
</tr>
20-
</thead>
6+
{% include 'includes/object_list_table_header.html' %}
217
<tbody>
228
{% for record in page_obj.object_list %}
239
<tr>
@@ -87,6 +73,3 @@
8773
{% endfor %}
8874
</tbody>
8975
</table>
90-
{% if page_obj.paginator.num_pages > 1 %}
91-
{% include 'pagination/object_list_pagination.html' with hx_target=tab_id_html %}
92-
{% endif %}

product_portfolio/views.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
from product_portfolio.filters import ProductComponentFilterSet
120120
from product_portfolio.filters import ProductFilterSet
121121
from product_portfolio.filters import ProductPackageFilterSet
122+
from product_portfolio.filters import TriageRecordFilterSet
122123
from product_portfolio.forms import AttributionConfigurationForm
123124
from product_portfolio.forms import BaseProductRelationshipInlineFormSet
124125
from product_portfolio.forms import ComparisonExcludeFieldsForm
@@ -1369,12 +1370,25 @@ class ProductTabTriageView(
13691370
LoginRequiredMixin,
13701371
BaseProductViewMixin,
13711372
PaginationMixin,
1373+
TableHeaderMixin,
13721374
TabContentView,
13731375
):
13741376
template_name = "product_portfolio/tabs/tab_triage.html"
13751377
paginate_by = 50
13761378
query_dict_page_param = "triage-page"
13771379
tab_id = "triage"
1380+
table_model = TriageRecord
1381+
filterset_class = TriageRecordFilterSet
1382+
table_headers = (
1383+
Header("package", _("Package"), help_text=_("Package with a pending triage action")),
1384+
Header("action", _("Recommended action"), filter="action"),
1385+
Header(
1386+
"vulnerability_exposure",
1387+
_("Vulnerability exposure"),
1388+
help_text=_("Known vulnerabilities affecting this package"),
1389+
),
1390+
Header("detected_date", _("Detected")),
1391+
)
13781392

13791393
def get_context_data(self, **kwargs):
13801394
product = self.object
@@ -1424,7 +1438,17 @@ def get_context_data(self, **kwargs):
14241438
)
14251439
total_count = triage_qs.count()
14261440

1427-
paginator = Paginator(triage_qs, self.paginate_by)
1441+
self.filterset = self.filterset_class(
1442+
self.request.GET,
1443+
queryset=triage_qs,
1444+
dataspace=product.dataspace,
1445+
prefix=self.tab_id,
1446+
anchor=f"#{self.tab_id}",
1447+
)
1448+
1449+
context_data = super().get_context_data(**kwargs)
1450+
1451+
paginator = Paginator(self.filterset.qs, self.paginate_by)
14281452
page_number = self.request.GET.get(self.query_dict_page_param)
14291453
page_obj = paginator.get_page(page_number)
14301454

@@ -1434,11 +1458,12 @@ def get_context_data(self, **kwargs):
14341458
record.action_badge_class = badge_class
14351459
record.action_icon = icon
14361460

1437-
context_data = super().get_context_data(**kwargs)
14381461
context_data.update(
14391462
{
1463+
"filterset": self.filterset,
14401464
"page_obj": page_obj,
14411465
"total_count": total_count,
1466+
"search_query": self.request.GET.get(f"{self.tab_id}-q", ""),
14421467
}
14431468
)
14441469

0 commit comments

Comments
 (0)