2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

Pass instance data through

This commit is contained in:
Oliver Walters
2024-08-11 23:09:42 +00:00
parent f81614dcbe
commit d25613ac3f
3 changed files with 20 additions and 3 deletions

View File

@ -43,6 +43,7 @@ import { PanelType } from './Panel';
export type PanelProps = { export type PanelProps = {
pageKey: string; pageKey: string;
panels: PanelType[]; panels: PanelType[];
targetInstance?: any;
targetModel?: ModelType | string; targetModel?: ModelType | string;
targetId?: number | null; targetId?: number | null;
selectedPanel?: string; selectedPanel?: string;
@ -55,6 +56,7 @@ function BasePanelGroup({
panels, panels,
onPanelChange, onPanelChange,
selectedPanel, selectedPanel,
targetInstance,
targetModel, targetModel,
targetId, targetId,
collapsible = true collapsible = true

View File

@ -10,6 +10,7 @@ import { PanelType } from '../nav/Panel';
interface PluginPanelProps extends PanelType { interface PluginPanelProps extends PanelType {
src?: string; src?: string;
params?: any; params?: any;
targetInstance?: any;
targetModel?: ModelType | string; targetModel?: ModelType | string;
targetId?: string | number | null; targetId?: string | number | null;
} }
@ -22,6 +23,7 @@ interface PluginPanelParameters {
props: PluginPanelProps; props: PluginPanelProps;
targetModel?: ModelType | string; targetModel?: ModelType | string;
targetId?: number | null; targetId?: number | null;
targetInstance?: any;
api: AxiosInstance; api: AxiosInstance;
} }
@ -39,6 +41,7 @@ function PanelNoContent() {
* *
* - api instance * - api instance
* - custom context data from server * - custom context data from server
* - model instance (already fetched via API)
*/ */
/** /**
@ -68,7 +71,8 @@ export default function PluginPanel({ props }: { props: PluginPanelProps }) {
props: props, props: props,
api: api, api: api,
targetModel: props.targetModel, targetModel: props.targetModel,
targetId: props.targetId targetId: props.targetId,
targetInstance: props.targetInstance
}); });
} }
}; };

View File

@ -18,9 +18,11 @@ export type PluginPanelState = {
}; };
export function usePluginPanels({ export function usePluginPanels({
targetInstance,
targetModel, targetModel,
targetId targetId
}: { }: {
targetInstance?: any;
targetModel?: ModelType | string; targetModel?: ModelType | string;
targetId?: string | number | null; targetId?: string | number | null;
}): PluginPanelState { }): PluginPanelState {
@ -33,7 +35,7 @@ export function usePluginPanels({
// API query to fetch information on available plugin panels // API query to fetch information on available plugin panels
const { isFetching, data } = useQuery({ const { isFetching, data } = useQuery({
enabled: pluginPanelsEnabled && !!targetModel, enabled: pluginPanelsEnabled && !!targetModel && targetId != undefined,
queryKey: [targetModel, targetId], queryKey: [targetModel, targetId],
queryFn: async () => { queryFn: async () => {
if (!pluginPanelsEnabled || !targetModel) { if (!pluginPanelsEnabled || !targetModel) {
@ -63,7 +65,16 @@ export function usePluginPanels({
name: identifierString(`${pluginKey}-${panel.name}`), name: identifierString(`${pluginKey}-${panel.name}`),
label: panel.label || t`Plugin Panel`, label: panel.label || t`Plugin Panel`,
icon: <InvenTreeIcon icon={panel.icon ?? 'plugin'} />, icon: <InvenTreeIcon icon={panel.icon ?? 'plugin'} />,
content: <PluginPanel props={panel} /> content: (
<PluginPanel
props={{
...panel,
targetId: targetId,
targetModel: targetModel,
targetInstance: targetInstance
}}
/>
)
}; };
}) ?? [] }) ?? []
); );