-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
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.