2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-18 18:28:18 +00:00

[plugin] Instance rendering (#10006)

* Move instance render types into @lib

- Expose type definitions

* Expose rendering function to the plugin context
This commit is contained in:
Oliver
2025-07-11 20:57:15 +10:00
committed by GitHub
parent 786fd846ba
commit d3f24bc529
4 changed files with 35 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ import type { ModelDict } from '../enums/ModelInformation';
import type { ModelType } from '../enums/ModelType';
import type { ApiFormModalProps, BulkEditApiFormModalProps } from './Forms';
import type { UseModalReturn } from './Modals';
import type { RenderInstanceProps } from './Rendering';
import type { SettingsStateProps } from './Settings';
import type { UserStateProps } from './User';
@@ -45,6 +46,7 @@ export type InvenTreeFormsContext = {
* @param locale - The current locale string (e.g. 'en' / 'de')
* @param model - The model type associated with the rendered component (if applicable)
* @param modelInformation - A dictionary of available model information
* @param renderInstance - A component function for rendering a model instance
* @param id - The ID (primary key) of the model instance for the plugin (if applicable)
* @param instance - The model instance data (if available)
* @param reloadContent - A function which can be called to reload the plugin content
@@ -59,6 +61,7 @@ export type InvenTreePluginContext = {
userSettings: SettingsStateProps;
globalSettings: SettingsStateProps;
modelInformation: ModelDict;
renderInstance: (props: Readonly<RenderInstanceProps>) => React.ReactNode;
host: string;
locale: string;
navigate: NavigateFunction;

View File

@@ -0,0 +1,24 @@
import type { ModelType } from '../enums/ModelType';
/**
* Interface for rendering a model instance.
*/
export interface InstanceRenderInterface {
instance: any;
link?: boolean;
navigate?: any;
showSecondary?: boolean;
}
type EnumDictionary<T extends string | symbol | number, U> = {
[K in T]: U;
};
export type ModelRendererDict = EnumDictionary<
ModelType,
(props: Readonly<InstanceRenderInterface>) => React.ReactNode
>;
export type RenderInstanceProps = {
model: ModelType | undefined;
} & InstanceRenderInterface;