Dynamic Tab Visibility Control in the ViewTabs Class #10212

Closed
opened 2025-12-29 21:28:26 +01:00 by adam · 1 comment
Owner

Originally created by @juninhoojl on GitHub (Sep 9, 2024).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v4.1.0

Feature type

New functionality

Proposed functionality

Edit: Waiting for issue approval and assignment before creating a PR. The feature is already implemented.

The new visibility feature in ViewTabs class allows developers to control whether a tab is displayed based on the attributes of the object being viewed. This functionality is implemented using a callable (e.g., a function or a lambda) that accepts the object as an argument and returns a boolean indicating whether the tab should be visible.

By introducing dynamic visibility, users can fine-tune the display of tabs for specific object states, providing a more personalized and contextual navigation experience within views. If no callable is provided, the tab remains visible by default, preserving backward compatibility.

Use case

Conditional Display Based on Device Role

For example, if you only want to display a tab for devices with the role "Bare Metal", you can pass a lambda function to the visible argument that checks the device_role attribute of the object. Here's how you can define it:

visible=lambda obj: str(obj.device_role) == "Bare Metal"

In this case, the tab will only appear when the device’s role is exactly "Bare Metal". For all other roles, the tab will be hidden. This is particularly useful for scenarios where certain tabs are only relevant for specific types of devices or objects.

Database changes

No changes.

External dependencies

No external dependencies.

Originally created by @juninhoojl on GitHub (Sep 9, 2024). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v4.1.0 ### Feature type New functionality ### Proposed functionality ✨ Edit: Waiting for issue approval and assignment before creating a PR. The feature is already implemented. The new visibility feature in ViewTabs class allows developers to control whether a tab is displayed based on the attributes of the object being viewed. This functionality is implemented using a callable (e.g., a function or a lambda) that accepts the object as an argument and returns a boolean indicating whether the tab should be visible. By introducing dynamic visibility, users can fine-tune the display of tabs for specific object states, providing a more personalized and contextual navigation experience within views. If no callable is provided, the tab remains visible by default, preserving backward compatibility. ### Use case **Conditional Display Based on Device Role** For example, if you only want to display a tab for devices with the role "Bare Metal", you can pass a lambda function to the `visible` argument that checks the `device_role` attribute of the object. Here's how you can define it: ```python visible=lambda obj: str(obj.device_role) == "Bare Metal" ``` In this case, the tab will only appear when the device’s role is exactly "Bare Metal". For all other roles, the tab will be hidden. This is particularly useful for scenarios where certain tabs are only relevant for specific types of devices or objects. ### Database changes No changes. ### External dependencies No external dependencies.
adam added the status: acceptedtype: featurenetboxcomplexity: low labels 2025-12-29 21:28:26 +01:00
adam closed this issue 2025-12-29 21:28:26 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 10, 2025):

I think this makes sense provided it can be implemented in a way that does not break existing behavior. However, it will need to be tagged for a minor release as it will introduce a change in the plugins API (for ViewTab).

@jeremystretch commented on GitHub (Jan 10, 2025): I think this makes sense provided it can be implemented in a way that does not break existing behavior. However, it will need to be tagged for a minor release as it will introduce a change in the plugins API (for ViewTab).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10212