mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-17 01:38:19 +00:00
[UI] Plugin actions (#10720)
* Add backend code for custom actions * docs * Add sample action code * Fetch plugin features * Load plugins and call function * Support icons * Alert message * Update CHANGELOG.md * Rename action type * Update docs * pdated playwright tests
This commit is contained in:
@@ -15,6 +15,7 @@ logger = structlog.get_logger('inventree')
|
||||
|
||||
# List of supported feature types
|
||||
FeatureType = Literal[
|
||||
'spotlight_action', # Custom actions for the spotlight search
|
||||
'dashboard', # Custom dashboard items
|
||||
'panel', # Custom panels
|
||||
'template_editor', # Custom template editor
|
||||
@@ -99,11 +100,12 @@ class UserInterfaceMixin:
|
||||
|
||||
"""
|
||||
feature_map = {
|
||||
'spotlight_action': self.get_ui_spotlight_actions,
|
||||
'dashboard': self.get_ui_dashboard_items,
|
||||
'navigation': self.get_ui_navigation_items,
|
||||
'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:
|
||||
@@ -112,6 +114,21 @@ class UserInterfaceMixin:
|
||||
logger.warning(f'Invalid feature type: {feature_type}')
|
||||
return []
|
||||
|
||||
def get_ui_spotlight_actions(
|
||||
self, request: Request, context: dict, **kwargs
|
||||
) -> list[UIFeature]:
|
||||
"""Return a list of custom actions to be injected into the UI spotlight.
|
||||
|
||||
Args:
|
||||
request: HTTPRequest object (including user information)
|
||||
context: Additional context data provided by the UI (query parameters)
|
||||
|
||||
Returns:
|
||||
list: A list of custom actions to be injected into the UI spotlight.
|
||||
"""
|
||||
# Default implementation returns an empty list
|
||||
return []
|
||||
|
||||
def get_ui_panels(
|
||||
self, request: Request, context: dict, **kwargs
|
||||
) -> list[UIFeature]:
|
||||
|
||||
@@ -49,6 +49,20 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug
|
||||
},
|
||||
}
|
||||
|
||||
def get_ui_spotlight_actions(self, request, context, **kwargs):
|
||||
"""Return a list of custom actions to be injected into the UI spotlight."""
|
||||
return [
|
||||
{
|
||||
'key': 'sample-action',
|
||||
'title': 'Sample Action',
|
||||
'description': 'This is a sample action for the spotlight search',
|
||||
'icon': 'ti:search:outline',
|
||||
'source': self.plugin_static_file(
|
||||
'sample_action.js:performSampleAction'
|
||||
),
|
||||
}
|
||||
]
|
||||
|
||||
def get_ui_panels(self, request, context, **kwargs):
|
||||
"""Return a list of custom panels to be injected into the UI."""
|
||||
panels = []
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* A sample action plugin for InvenTree.
|
||||
*
|
||||
* This is a very basic example of how to define a custom action.
|
||||
* In practice, you would want to implement more complex logic here.
|
||||
*/
|
||||
|
||||
export function performSampleAction(data) {
|
||||
// Simply log the data to the console
|
||||
alert("Sample! Refer to the console");
|
||||
console.log("Sample action performed with data:", data);
|
||||
}
|
||||
Reference in New Issue
Block a user