Render Note instance in forms

This commit is contained in:
Oliver Walters 2026-06-14 00:48:05 +00:00
parent b06f47815d
commit cc36bfb8e4
5 changed files with 26 additions and 3 deletions

View File

@ -325,5 +325,12 @@ export const ModelInformationDict: ModelDict = {
label_multiple: () => t`Tags`,
api_endpoint: ApiEndpoints.tag_list,
icon: 'tag'
},
notetemplate: {
label: () => t`Note Template`,
label_multiple: () => t`Note Templates`,
url_overview: '/settings/admin/notes',
api_endpoint: ApiEndpoints.note_list,
icon: 'notes'
}
};

View File

@ -39,7 +39,8 @@ export enum ModelType {
selectionlist = 'selectionlist',
selectionentry = 'selectionentry',
error = 'error',
tag = 'tag'
tag = 'tag',
notetemplate = 'notetemplate'
}
export enum PluginPanelKey {

View File

@ -58,6 +58,7 @@ import {
RenderSelectionList,
RenderTag
} from './Generic';
import { RenderNoteTemplate } from './Note';
import {
RenderPurchaseOrder,
RenderReturnOrder,
@ -118,7 +119,8 @@ export const RendererLookup: ModelRendererDict = {
[ModelType.selectionlist]: RenderSelectionList,
[ModelType.selectionentry]: RenderSelectionEntry,
[ModelType.error]: RenderError,
[ModelType.tag]: RenderTag
[ModelType.tag]: RenderTag,
[ModelType.notetemplate]: RenderNoteTemplate
};
/**

View File

@ -0,0 +1,13 @@
import type { ReactNode } from 'react';
import { RenderInlineModel } from './Instance';
export function RenderNoteTemplate({
instance
}: Readonly<{
instance: any;
}>): ReactNode {
return (
<RenderInlineModel primary={instance.title} suffix={instance.description} />
);
}

View File

@ -345,13 +345,13 @@ export function useNoteFields({
field_type: 'related field',
label: t`From Template`,
description: t`Optionally pre-fill this note from an existing template`,
model: ModelType.notetemplate,
api_url: apiUrl(ApiEndpoints.note_list),
filters: {
template: true,
model_type: modelType
},
pk_field: 'pk',
render_description_field: 'description',
required: false,
onValueChange: (value: any) => fetchTemplate(value),
value: null