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:
Matthias Mair
2026-05-14 13:18:52 +10:00
committed by GitHub
parent 6e2a867c92
commit 701a788a6e
7 changed files with 79 additions and 9 deletions
+7
View File
@@ -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;
+2
View File
@@ -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;
+4
View File
@@ -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;