2
0
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:
Oliver
2025-09-18 13:19:47 +10:00
committed by GitHub
parent 21cb488eef
commit df0e27bed2
3 changed files with 15 additions and 11 deletions

View File

@@ -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)

View File

@@ -93,13 +93,17 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug
except (Part.DoesNotExist, ValueError): except (Part.DoesNotExist, ValueError):
part = None part = None
panels.append({ # Only display this panel for "active" parts
'key': 'part-panel', if part and part.active:
'title': _('Part Panel'), panels.append({
'source': self.plugin_static_file('sample_panel.js:renderPartPanel'), 'key': 'part-panel',
'icon': 'ti:package_outline', 'title': _('Part Panel'),
'context': {'part_name': part.name if part else ''}, 'source': self.plugin_static_file(
}) 'sample_panel.js:renderPartPanel'
),
'icon': 'ti:package:outline',
'context': {'part_name': part.name if part else ''},
})
# Next, add a custom panel which will appear on the 'purchaseorder' page # Next, add a custom panel which will appear on the 'purchaseorder' page
if target_model == 'purchaseorder' and self.get_setting( if target_model == 'purchaseorder' and self.get_setting(

View File

@@ -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;