mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Example of plugin panel selection based on page
This commit is contained in:
parent
299839312f
commit
e03dafbdd6
@ -427,29 +427,47 @@ class PluginPanelList(APIView):
|
|||||||
# TODO: Allow plugins to fill this data out
|
# TODO: Allow plugins to fill this data out
|
||||||
...
|
...
|
||||||
|
|
||||||
panels = [
|
user = request.user
|
||||||
{
|
target_model = request.query_params.get('target_model', None)
|
||||||
'plugin': 'myplugin',
|
target_id = request.query_params.get('target_id', None)
|
||||||
'name': 'test-plugin',
|
|
||||||
'label': 'My Plugin',
|
if target_model == 'part' and target_id:
|
||||||
'icon': 'part',
|
panels = [
|
||||||
'content': '<div>hello world</div>',
|
*panels,
|
||||||
},
|
{
|
||||||
{
|
'plugin': 'myplugin',
|
||||||
'plugin': 'myplugin',
|
'name': 'test-plugin',
|
||||||
'name': 'test-plugin-2',
|
'label': 'My Plugin',
|
||||||
'label': 'My Plugin 2',
|
'icon': 'part',
|
||||||
'icon': 'email',
|
'content': '<div>hello world</div>',
|
||||||
'content': '<div>hello world 2</div>',
|
},
|
||||||
},
|
{
|
||||||
{
|
'plugin': 'myplugin',
|
||||||
'plugin': 'myplugin',
|
'name': 'test-plugin-2',
|
||||||
'name': 'test-plugin-3',
|
'label': 'My Plugin 2',
|
||||||
'label': 'My Plugin 3',
|
'icon': 'email',
|
||||||
'icon': 'website',
|
'content': '<div>hello world 2</div>',
|
||||||
'content': '<div>hello world 3</div>',
|
},
|
||||||
},
|
{
|
||||||
]
|
'plugin': 'myplugin',
|
||||||
|
'name': 'test-plugin-3',
|
||||||
|
'label': 'My Plugin 3',
|
||||||
|
'icon': 'website',
|
||||||
|
'content': '<div>hello world 3</div>',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
if target_model == 'partcategory':
|
||||||
|
panels = [
|
||||||
|
*panels,
|
||||||
|
{
|
||||||
|
'plugin': 'cat',
|
||||||
|
'name': 'demo-cat',
|
||||||
|
'label': 'Custom Category',
|
||||||
|
'icon': 'customer',
|
||||||
|
'content': 'This should only appear for a category',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)
|
return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ import {
|
|||||||
} from '../../components/items/ActionDropdown';
|
} from '../../components/items/ActionDropdown';
|
||||||
import NavigationTree from '../../components/nav/NavigationTree';
|
import NavigationTree from '../../components/nav/NavigationTree';
|
||||||
import { PageDetail } from '../../components/nav/PageDetail';
|
import { PageDetail } from '../../components/nav/PageDetail';
|
||||||
import { PanelGroup, PanelType } from '../../components/nav/PanelGroup';
|
import { PanelType } from '../../components/nav/Panel';
|
||||||
|
import { PanelGroup } from '../../components/nav/PanelGroup';
|
||||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||||
import { ModelType } from '../../enums/ModelType';
|
import { ModelType } from '../../enums/ModelType';
|
||||||
import { UserRoles } from '../../enums/Roles';
|
import { UserRoles } from '../../enums/Roles';
|
||||||
@ -31,6 +32,7 @@ import {
|
|||||||
useEditApiFormModal
|
useEditApiFormModal
|
||||||
} from '../../hooks/UseForm';
|
} from '../../hooks/UseForm';
|
||||||
import { useInstance } from '../../hooks/UseInstance';
|
import { useInstance } from '../../hooks/UseInstance';
|
||||||
|
import { usePluginPanels } from '../../hooks/UsePluginPanels';
|
||||||
import { useUserState } from '../../states/UserState';
|
import { useUserState } from '../../states/UserState';
|
||||||
import ParametricPartTable from '../../tables/part/ParametricPartTable';
|
import ParametricPartTable from '../../tables/part/ParametricPartTable';
|
||||||
import { PartCategoryTable } from '../../tables/part/PartCategoryTable';
|
import { PartCategoryTable } from '../../tables/part/PartCategoryTable';
|
||||||
@ -260,6 +262,15 @@ export default function CategoryDetail({}: {}) {
|
|||||||
[category, id]
|
[category, id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const pluginPanels = usePluginPanels({
|
||||||
|
targetModel: ModelType.partcategory,
|
||||||
|
targetId: id
|
||||||
|
});
|
||||||
|
|
||||||
|
const panels: PanelType[] = useMemo(() => {
|
||||||
|
return [...categoryPanels, ...pluginPanels.panels];
|
||||||
|
}, [categoryPanels, pluginPanels]);
|
||||||
|
|
||||||
const breadcrumbs = useMemo(
|
const breadcrumbs = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{ name: t`Parts`, url: '/part' },
|
{ name: t`Parts`, url: '/part' },
|
||||||
@ -296,7 +307,7 @@ export default function CategoryDetail({}: {}) {
|
|||||||
}}
|
}}
|
||||||
actions={categoryActions}
|
actions={categoryActions}
|
||||||
/>
|
/>
|
||||||
<PanelGroup pageKey="partcategory" panels={categoryPanels} />
|
<PanelGroup pageKey="partcategory" panels={panels} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user