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): basic editing of columns (rename not supported)
Elian Doran7cd0e664ac06
diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.tsindex 51f8120a9e..24545fdaa6 100644--- a/apps/client/src/components/app_context.ts+++ b/apps/client/src/components/app_context.ts@@ -284,6 +284,7 @@ export type CommandMappings = {parentNotePath?: string;};addNewTableColumn: CommandData & {+ columnToEdit?: ColumnComponent;referenceColumn?: ColumnComponent;direction?: "before" | "after";};diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex fae8d04a13..cfc80a537f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1955,7 +1955,8 @@"row-insert-below": "Insert row below","row-insert-child": "Insert child note","add-column-to-the-left": "Add column to the left",- "add-column-to-the-right": "Add column to the right"+ "add-column-to-the-right": "Add column to the right",+ "edit-column": "Edit column"},"book_properties_config": {"hide-weekends": "Hide weekends",diff --git a/apps/client/src/widgets/view_widgets/table_view/col_editing.ts b/apps/client/src/widgets/view_widgets/table_view/col_editing.tsindex 193714a6e1..983b89b1d5 100644--- a/apps/client/src/widgets/view_widgets/table_view/col_editing.ts+++ b/apps/client/src/widgets/view_widgets/table_view/col_editing.ts@@ -25,12 +25,21 @@ export default class TableColumnEditing extends Component {this.parentNote = parentNote;}- addNewTableColumnCommand({ referenceColumn, direction }: EventData<"addNewTableColumn">) {- const attr: Attribute = {- type: "label",- name: "label:myLabel",- value: "promoted,single,text"- };+ addNewTableColumnCommand({ referenceColumn, columnToEdit, direction }: EventData<"addNewTableColumn">) {+ let attr: Attribute | undefined;++ if (columnToEdit) {+ attr = this.getAttributeFromField(columnToEdit.getField());+ console.log("Built ", attr);+ }++ if (!attr) {+ attr = {+ type: "label",+ name: "label:myLabel",+ value: "promoted,single,text"+ };+ }if (referenceColumn && this.api) {this.newAttributePosition = this.api.getColumns().indexOf(referenceColumn);@@ -47,7 +56,7 @@ export default class TableColumnEditing extends Component {allAttributes: [ attr ],isOwned: true,x: 0,- y: 75,+ y: 150,focus: "name"});}@@ -62,7 +71,7 @@ export default class TableColumnEditing extends Component {}const { name, value } = this.newAttribute;- attributes.addLabel(this.parentNote.noteId, name, value, true);+ attributes.setLabel(this.parentNote.noteId, name, value);}getNewAttributePosition() {@@ -73,4 +82,23 @@ export default class TableColumnEditing extends Component {this.newAttributePosition = 0;}+ getFAttributeFromField(field: string) {+ const [ type, name ] = field.split(".", 2);+ const attrName = `${type.replace("s", "")}:${name}`;+ return this.parentNote.getLabel(attrName);+ }++ getAttributeFromField(field: string) {+ const fAttribute = this.getFAttributeFromField(field);+ if (fAttribute) {+ return {+ name: fAttribute.name,+ value: fAttribute.value,+ type: fAttribute.type+ };+ }+ return undefined;+ }+}+diff --git a/apps/client/src/widgets/view_widgets/table_view/context_menu.ts b/apps/client/src/widgets/view_widgets/table_view/context_menu.tsindex 816e5c27c7..0c7ed4760a 100644--- a/apps/client/src/widgets/view_widgets/table_view/context_menu.ts+++ b/apps/client/src/widgets/view_widgets/table_view/context_menu.ts@@ -86,6 +86,13 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, tabulator:referenceColumn: column})},+ {+ title: t("table_view.edit-column"),+ uiIcon: "bx bx-edit",+ handler: () => getParentComponent(e)?.triggerCommand("addNewTableColumn", {+ columnToEdit: column+ })+ },{title: t("table_view.add-column-to-the-right"),uiIcon: "bx bx-horizontal-right",