netbox
netbox copied to clipboard
Saved Filters
NetBox version
3.2.5
Feature type
New functionality
Proposed functionality
After building a filter it would be useful to be able to save it for future re-use, give it a name and the option to make it public. Public filters would then be viewable by all logged in to Netbox.
Proposing a 3rd tab alongside Results | Filters - perhaps 'Saved Filters'. Or possibly a section within the existing Filters tab to show any saved filters.
UI Suggestion for model list view
Filters would not need to be modifiable, once saved, the user that created the filter can delete it from the saved filters list. When a user is removed from the system, the filters they created should also be removed.
Use case
I often find myself having to build the same filter repeatedly in Netbox as well as having to remember to share links with the team when I build a useful filter. Having the option to save a filter in Netbox and share it with my users would save time.
Database changes
A new model would need to be created to store the saved filters. Model would require a relation to the object type e.g. dcim.devices, filter attributes, friendly name, is public and a relation to the user that created it (to allow that user to delete it).
External dependencies
No response
@jasonyates it sounds like a neat idea, but could you spend some more time fleshing out the proposal please? You haven't noted anything under database changes, and I'd assume this would require at least a new model.
@jeremystretch Done. I included a proposed mockup of a piece of the UI too.
Expanding on the proposed model a bit, we probably need:
- Name
- User (nullable FK)
- Description (optional)
- Object type(s?)
- Query parameters (JSON data)
- Shared (boolean)
If shared is true, the filter will be made available for other users; otherwise, only the owner will see it listed as an available option when filtering an object list. However, it should still appear as visible in the saved filters list.
I've proposed making the user field nullable, so that the saved filter remains intact if the owning user is deleted.
We still need to determine how a saved filter would be applied in practice. I see two options:
- Reference the saved filter directly when making a query, e.g.
GET /dcim/sites/?filter=my_saved_filter - Use the filter to generate a query URL in the UI, so that when the user clicks "My saved filter," a request is made for e.g.
GET /dcim/sites/?status=planned&tenant=blah
There are some caveats to both approaches. Making reference to a filter doesn't reveal the actual query parameters being used, which is likely to lead to confusion. It might also be difficult to parse on the backend. However, the second approach is of very limited utility outside of the UI: It provides no way for an API client to directly employ a saved filter.
A third, hybrid approach might be reasonable: A request for e.g. GET /dcim/sites/?filter=my_saved_filter would return a 302 redirect with the appropriate query parameters attached. This is slightly less efficient but may be a reasonable compromise.
I like this idea. I also think we should leverage NetBox User preference framework to potentially store a "default" filter, per object type, per user.
I like the "redirect" idea as it would mean it would be easy for a user to edit the fields after they've selected the filter.
for example maybe theres a filter "find x cust devices with custom attrib" where its searching for devices where a tenant is set to x customer and some other logic.
User selects that filter, gets redirected, then changes the tenant in the filter to the one that suits them.
permissions: Also i can already envision a new extra permission to allow users to edit any shared filter, would be useful to allow the "powerusers" to edit shared filters without giving them superadmin (assuming superadmins would be able to edit shared filters)
api: Maybe a new endpoint where you can list / lookup filters and get the query params? once you have the params / search uri you can just call it.
Still in the early stages, but came up with this pretty quick. After some experimentation, I'm leaning away from the redirect idea, primarily because there's no clean way to convey to the user which saved filter they have applied. The groundwork is all in place now though; happy to discuss up to and during the beta period.

That looks awesome!Can the filter be selected via URL params?I know most of my users use bookmarks, so it would be beneficial if I could send them a URL pointing to a filter.On 27 Oct 2022, at 22:44, Jeremy Stretch @.***> wrote: Still in the early stages, but came up with this pretty quick. After some experimentation, I'm leaning away from the redirect idea, primarily because there's no clean way to convey to the user which saved filter they have applied. The groundwork is all in place now though; happy to discuss up to and during the beta period.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
@hagbarddenstore Yes, you link to e.g. /dcim/devices/?filter=my-custom-filter to apply the saved filter.
Perfect!Awesome work!On 28 Oct 2022, at 20:13, Jeremy Stretch @.***> wrote: @hagbarddenstore Yes, you link to e.g. /dcim/devices/?filter=my-custom-filter to apply the saved filter.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>