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
refactor(book/table): make clear what kind of attribute is being changed
Elian Doran168e224d3e1c
diff --git a/apps/client/src/widgets/view_widgets/table_view/data.ts b/apps/client/src/widgets/view_widgets/table_view/data.tsindex 1a7d6fd084..7a8a461d82 100644--- a/apps/client/src/widgets/view_widgets/table_view/data.ts+++ b/apps/client/src/widgets/view_widgets/table_view/data.ts@@ -6,7 +6,8 @@ import { default as getPromotedAttributeInformation, type PromotedAttributeInforexport type TableData = {noteId: string;title: string;-} & Record<string, string>;+ labels: Record<string, boolean | string | null>;+};type GridLabelType = 'text' | 'number' | 'boolean' | 'date' | 'dateString' | 'object';@@ -33,7 +34,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {for (const { name, title, type } of info) {columnDefs.push({- field: name,+ field: `labels.${name}`,headerName: title,cellDataType: mapDataType(type),editable: true@@ -64,20 +65,19 @@ function mapDataType(labelType: LabelType | undefined): GridLabelType {export function buildRowDefinitions(notes: FNote[], infos: PromotedAttributeInformation[]) {const definitions: GridOptions<TableData>["rowData"] = [];for (const note of notes) {- const data = {- noteId: note.noteId,- title: note.title- };-+ const labels: typeof definitions[0]["labels"] = {};for (const { name, type } of infos) {if (type === "boolean") {- data[name] = note.hasLabel(name);+ labels[name] = note.hasLabel(name);} else {- data[name] = note.getLabelValue(name);+ labels[name] = note.getLabelValue(name);}}-- definitions.push(data);+ definitions.push({+ noteId: note.noteId,+ title: note.title,+ labels+ });}return definitions;diff --git a/apps/client/src/widgets/view_widgets/table_view/renderer.ts b/apps/client/src/widgets/view_widgets/table_view/renderer.tsindex 18ed838a4f..c4e7384b4b 100644--- a/apps/client/src/widgets/view_widgets/table_view/renderer.ts+++ b/apps/client/src/widgets/view_widgets/table_view/renderer.ts@@ -42,8 +42,11 @@ function setupEditing(): GridOptions<TableData> {return;}- const { newValue } = event;- setLabel(noteId, name, newValue);+ if (name.startsWith("labels.")) {+ const { newValue } = event;+ const labelName = name.split(".", 2)[1];+ setLabel(noteId, labelName, newValue);+ }}}}