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

Saved Filters #9623

Closed
jasonyates opened this issue Jun 28, 2022 · 9 comments
Closed

Saved Filters #9623

jasonyates opened this issue Jun 28, 2022 · 9 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@jasonyates
Copy link

jasonyates commented Jun 28, 2022

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

Screenshot 2022-06-29 at 10 45 03

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 jasonyates added the type: feature Introduction of new functionality to the application label Jun 28, 2022
@jeremystretch
Copy link
Member

@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 jeremystretch added the status: revisions needed This issue requires additional information to be actionable label Jun 28, 2022
@jasonyates
Copy link
Author

@jeremystretch Done. I included a proposed mockup of a piece of the UI too.

@jeremystretch jeremystretch added status: under review Further discussion is needed to determine this issue's scope and/or implementation and removed status: revisions needed This issue requires additional information to be actionable labels Jun 29, 2022
@jeremystretch
Copy link
Member

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.

@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Jul 27, 2022
@jeremystretch jeremystretch added this to the v3.4 milestone Jul 27, 2022
@jeremystretch jeremystretch self-assigned this Sep 27, 2022
@jsenecal
Copy link
Contributor

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.

@ITJamie
Copy link
Contributor

ITJamie commented Sep 28, 2022

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.

@jeremystretch
Copy link
Member

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.

saved_filters

@hagbarddenstore
Copy link
Contributor

hagbarddenstore commented Oct 28, 2022 via email

@jeremystretch
Copy link
Member

@hagbarddenstore Yes, you link to e.g. /dcim/devices/?filter=my-custom-filter to apply the saved filter.

@hagbarddenstore
Copy link
Contributor

hagbarddenstore commented Oct 29, 2022 via email

jeremystretch added a commit that referenced this issue Nov 2, 2022
* Initial work on saved filters

* Return only enabled/shared filters

* Add tests

* Clean up filtering of usable SavedFilters
DanSheps added a commit that referenced this issue Nov 10, 2022
Co-authored-by: Jeremy Stretch <jstretch@ns1.com>
jeremystretch added a commit that referenced this issue Nov 11, 2022
* Work on #7854

* Move to new URL scheme.

* Fix PEP8 errors

* Fix PEP8 errors

* Add GraphQL and fix primary_ip missing

* Fix PEP8 on GQL Type

* Fix missing NestedSerializer.

* Fix missing NestedSerializer & rename VDC to VDCs

* Fix migration

* Change Validation for identifier

* Fix missing migration

* Rebase to feature

* Post-review changes

* Remove VDC Type
* Remove M2M Enforcement logic

* Interface related changes

* Add filter fields to filterset for Interface filter
* Add form field to filterset form for Interface filter
* Add VDC display to interface detail template

* Remove VirtualDeviceContextTypeChoices

* Accommodate recent changes in feature branch

* Add tests
Add missing search()

* Update tests, and fix model form

* Update test_api

* Update test_api.InterfaceTest create_data

* Fix issue with tests

* Update interface serializer

* Update serializer and tests

* Update status to be required

* Remove error message for constraint

* Remove extraneous import

* Re-ordered devices menu to place VDC below virtual chassis

* Add helptext for `identifier` field

* Fix breadcrumb link

* Remove add interface link

* Add missing tenant and status fields

* Changes to tests as per Jeremy

* Change for #9623

Co-authored-by: Jeremy Stretch <jstretch@ns1.com>

* Update filterset form for status field

* Remove Rename View

* Change tabs to spaces

* Update netbox/dcim/tables/devices.py

Co-authored-by: Jeremy Stretch <jstretch@ns1.com>

* Update netbox/dcim/tables/devices.py

Co-authored-by: Jeremy Stretch <jstretch@ns1.com>

* Fix tenant in bulk_edit

* Apply suggestions from code review

Co-authored-by: Jeremy Stretch <jstretch@ns1.com>

* Add status field to table.

* Re-order table fields.

Co-authored-by: Jeremy Stretch <jstretch@ns1.com>
jeremystretch added a commit that referenced this issue Dec 12, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

5 participants