Skip to content

Commit

Permalink
Filter incident by tags with simple input field
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Jan 20, 2025
1 parent bfa8920 commit a305a25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/1044.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add text field to filter incident list by tags
16 changes: 15 additions & 1 deletion src/argus/htmx/incident/filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms

from argus.filter import get_filter_backend
from argus.incident.models import SourceSystem
from argus.incident.models import SourceSystem, Tag

Check failure on line 4 in src/argus/htmx/incident/filter.py

View workflow job for this annotation

GitHub Actions / Lint Python

Ruff (F401)

src/argus/htmx/incident/filter.py:4:49: F401 `argus.incident.models.Tag` imported but unused
from argus.incident.constants import Level
from argus.htmx.widgets import BadgeDropdownMultiSelect

Expand All @@ -26,6 +26,16 @@ class IncidentFilterForm(forms.Form):
required=False,
label="Sources",
)
tags = forms.CharField(
widget=forms.TextInput(
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",
}
),
required=False,
label="Tags",
)
maxlevel = forms.IntegerField(
widget=forms.NumberInput(
attrs={"type": "range", "step": "1", "min": min(Level).value, "max": max(Level).value}
Expand Down Expand Up @@ -63,6 +73,10 @@ def to_filterblob(self):
if source:
filterblob["sourceSystemIds"] = source

tags = self.cleaned_data.get("tags", [])
if tags:
filterblob["tags"] = tags.split(", ")

maxlevel = self.cleaned_data.get("maxlevel", 0)
if maxlevel:
filterblob["maxlevel"] = maxlevel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% for field in filter_form %}
{% if not field.field.in_header %}
<li class="form-control">
{% if field.name == "source" %}
{% if field.name == "source" or field.name == "tags" %}
<div class="flex flex-nowrap">
<label class="label">
<span class="label-text">{{ field.label }}</span>
Expand Down

0 comments on commit a305a25

Please sign in to comment.