mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-02 10:18:42 +00:00
feat(frontend): custom model render registration (#11928)
* refactor RenderInstance * add custom mode renderer * add optional custom_model api form arg * switch to fallback mechanism * remove warning * fix imports * adress sonarque rules
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import type { InstanceRenderInterface } from '../types/Rendering';
|
||||
|
||||
export type setRenderProps = (
|
||||
model: string,
|
||||
renderer: (props: Readonly<InstanceRenderInterface>) => ReactNode
|
||||
) => void;
|
||||
@@ -45,6 +45,7 @@ export type ApiFormFieldHeader = {
|
||||
* @param api_url : The API endpoint to fetch data from (for related fields)
|
||||
* @param pk_field : The primary key field for the related field (default = "pk")
|
||||
* @param model : The model to use for related fields
|
||||
* @param custom_model : Optional custom model name (plugins may register renderers for custom models)
|
||||
* @param modelRenderer : Optional function to render the related model instance (for related fields)
|
||||
* @param filters : Optional API filters to apply to related fields
|
||||
* @param child: Optional definition of a child field (for nested objects)
|
||||
@@ -101,6 +102,7 @@ export type ApiFormFieldType = {
|
||||
api_url?: string;
|
||||
pk_field?: string;
|
||||
model?: ModelType;
|
||||
custom_model?: string;
|
||||
modelRenderer?: (instance: any) => ReactNode;
|
||||
filters?: any;
|
||||
child?: ApiFormFieldType;
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { JSX } from 'react';
|
||||
import type { NavigateFunction } from 'react-router-dom';
|
||||
import type { ModelDict } from '../enums/ModelInformation';
|
||||
import type { ModelType } from '../enums/ModelType';
|
||||
import type { setRenderProps } from '../states/types';
|
||||
import type {
|
||||
ApiFormModalProps,
|
||||
ApiFormProps,
|
||||
@@ -119,6 +120,9 @@ export type InvenTreePluginContext = {
|
||||
theme: MantineTheme;
|
||||
colorScheme: MantineColorScheme;
|
||||
forms: InvenTreeFormsContext;
|
||||
stateFnc: {
|
||||
setRenderer: setRenderProps;
|
||||
};
|
||||
tables: InvenTreeTablesContext<any>;
|
||||
importer: ImporterDrawerContext;
|
||||
model?: ModelType | string;
|
||||
|
||||
Reference in New Issue
Block a user