mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Pass instance data through
This commit is contained in:
@ -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
|
||||||
|
@ -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
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
};
|
};
|
||||||
}) ?? []
|
}) ?? []
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user