-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to create and select incident filters #1122
base: master
Are you sure you want to change the base?
Conversation
No functionality
Both filter params and the incidents table are updated accordingly to a selected filter
In order to match expected FilterKey
Test results 10 files 1 060 suites 38m 8s ⏱️ Results for commit c9c7b36. ♻️ This comment has been updated with latest results. |
We could also make open/closed and acked/unacked take up less space. |
68dd3e8
to
beba7b2
Compare
src/argus/htmx/incident/views.py
Outdated
filter_pk, filter_obj = request.session.get("selected_filter", None), None | ||
if filter_pk: | ||
filter_obj = get_object_or_404(Filter, pk=filter_pk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest placing this inside incident_list_filter
instead of in the view. This keeps both the view and the filter-plugin interface clean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear. The session stuff or raising the 404 or both?
I'm not too fond of raising 404 directly in incident_list_filter
.
src/argus/htmx/incident/views.py
Outdated
def create_filter(request: HtmxHttpRequest): | ||
filter_name = request.POST.get("filter_name", None) | ||
incident_list_filter = get_filter_function() | ||
filter_form, _ = incident_list_filter(request, None) | ||
if filter_name and filter_form.is_valid(): | ||
filterblob = filter_form.to_filterblob() | ||
_, filter_obj = create_named_filter(request, filter_name, filterblob) | ||
if filter_obj: | ||
request.session["selected_filter"] = str(filter_obj.id) | ||
return HttpResponseClientRefresh() | ||
messages.error(request, "Failed to create filter") | ||
return HttpResponseBadRequest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a nice candidate for extending the filter plugin system (which is currently only get_filter_function
). If we can override filter validation and creation of Filter
s, we can also make use of this endpoint (and others concerning filters). Don't think it'll have to be this pr though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope now, yes, let's make it work first. Also we should have update and delete filter working first I suspect!
14e7ed6
to
91a5b79
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1122 +/- ##
==========================================
- Coverage 79.71% 79.05% -0.67%
==========================================
Files 141 141
Lines 5285 5356 +71
==========================================
+ Hits 4213 4234 +21
- Misses 1072 1122 +50 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good! Now it is only nitpicking and polish suggestion for new issues from my side
I think it would be good to add comments to the parts that override request.session["selected_filter"] to explain why that is happening (to persist the choices)
@@ -93,6 +93,7 @@ def incident_update(request: HtmxHttpRequest, action: str): | |||
|
|||
@require_GET | |||
def filter_form(request: HtmxHttpRequest): | |||
request.session["selected_filter"] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you setting the selected_filter
here to None
? It probably has a good reason, I just don't understand it fully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually the name (and purpose) of filter_form
that adds to confusion here. It is only used to return form after user manually updates the value of sources-selector. The reason why we set the selected_filter
to None
here is because we need to reset the selected filter on any manual filter params update (by user).
Quality Gate passedIssues Measures |
Closes #1045