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 dc7b986 commit 49d367e
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 57 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 @@ -3,7 +3,7 @@
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.htmx.widgets import BadgeDropdownMultiSelect, SearchDropdownMultiSelect


filter_backend = get_filter_backend()
Expand All @@ -27,11 +27,13 @@ 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...",
},
extra={
"hx_get": "htmx:search-tags",
},
),
required=False,
label="Tags",
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 @@ -9,4 +9,5 @@
path("<int:pk>/", views.incident_detail, name="incident-detail"),
path("update/<str:action>/", views.incident_update, name="incident-update"),
path("filter/", views.filter_form, name="incident-filter"),
path("search-tags", views.search_tags, name="search-tags"),
]
24 changes: 22 additions & 2 deletions src/argus/htmx/incident/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

from django import forms
from django.contrib.auth import get_user_model
from django.shortcuts import render, get_object_or_404
from django.shortcuts import redirect, render, get_object_or_404

Check failure on line 8 in src/argus/htmx/incident/views.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (F401)

src/argus/htmx/incident/views.py:8:30: F401 `django.shortcuts.redirect` imported but unused

from django.views.decorators.http import require_POST, require_GET
from django.core.paginator import Paginator
from django.http import HttpResponse, HttpResponseBadRequest
from django_htmx.http import HttpResponseClientRefresh

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

from ..request import HtmxHttpRequest
Expand Down Expand Up @@ -97,6 +97,26 @@ def filter_form(request: HtmxHttpRequest):
return render(request, "htmx/incident/_incident_filterbox.html", context=context)


@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 49d367e

Please sign in to comment.