Skip to content
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

Closes: #9583 - Add column specific search field to tables #15073

Open
wants to merge 28 commits into
base: feature
Choose a base branch
from

Conversation

DanSheps
Copy link
Member

@DanSheps DanSheps commented Feb 7, 2024

Closes: #9583 - Add column specific search field to tables

The plan is to use the existing filterset to generate form fields on the table column headers to allow for inline-filtering using HTMX requests

Progress

  • Fields are generated for type fields HTMX requests are sent and account for both fields
  • Integrate with "quick search"
  • Works with custom fields
  • Allow dropdown to float outside of the parent div

Todo

  • Add input fields for "name" Not needed - Quick search is suitable for this
  • Fix filter float (Move before field name perhaps) Done
  • Add show/hide filter (Optional) Outside of scope

@DanSheps DanSheps changed the base branch from develop to feature February 7, 2024 19:41
Copy link
Member Author

@DanSheps DanSheps left a 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 mostly there

netbox/netbox/views/generic/bulk_views.py Outdated Show resolved Hide resolved
@@ -5,7 +5,7 @@
<div class="col-auto d-print-none">
<div class="input-group input-group-flat me-2 quicksearch">
<input type="search" results="5" name="q" id="quicksearch" class="form-control px-2 py-1" placeholder="Quick search"
hx-get="{{ request.full_path }}" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
hx-get="" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
Copy link
Member Author

@DanSheps DanSheps Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed full path, as this will allow taking into account filters on the form (to facilitate pushing of the filters from the column as well).

Should not impact functionality

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not impact functionality

Do we know this for sure? IIRC we specify the full path for a reason, I just can't recall why.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my testing, I haven't found any issues with it.

netbox/utilities/templatetags/form_helpers.py Show resolved Hide resolved
@jeremystretch jeremystretch added this to the v4.0 milestone Feb 8, 2024
@DanSheps DanSheps marked this pull request as ready for review February 12, 2024 22:09
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a lot of errors when trying to load the filter fields.

screenshot

This is likely due to having multiple form fields with the same ID (one on the table and one on the "filters" tab).

netbox/utilities/templatetags/form_helpers.py Outdated Show resolved Hide resolved
netbox/utilities/templatetags/form_helpers.py Outdated Show resolved Hide resolved
netbox/utilities/templatetags/form_helpers.py Outdated Show resolved Hide resolved
netbox/templates/inc/table_htmx.html Outdated Show resolved Hide resolved
netbox/templates/inc/table_htmx.html Outdated Show resolved Hide resolved
netbox/templates/inc/table_header_filter_dropdown.html Outdated Show resolved Hide resolved
@@ -5,7 +5,7 @@
<div class="col-auto d-print-none">
<div class="input-group input-group-flat me-2 quicksearch">
<input type="search" results="5" name="q" id="quicksearch" class="form-control px-2 py-1" placeholder="Quick search"
hx-get="{{ request.full_path }}" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
hx-get="" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not impact functionality

Do we know this for sure? IIRC we specify the full path for a reason, I just can't recall why.

