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
chore(views/table): bring back editing title
Elian Doran9a6a8580de8c
diff --git a/apps/client/src/widgets/view_widgets/table_view/data.ts b/apps/client/src/widgets/view_widgets/table_view/data.tsindex d9111ffee2..d798b345e0 100644--- a/apps/client/src/widgets/view_widgets/table_view/data.ts+++ b/apps/client/src/widgets/view_widgets/table_view/data.ts@@ -56,7 +56,8 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {},{field: "title",- title: "Title"+ title: "Title",+ editor: "input"},{field: "position",@@ -68,6 +69,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {columnDefs.push({field: `labels.${name}`,title: title ?? name,+ editable: true// cellDataType: mapDataType(type),});}diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.tsindex 3267e96c5b..53bc5da8a4 100644--- a/apps/client/src/widgets/view_widgets/table_view/index.ts+++ b/apps/client/src/widgets/view_widgets/table_view/index.ts@@ -8,8 +8,8 @@ import branches from "../../../services/branches.js";import type { CommandListenerData, EventData } from "../../../components/app_context.js";import type { Attribute } from "../../../services/attribute_parser.js";import note_create from "../../../services/note_create.js";-import {Tabulator, SortModule, FormatModule, InteractionModule} from 'tabulator-tables';-import "tabulator-tables/dist/css/tabulator_bootstrap5.min.css";+import {Tabulator, SortModule, FormatModule, InteractionModule, EditModule} from 'tabulator-tables';+import "tabulator-tables/dist/css/tabulator_midnight.min.css";const TPL = /*html*/`<div class="table-view">@@ -81,7 +81,7 @@ export default class TableView extends ViewMode<StateInfo> {const viewStorage = await this.viewStorage.restore();const initialState = viewStorage?.gridState;- const modules = [SortModule, FormatModule, InteractionModule];+ const modules = [SortModule, FormatModule, InteractionModule, EditModule];for (const module of modules) {Tabulator.registerModule(module);}@@ -98,6 +98,7 @@ export default class TableView extends ViewMode<StateInfo> {columns: buildColumnDefinitions(info),data: await buildRowDefinitions(this.parentNote, notes, info)});+ this.setupEditing();}private onSave() {@@ -110,31 +111,36 @@ export default class TableView extends ViewMode<StateInfo> {});}- private setupEditing(): GridOptions<TableData> {- return {- onCellValueChanged(event) {- if (event.type !== "cellValueChanged") {- return;- }-- const noteId = event.data.noteId;- const name = event.colDef.field;- if (!name) {- return;- }+ private setupEditing() {+ this.api!.on("cellEdited", (cell) => {+ const noteId = cell.getRow().getData().noteId;+ const field = cell.getField();+ const newValue = cell.getValue();- const { newValue } = event;- if (name === "title") {- // TODO: Deduplicate with note_title.- server.put(`notes/${noteId}/title`, { title: newValue });- }-- if (name.startsWith("labels.")) {- const labelName = name.split(".", 2)[1];- setLabel(noteId, labelName, newValue);- }+ console.log("Cell edited", field, newValue);+ if (field === "title") {+ server.put(`notes/${noteId}/title`, { title: newValue });}- }+ });++ // return {+ // onCellValueChanged(event) {+ // if (event.type !== "cellValueChanged") {+ // return;+ // }++ // const noteId = event.data.noteId;+ // const name = event.colDef.field;+ // if (!name) {+ // return;+ // }++ // if (name.startsWith("labels.")) {+ // const labelName = name.split(".", 2)[1];+ // setLabel(noteId, labelName, newValue);+ // }+ // }+ // }}private setupDragging() {