Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(views/table): set up relation editor
Elian Dorana2e197facd4b
diff --git a/apps/client/src/widgets/view_widgets/table_view/data.ts b/apps/client/src/widgets/view_widgets/table_view/data.tsindex fd667ca0a3..a86886f709 100644--- a/apps/client/src/widgets/view_widgets/table_view/data.ts+++ b/apps/client/src/widgets/view_widgets/table_view/data.ts@@ -2,6 +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";export type TableData = {iconClass: string;@@ -12,13 +13,15 @@ export type TableData = {position: number;};+type ColumnType = LabelType | "relation";+export interface PromotedAttributeInformation {name: string;title?: string;- type?: LabelType | "relation";+ type?: ColumnType;}-const labelTypeMappings: Record<LabelType, Partial<ColumnDefinition>> = {+const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {text: {editor: "input"},@@ -41,6 +44,9 @@ const labelTypeMappings: Record<LabelType, Partial<ColumnDefinition>> = {url: {formatter: "link",editor: "input"+ },+ relation: {+ editor: RelationEditor}};diff --git a/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts b/apps/client/src/widgets/view_widgets/table_view/relation_editor.tsindex 4f4f17f526..34efad4f61 100644--- a/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts+++ b/apps/client/src/widgets/view_widgets/table_view/relation_editor.ts@@ -1,4 +1,5 @@import { CellComponent } from "tabulator-tables";+import note_autocomplete from "../../../services/note_autocomplete";export default function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){//cell - the cell component for the editable cell@@ -8,9 +9,9 @@ export default function RelationEditor(cell: CellComponent, onRendered, success,//editorParams - params object passed into the editorParams column definition property//create and style editor- var editor = document.createElement("input");-- editor.setAttribute("type", "date");+ const editor = document.createElement("input");+ const $editor = $(editor);+ editor.classList.add("form-control");//create and style inputeditor.style.padding = "3px";@@ -22,13 +23,13 @@ export default function RelationEditor(cell: CellComponent, onRendered, success,//set focus on the select box when the editor is selectedonRendered(function(){+ note_autocomplete.initNoteAutocomplete($editor);editor.focus();- editor.style.css = "100%";});//when the value has been set, trigger the cell to updatefunction successFunc(){- success("Hi");+ success($editor.getSelectedNoteId());}editor.addEventListener("change", successFunc);