mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-18 16:41:32 +00:00
UI panels fix (#10341)
* Tweak sample plugin * Re-fetch panels when instance changes * Unit test fix
This commit is contained in:
@@ -111,7 +111,7 @@ class UserInterfaceMixinTests(InvenTreeAPITestCase):
|
|||||||
# Request custom panel information for a part instance
|
# Request custom panel information for a part instance
|
||||||
response = self.get(url, data=query_data)
|
response = self.get(url, data=query_data)
|
||||||
|
|
||||||
# There should be 4 active panels for the part by default
|
# There should be 3 active panels for the part by default
|
||||||
self.assertEqual(3, len(response.data))
|
self.assertEqual(3, len(response.data))
|
||||||
|
|
||||||
_part.active = False
|
_part.active = False
|
||||||
@@ -119,8 +119,8 @@ class UserInterfaceMixinTests(InvenTreeAPITestCase):
|
|||||||
|
|
||||||
response = self.get(url, data=query_data)
|
response = self.get(url, data=query_data)
|
||||||
|
|
||||||
# As the part is not active, only 3 panels left
|
# As the part is not active, only 2 panels left
|
||||||
self.assertEqual(3, len(response.data))
|
self.assertEqual(2, len(response.data))
|
||||||
|
|
||||||
# Disable the "ENABLE_PART_PANELS" setting, and try again
|
# Disable the "ENABLE_PART_PANELS" setting, and try again
|
||||||
plugin.set_setting('ENABLE_PART_PANELS', False)
|
plugin.set_setting('ENABLE_PART_PANELS', False)
|
||||||
|
@@ -93,11 +93,15 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug
|
|||||||
except (Part.DoesNotExist, ValueError):
|
except (Part.DoesNotExist, ValueError):
|
||||||
part = None
|
part = None
|
||||||
|
|
||||||
|
# Only display this panel for "active" parts
|
||||||
|
if part and part.active:
|
||||||
panels.append({
|
panels.append({
|
||||||
'key': 'part-panel',
|
'key': 'part-panel',
|
||||||
'title': _('Part Panel'),
|
'title': _('Part Panel'),
|
||||||
'source': self.plugin_static_file('sample_panel.js:renderPartPanel'),
|
'source': self.plugin_static_file(
|
||||||
'icon': 'ti:package_outline',
|
'sample_panel.js:renderPartPanel'
|
||||||
|
),
|
||||||
|
'icon': 'ti:package:outline',
|
||||||
'context': {'part_name': part.name if part else ''},
|
'context': {'part_name': part.name if part else ''},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -52,7 +52,7 @@ export function usePluginPanels({
|
|||||||
// API query to fetch initial information on available plugin panels
|
// API query to fetch initial information on available plugin panels
|
||||||
const pluginQuery = useQuery({
|
const pluginQuery = useQuery({
|
||||||
enabled: pluginPanelsEnabled && !!model && id !== undefined,
|
enabled: pluginPanelsEnabled && !!model && id !== undefined,
|
||||||
queryKey: ['custom-plugin-panels', model, id],
|
queryKey: ['custom-plugin-panels', model, id, instance],
|
||||||
throwOnError: (error: any) => {
|
throwOnError: (error: any) => {
|
||||||
console.error('ERR: Failed to fetch plugin panels');
|
console.error('ERR: Failed to fetch plugin panels');
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user