mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-15 09:21:26 +00:00
feat: New / Refactor "Nav Mixin" (#9283)
* [FR/P-UI] New / Refactor "Nav Mixin" Fixes #5269 * remove logging * fix sample item that causes issues * Add test coverage * Update src/frontend/src/components/plugins/PluginUIFeatureTypes.ts Co-authored-by: Lukas <76838159+wolflu05@users.noreply.github.com> * [FR/P-UI] New / Refactor "Nav Mixin" Fixes #5269 * fix style * remove requirement for source * fix import * bump api version --------- Co-authored-by: Lukas <76838159+wolflu05@users.noreply.github.com>
This commit is contained in:
src
backend
InvenTree
InvenTree
plugin
frontend
src
components
@ -1,13 +1,16 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 338
|
||||
INVENTREE_API_VERSION = 339
|
||||
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v339 -> 2025-04-15 : https://github.com/inventree/InvenTree/pull/9283
|
||||
- Remove need for source in /plugins/ui/features
|
||||
|
||||
v338 -> 2025-04-15 : https://github.com/inventree/InvenTree/pull/9333
|
||||
- Adds oAuth2 support for the API
|
||||
|
||||
|
@ -19,6 +19,7 @@ FeatureType = Literal[
|
||||
'panel', # Custom panels
|
||||
'template_editor', # Custom template editor
|
||||
'template_preview', # Custom template preview
|
||||
'navigation', # Custom navigation items
|
||||
]
|
||||
|
||||
|
||||
@ -102,6 +103,7 @@ class UserInterfaceMixin:
|
||||
'panel': self.get_ui_panels,
|
||||
'template_editor': self.get_ui_template_editors,
|
||||
'template_preview': self.get_ui_template_previews,
|
||||
'navigation': self.get_ui_navigation_items,
|
||||
}
|
||||
|
||||
if feature_type in feature_map:
|
||||
@ -169,3 +171,18 @@ class UserInterfaceMixin:
|
||||
"""
|
||||
# Default implementation returns an empty list
|
||||
return []
|
||||
|
||||
def get_ui_navigation_items(
|
||||
self, request: Request, context: dict, **kwargs
|
||||
) -> list[UIFeature]:
|
||||
"""Return a list of custom navigation items to be injected into the UI.
|
||||
|
||||
Args:
|
||||
request: HTTPRequest object (including user information)
|
||||
context: Additional context data provided by the UI (query parameters)
|
||||
|
||||
Returns:
|
||||
list: A list of custom navigation items to be injected into the UI
|
||||
"""
|
||||
# Default implementation returns an empty list
|
||||
return []
|
||||
|
@ -61,5 +61,5 @@ class PluginUIFeatureSerializer(serializers.Serializer):
|
||||
context = serializers.DictField(label=_('Feature Context'), default=None)
|
||||
|
||||
source = serializers.CharField(
|
||||
label=_('Feature Source (javascript)'), required=True, allow_blank=False
|
||||
label=_('Feature Source (javascript)'), required=False, allow_blank=True
|
||||
)
|
||||
|
@ -223,3 +223,13 @@ class UserInterfaceMixinTests(InvenTreeAPITestCase):
|
||||
|
||||
# Set the setting back to True for subsequent tests
|
||||
InvenTreeSetting.set_setting('ENABLE_PLUGINS_INTERFACE', True, change_user=None)
|
||||
|
||||
def test_ui_navigation_items(self):
|
||||
"""Test that the sample UI plugin provides custom navigation items."""
|
||||
response = self.get(
|
||||
reverse('api-plugin-ui-feature-list', kwargs={'feature': 'navigation'})
|
||||
)
|
||||
self.assertEqual(1, len(response.data))
|
||||
self.assertEqual(response.data[0]['plugin_name'], 'sampleui')
|
||||
self.assertEqual(response.data[0]['key'], 'sample-nav-item')
|
||||
self.assertEqual(response.data[0]['title'], 'Sample Nav Item')
|
||||
|
@ -197,6 +197,17 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug
|
||||
}
|
||||
]
|
||||
|
||||
def get_ui_navigation_items(self, request, context, **kwargs):
|
||||
"""Return a list of custom navigation items."""
|
||||
return [
|
||||
{
|
||||
'key': 'sample-nav-item',
|
||||
'title': 'Sample Nav Item',
|
||||
'icon': 'ti:menu',
|
||||
'options': {'url': '/sample/page/'},
|
||||
}
|
||||
]
|
||||
|
||||
def get_admin_context(self) -> dict:
|
||||
"""Return custom context data which can be rendered in the admin panel."""
|
||||
return {'apple': 'banana', 'foo': 'bar', 'hello': 'world'}
|
||||
|
Reference in New Issue
Block a user