mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Pass instance data through
This commit is contained in:
parent
f81614dcbe
commit
d25613ac3f
@ -43,6 +43,7 @@ import { PanelType } from './Panel';
|
||||
export type PanelProps = {
|
||||
pageKey: string;
|
||||
panels: PanelType[];
|
||||
targetInstance?: any;
|
||||
targetModel?: ModelType | string;
|
||||
targetId?: number | null;
|
||||
selectedPanel?: string;
|
||||
@ -55,6 +56,7 @@ function BasePanelGroup({
|
||||
panels,
|
||||
onPanelChange,
|
||||
selectedPanel,
|
||||
targetInstance,
|
||||
targetModel,
|
||||
targetId,
|
||||
collapsible = true
|
||||
|
@ -10,6 +10,7 @@ import { PanelType } from '../nav/Panel';
|
||||
interface PluginPanelProps extends PanelType {
|
||||
src?: string;
|
||||
params?: any;
|
||||
targetInstance?: any;
|
||||
targetModel?: ModelType | string;
|
||||
targetId?: string | number | null;
|
||||
}
|
||||
@ -22,6 +23,7 @@ interface PluginPanelParameters {
|
||||
props: PluginPanelProps;
|
||||
targetModel?: ModelType | string;
|
||||
targetId?: number | null;
|
||||
targetInstance?: any;
|
||||
api: AxiosInstance;
|
||||
}
|
||||
|
||||
@ -39,6 +41,7 @@ function PanelNoContent() {
|
||||
*
|
||||
* - api instance
|
||||
* - custom context data from server
|
||||
* - model instance (already fetched via API)
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -68,7 +71,8 @@ export default function PluginPanel({ props }: { props: PluginPanelProps }) {
|
||||
props: props,
|
||||
api: api,
|
||||
targetModel: props.targetModel,
|
||||
targetId: props.targetId
|
||||
targetId: props.targetId,
|
||||
targetInstance: props.targetInstance
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -18,9 +18,11 @@ export type PluginPanelState = {
|
||||
};
|
||||
|
||||
export function usePluginPanels({
|
||||
targetInstance,
|
||||
targetModel,
|
||||
targetId
|
||||
}: {
|
||||
targetInstance?: any;
|
||||
targetModel?: ModelType | string;
|
||||
targetId?: string | number | null;
|
||||
}): PluginPanelState {
|
||||
@ -33,7 +35,7 @@ export function usePluginPanels({
|
||||
|
||||
// API query to fetch information on available plugin panels
|
||||
const { isFetching, data } = useQuery({
|
||||
enabled: pluginPanelsEnabled && !!targetModel,
|
||||
enabled: pluginPanelsEnabled && !!targetModel && targetId != undefined,
|
||||
queryKey: [targetModel, targetId],
|
||||
queryFn: async () => {
|
||||
if (!pluginPanelsEnabled || !targetModel) {
|
||||
@ -63,7 +65,16 @@ export function usePluginPanels({
|
||||
name: identifierString(`${pluginKey}-${panel.name}`),
|
||||
label: panel.label || t`Plugin Panel`,
|
||||
icon: <InvenTreeIcon icon={panel.icon ?? 'plugin'} />,
|
||||
content: <PluginPanel props={panel} />
|
||||
content: (
|
||||
<PluginPanel
|
||||
props={{
|
||||
...panel,
|
||||
targetId: targetId,
|
||||
targetModel: targetModel,
|
||||
targetInstance: targetInstance
|
||||
}}
|
||||
/>
|
||||
)
|
||||
};
|
||||
}) ?? []
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user