Skip to content

Commit

Permalink
Add search for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Jan 22, 2025
1 parent 10bc9dd commit 5e34b8d
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 29 deletions.
12 changes: 7 additions & 5 deletions src/argus/htmx/incident/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from argus.filter import get_filter_backend
from argus.incident.models import SourceSystem
from argus.incident.constants import Level
from argus.htmx.widgets import BadgeDropdownMultiSelect
from argus.notificationprofile.models import Filter
from argus.htmx.widgets import BadgeDropdownMultiSelect, SearchDropdownMultiSelect


filter_backend = get_filter_backend()
QuerySetFilter = filter_backend.QuerySetFilter
Expand Down Expand Up @@ -48,11 +49,11 @@ class IncidentFilterForm(forms.Form):
label="Sources",
)
tags = forms.CharField(
widget=forms.TextInput(
widget=SearchDropdownMultiSelect(
attrs={
"placeholder": "enter tags...",
"class": "show-selected-box input input-accent input-bordered input-md border overflow-y-auto min-h-8 h-auto max-h-16 max-w-xs leading-tight",
}
"placeholder": "search tags...",
},
partial_get=None,
),
required=False,
label="Tags",
Expand All @@ -70,6 +71,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# mollify tests
self.fields["sourceSystemIds"].widget.partial_get = reverse("htmx:incident-filter")
self.fields["tags"].widget.partial_get = reverse("htmx:search-tags")

def _tristate(self, onkey, offkey):
on = self.cleaned_data.get(onkey, None)
Expand Down
1 change: 1 addition & 0 deletions src/argus/htmx/incident/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
path("filter-list/", filter.FilterListView.as_view(), name="filter-list"),
path("select-filter/", views.filter_select, name="select-filter"),
path("filter-create/", views.create_filter, name="filter-create"),
path("search-tags/", views.search_tags, name="search-tags"),
]
22 changes: 21 additions & 1 deletion src/argus/htmx/incident/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django_htmx.http import HttpResponseClientRefresh, reswap, retarget

from argus.auth.utils import get_or_update_preference
from argus.incident.models import Incident
from argus.incident.models import Incident, Tag
from argus.notificationprofile.models import Filter
from argus.util.datetime_utils import make_aware

Expand Down Expand Up @@ -134,6 +134,26 @@ def filter_select(request: HtmxHttpRequest):
return retarget(HttpResponse(), "#incident-filter-select")


@require_GET
def search_tags(request):
query = request.GET.get("search")

if not query:
tags = None
else:
if Tag.TAG_DELIMITER in query:
key, value = Tag.split(query)
tags = Tag.objects.filter(key=key, value__icontains=value)[:50]
else:
tags = Tag.objects.filter(key__icontains=query)[:50]

return render(
request,
"htmx/forms/search_results.html",
{"tags": tags},
)


@require_GET
def incident_list(request: HtmxHttpRequest) -> HttpResponse:
columns = get_incident_table_columns()
Expand Down
Loading

0 comments on commit 5e34b8d

Please sign in to comment.