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;
};
addNewTableColumn: CommandData & {
columnToEdit?: ColumnComponent;
referenceColumn?: ColumnComponent;
direction?: "before" | "after";
};

View file

@ -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",

View file

@ -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;
}
}

View file

@ -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",