Skip to content

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

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

Closed

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

@@ -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.

@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).

@@ -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.

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.

@DanSheps
Copy link
Member Author

Interesting note:

yarn:bundle on windows outputs CSS with RGB color values
yarn:bundle on linux outputs CSS with HEX color values

@DanSheps DanSheps requested review from arthanson and bctiemann and removed request for arthanson and jeremystretch February 13, 2025 16:52
@DanSheps
Copy link
Member Author

@arthanson @bctiemann I just updated the bundle. Could you two give this a look?

@arthanson
Copy link
Collaborator

@DanSheps build is failing?

@DanSheps
Copy link
Member Author

Thanks @arthanson, wil let you know when it passes.

@DanSheps
Copy link
Member Author

I think I only update the styles, this is my bad. Pushing the latest bundle now.

@DanSheps DanSheps force-pushed the 9583-add_column_specific_search_field_to_tables branch from 02ddf4d to 01cb7be Compare February 19, 2025 20:55
@DanSheps
Copy link
Member Author

@arthanson good to go it looks like

@arthanson
Copy link
Collaborator

arthanson commented Feb 25, 2025

Just a note - not sure if this is a bootstrap type behavior but if you click a filter dropdown (leave it open) then click another filter dropdown - it closes the first one, opens the new one, then closes the new one. If you close the first one and then select the new one it works okay, but if you don't close the first one it will auto-close the second one after a brief delay.

Actually while testing I was finding this pretty annoying - even if I close a previous filter dropdown then quickly select another it will auto close it. There seems to be some type of delayed close signal or something.

@arthanson
Copy link
Collaborator

Sites -> Locations table there is a dropdown for "FACILITY" that drops down for a text entry box, but it doesn't seem to search correctly. I added faculty "aaa" to one and "bbb" to another location then in the dropdown searched for "bbb" and it errors "No Locations were selected".

@arthanson
Copy link
Collaborator

arthanson commented Feb 25, 2025

Contact Assignments "OBJECT TYPE" filter, because of the long name it causes UI issues - if it was a bit longer the x at the end of object would not be selectable, it doesn't scroll either (meaning you can't scroll sideways to get to the x from what I've tried). Not sure how fixable this is and can remove the filter in the chit, but would be good to fix if possible.
filter1

@arthanson
Copy link
Collaborator

Height is the same as facility above - it allows me to select a number but when I do an press return it say "No racks were selected" even if there are Racks with that height.
filter2

@arthanson
Copy link
Collaborator

arthanson commented Feb 25, 2025

Is this by design or a bug? If I do filters by the filter drop-down then I get the filter chit but the "Filters" tab doesn't show any filter applied, and if I go to the filters tab it doesn't show any filters. This is different behavior then if I select the filter via the filter tab. It seems a bit confusing that I have the filter chit but the filters are working two different ways. Say I use the filter dropdown to filter something then I want to filter something more complex and go to the filter tab, but now I don't have that filter. Seems like they should work inter-changeably?

Actually, think bug - if you apply filters from two different columns, then remove one by clicking the chit the Filters tab then shows the correct info.
filter3

@arthanson
Copy link
Collaborator

Device Types - "PART NUMBER" also doesn't work:
filter 5

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.

Still seems like (minor) UI issues, I didn't test every table dropdown as several issues (like certain entry fields aren't filtering correctly) seem to be a general issue. It's a nice feature, but I'm a bit worried that it could be a support issue (minor UX nits popping up)

I haven't done a thorough code review again as these UX issues will cause code changes.

@DanSheps
Copy link
Member Author

Still seems like (minor) UI issues, I didn't test every table dropdown as several issues (like certain entry fields aren't filtering correctly) seem to be a general issue. It's a nice feature, but I'm a bit worried that it could be a support issue (minor UX nits popping up)

I haven't done a thorough code review again as these UX issues will cause code changes.

I will have to check but if there isn't a corresponding filter it shouldn't allow filtering. This seems like it is allowing filtering even if the filter itself doesn't exist. I will double check though and see what I can find.

@arthanson
Copy link
Collaborator

Great work, however as per discussion, closing this one for now as it needs another round of refactoring and fixing some UI issues. @DanSheps can you re open it after changes are complete. The major areas to look at are:

  • Look into an alternative solution that doesn't require column names to match the filter names per Jeremy's earlier comment "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."
  • Investigate / fix the issue "allowing filtering even if the filter itself doesn't exist" found in the UI testing. (Sites -> Locations table dropdown for "FACILITY" )
  • Filters tab getting updated when filter Is selected

I think a final UI run-through of every table / dropdown needs to be done to double-check the functionality.

@arthanson arthanson closed this Feb 28, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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