2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

[PUI] Plugin panel context (#8190)

* Add server-side context for panel plugin rendering

* Add "context" to PluginContext type

* Pass server context through to client-side rendering

* Bump API version
This commit is contained in:
Oliver
2024-09-26 20:30:51 +10:00
committed by GitHub
parent 35362347a7
commit 194640f55a
7 changed files with 49 additions and 10 deletions

View File

@ -13,6 +13,7 @@ export type PluginPanelProps = {
label: string;
icon?: string;
content?: string;
context?: any;
source?: string;
};
@ -82,7 +83,9 @@ export default function PluginPanelContent({
func(ref.current, pluginContext);
setError('');
} catch (error) {
setError(t`Error occurred while rendering plugin content`);
setError(
t`Error occurred while rendering plugin content: ${error}`
);
}
} else {
setError(t`Plugin did not provide panel rendering function`);

View File

@ -111,6 +111,11 @@ export function usePluginPanels({
);
const isHidden: boolean = panelState[identifier] ?? true;
const pluginContext: any = {
...contextData,
context: props.context
};
return {
name: identifier,
label: props.label,
@ -118,7 +123,7 @@ export function usePluginPanels({
content: (
<PluginPanelContent
pluginProps={props}
pluginContext={contextData}
pluginContext={pluginContext}
/>
),
hidden: isHidden