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:
@@ -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;
|
||||
|
||||
24
src/frontend/lib/types/Rendering.tsx
Normal file
24
src/frontend/lib/types/Rendering.tsx
Normal 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;
|
||||
Reference in New Issue
Block a user