netbox/templates/inc/table_header_filter_dropdown.html Outdated Show resolved Hide resolved
netbox/templates/inc/table_htmx.html Outdated Show resolved Hide resolved
netbox/utilities/templatetags/form_helpers.py Outdated Show resolved Hide resolved
Comment on lines 161 to 167
field.field.widget.attrs.update({
'id': f'table_filter_id_{field.name}',
'hx-get': url if url else '#',
'hx-push-url': "true",
'hx-target': '#object_list',
'hx-trigger': 'hidden.bs.dropdown from:closest .dropdown'
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this approach is tenable: We're using the same form field for both the column and the regular filter form (behind the second tab). Setting HTMX attributes on a non-HTMX form field should be avoided, and overriding its ID may cause problems. IMO we should try to identify a cleaner approach.

Copy link
Member Author

@DanSheps DanSheps Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have went ahead and made a possible modification to this.

In bulk views, I initialize two copies of the form:

  1. A copy of the form for the filtering tab
  2. A copy of the form for the table column filtering

Since this render_table_filter_field tag is only used by the table coumn filtering logic, this shouldn't be a problem anymore.

Let me know if this approach is a more "safer" one while allowing for some code re-use. I can go a little deeper and perhaps modify all filtersets to add a "column filter" tuple to allow a more clean approach to limiting the columns as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this should work fine, but do we need a full form instance for the columns? It might suffice to make a copy of the relevant fields from the filter form and attach them to their respective columns.

Though with either approach, I feel like we're missing a step. The current implementation depends on the column name and the field name matching (form_field=table.filterset_form|get_filter_field:column.name). This should work ~95% of the time but inevitably we're going to find exceptions. I'd like to see if we can devise a more robust approach, short of duplicating the field definitions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this should work fine, but do we need a full form instance for the columns? It might suffice to make a copy of the relevant fields from the filter form and attach them to their respective columns.

Instead of initializing the form right away, we could copy the form definition and then remove fields that not present on the table before intitialization. This feels like excess code for very little gain however

Though with either approach, I feel like we're missing a step. The current implementation depends on the column name and the field name matching (form_field=table.filterset_form|get_filter_field:column.name). This should work ~95% of the time but inevitably we're going to find exceptions. I'd like to see if we can devise a more robust approach, short of duplicating the field definitions.

I think we should handle this on a case-by-case. The only other option would be looking at the table and building a completely new form class dynamically based on the table field types, however we then would likely lose all the custom filtering unless we tie it with the existing filter form somehow.

@jeremystretch
Copy link
Member

Another concern: There's no way to quickly discern when a column filter has been applied.

@arthanson
Copy link
Collaborator

Suggestion - could we make the funnel icon smaller (use a smaller font-size for it) I think it would be just as visible and would reduce the header height to what it was before.

@DanSheps
Copy link
Member Author

It does have the filtering chits if you refresh the page, it just doesn't show them when you select the filters - it should be changed to show the filtering chits when you select the filters.

This is outside of the htmx container, so it doesn't get refreshed, I am not sure if there is an easy way to do this. Perhaps extracting the filtering chits in the same request, but any suggestions are appreciated.

There is a minor UI issue:

  1. Click one of the filters so it drops-down.
  2. Click on another of the filters so it drops-down.

Both filters get un-selected (not dropped down). It opens up the drop-down for the second filter, then closes the drop-down for the first filter, then closes the drop-down fro the second filter.

This is just the way the dropdown works. When the dropdown closes, it reloads the htmx container, which includes all of these fields.

Also: Suggestion (not sure if this is just the way the components work) when you drop-down a filter it shows the small selection box which you then have to click to see the list. IMHO it would be nicer if when you first drop-down the filter it would show the list as well.

I have fixed this. Removing btn did the trick

Another minor UI issue - if you select multiple items it will get clipped in the window - the multi-select on edit pages (like tags) handles this by going to multi-line which should work here as well.

Should be fixed via a max-width CSS attribute on the dropdown menu.

Suggestion - could we make the funnel icon smaller (use a smaller font-size for it) I think it would be just as visible and would reduce the header height to what it was before.

Done

@DanSheps DanSheps requested a review from arthanson April 15, 2024 13:20
@DanSheps DanSheps self-assigned this Apr 15, 2024
@DanSheps
Copy link
Member Author

Another concern: There's no way to quickly discern when a column filter has been applied.

Should pop the badges now

@jeremystretch jeremystretch added the beta Concerns a bug/feature in a beta release label Apr 17, 2024
@jeremystretch jeremystretch removed this from the v4.0 milestone Apr 17, 2024
@arthanson
Copy link
Collaborator

Still some weirdness - If I select a filter then I do a page refresh I get doubling up of the chits (see below) I tried it on feature branch and this doesn't happen.

Monosnap Devices | NetBox 2024-04-18 09-13-33

@arthanson
Copy link
Collaborator

arthanson commented Apr 18, 2024

If I select a filter (works correctly) then click on another filter again (as I want to change what it is filtering on) I get a blank drop-down so I can't actually select anything else. Sort of weird, possibly a timing thing as if I click around to other filters after a couple seconds they start rendering correctly

Monosnap Devices | NetBox 2024-04-18 09-16-13

@arthanson
Copy link
Collaborator

arthanson commented Apr 18, 2024

If you do select a filter (I did site -> Butler Communication) then click the checkbox next to Name (for select all in list) it doesn't select anything in the list. I also tried on feature and it works correctly.

Monosnap Devices | NetBox 2024-04-18 09-33-00

Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments - several UI issues still

@DanSheps
Copy link
Member Author

Will take a peek when I can.

@DanSheps
Copy link
Member Author

DanSheps commented Apr 23, 2024

If I select a filter (works correctly) then click on another filter again (as I want to change what it is filtering on) I get a blank drop-down so I can't actually select anything else. Sort of weird, possibly a timing thing as if I click around to other filters after a couple seconds they start rendering correctly

I think this is simply a timing thing as the HTMX re-renders the whole table, including headers.

Not sure if there is a way around this, an "easy" way would be to return the whole table but only swap the tbody on operations surrounding the column filters/search. I think the only way to handle this would be to break up the HTMX request into multiple more components with some OOB swaps, however that doesn't seem to work as intended.

@DanSheps
Copy link
Member Author

If you do select a filter (I did site -> Butler Communication) then click the checkbox next to Name (for select all in list) it doesn't select anything in the list. I also tried on feature and it works correctly.

I can't recreate this. I am able to select the full list as intended. We might need some additional testing on this one.

@DanSheps
Copy link
Member Author

Still some weirdness - If I select a filter then I do a page refresh I get doubling up of the chits (see below) I tried it on feature branch and this doesn't happen.

This one should be fixed. See comments for other two. Open to suggestions on those.

@DanSheps DanSheps requested a review from arthanson April 23, 2024 03:45
@arthanson
Copy link
Collaborator

This is looking really good Dan, I just see one minor issue - if you select a filter, then click the select all (next to name) it will show the "Select all xx devices matching query" the count is all the items in the table, not the filtered count. If you go through the filters tab and do the filter that way, then click the select all it will not show the "Select all xx..." message.

Monosnap Devices | NetBox 2024-04-23 08-42-03

@DanSheps
Copy link
Member Author

This is looking really good Dan, I just see one minor issue - if you select a filter, then click the select all (next to name) it will show the "Select all xx devices matching query" the count is all the items in the table, not the filtered count. If you go through the filters tab and do the filter that way, then click the select all it will not show the "Select all xx..." message.

Just checked, this bug is present in both feature and develop (it is a long standing bug I believe, just maybe no issue for it).

I think it would be pretty easy to fix but we should track it as a separate bug IMO.

@arthanson
Copy link
Collaborator

@DanSheps I'm not seeing the behavior with the select-all on feature (see screenshot), I'm only seeing it on your branch. I just go to filter tab, select a filter and then do the select-all button. If I do select-all after doing the filtering by the drop-downs, that is where I see it. What are the steps you are using when seeing it on feature?

Monosnap Sites | NetBox 2024-04-25 08-34-09

@DanSheps
Copy link
Member Author

Do a quick search, not a filter. The quick search does an HTMX request on the table only.

The issue is the edit div doesn't get updated because it is outside the scope of the htmx request.

We need to do an OOB swap for that as well.

@arthanson
Copy link
Collaborator

@DanSheps can you open a separate bug for the select-all issue?

@jeremystretch jeremystretch removed the beta Concerns a bug/feature in a beta release label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add column-specific search fields to tables
3 participants