feat(views/table): basic formatter for relations

This commit is contained in:
Elian Doran 2025-07-04 15:02:10 +03:00
parent a2e197facd
commit b293643398
No known key found for this signature in database
2 changed files with 13 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import FNote from "../../../entities/fnote.js";
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
import type { ColumnDefinition } from "tabulator-tables";
import link from "../../../services/link.js";
import RelationEditor from "./relation_editor.js";
import { RelationEditor, RelationFormatter } from "./relation_editor.js";
export type TableData = {
iconClass: string;
@ -46,7 +46,8 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
editor: "input"
},
relation: {
editor: RelationEditor
editor: RelationEditor,
formatter: RelationFormatter
}
};

View File

@ -1,7 +1,7 @@
import { CellComponent } from "tabulator-tables";
import note_autocomplete from "../../../services/note_autocomplete";
export default function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){
export function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){
//cell - the cell component for the editable cell
//onRendered - function to call when the editor has been rendered
//success - function to call to pass thesuccessfully updated value to Tabulator
@ -38,3 +38,12 @@ export default function RelationEditor(cell: CellComponent, onRendered, success,
//return the editor element
return editor;
};
export function RelationFormatter(cell: CellComponent, formatterParams, onRendered) {
const noteId = cell.getValue();
if (!noteId) {
return "";
}
return `<a href="#root/${noteId}">Title goes here</a>`;
}