feat(views/table): basic editing of columns (rename not supported)

This commit is contained in:
Elian Doran 2025-07-15 18:51:51 +03:00
parent a04804d3fa
commit 7cd0e664ac
No known key found for this signature in database
4 changed files with 46 additions and 9 deletions

View File

@ -284,6 +284,7 @@ export type CommandMappings = {
parentNotePath?: string; parentNotePath?: string;
}; };
addNewTableColumn: CommandData & { addNewTableColumn: CommandData & {
columnToEdit?: ColumnComponent;
referenceColumn?: ColumnComponent; referenceColumn?: ColumnComponent;
direction?: "before" | "after"; direction?: "before" | "after";
}; };

View File

@ -1955,7 +1955,8 @@
"row-insert-below": "Insert row below", "row-insert-below": "Insert row below",
"row-insert-child": "Insert child note", "row-insert-child": "Insert child note",
"add-column-to-the-left": "Add column to the left", "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": { "book_properties_config": {
"hide-weekends": "Hide weekends", "hide-weekends": "Hide weekends",

View File

@ -25,12 +25,21 @@ export default class TableColumnEditing extends Component {
this.parentNote = parentNote; this.parentNote = parentNote;
} }
addNewTableColumnCommand({ referenceColumn, direction }: EventData<"addNewTableColumn">) { addNewTableColumnCommand({ referenceColumn, columnToEdit, direction }: EventData<"addNewTableColumn">) {
const attr: Attribute = { let attr: Attribute | undefined;
if (columnToEdit) {
attr = this.getAttributeFromField(columnToEdit.getField());
console.log("Built ", attr);
}
if (!attr) {
attr = {
type: "label", type: "label",
name: "label:myLabel", name: "label:myLabel",
value: "promoted,single,text" value: "promoted,single,text"
}; };
}
if (referenceColumn && this.api) { if (referenceColumn && this.api) {
this.newAttributePosition = this.api.getColumns().indexOf(referenceColumn); this.newAttributePosition = this.api.getColumns().indexOf(referenceColumn);
@ -47,7 +56,7 @@ export default class TableColumnEditing extends Component {
allAttributes: [ attr ], allAttributes: [ attr ],
isOwned: true, isOwned: true,
x: 0, x: 0,
y: 75, y: 150,
focus: "name" focus: "name"
}); });
} }
@ -62,7 +71,7 @@ export default class TableColumnEditing extends Component {
} }
const { name, value } = this.newAttribute; const { name, value } = this.newAttribute;
attributes.addLabel(this.parentNote.noteId, name, value, true); attributes.setLabel(this.parentNote.noteId, name, value);
} }
getNewAttributePosition() { getNewAttributePosition() {
@ -73,4 +82,23 @@ export default class TableColumnEditing extends Component {
this.newAttributePosition = 0; 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;
}
}

View File

@ -86,6 +86,13 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, tabulator:
referenceColumn: column 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"), title: t("table_view.add-column-to-the-right"),
uiIcon: "bx bx-horizontal-right", uiIcon: "bx bx-horizontal-right",