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 = {
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

View File

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

View File

@ -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
}}
/>
)
};
}) ?? []
);