feat(views/table): support renaming columns

This commit is contained in:
Elian Doran 2025-07-15 20:42:47 +03:00
parent cf8063f311
commit 14cdc52670
No known key found for this signature in database
3 changed files with 25 additions and 1 deletions

View File

@ -10,6 +10,7 @@ export default class TableColumnEditing extends Component {
private attributeDetailWidget: AttributeDetailWidget;
private newAttributePosition?: number;
private existingAttributeToEdit?: Attribute;
private api: Tabulator;
private newAttribute?: Attribute;
private parentNote: FNote;
@ -30,7 +31,9 @@ export default class TableColumnEditing extends Component {
if (columnToEdit) {
attr = this.getAttributeFromField(columnToEdit.getField());
console.log("Built ", attr);
this.existingAttributeToEdit = { ...attr };
} else {
this.existingAttributeToEdit = undefined;
}
if (!attr) {
@ -71,6 +74,11 @@ export default class TableColumnEditing extends Component {
}
const { name, value } = this.newAttribute;
if (this.existingAttributeToEdit && this.existingAttributeToEdit.name !== name) {
attributes.removeOwnedLabelByName(this.parentNote, this.existingAttributeToEdit.name);
}
attributes.setLabel(this.parentNote.noteId, name, value);
}

View File

@ -78,4 +78,19 @@ describe("restoreExistingData", () => {
expect(restored[1].field).toBe("noteId");
expect(restored[2].field).toBe("newColumn");
});
it("supports a rename", () => {
const newDefs: ColumnDefinition[] = [
{ field: "title", title: "Title", editor: "input" },
{ field: "noteId", title: "Note ID", visible: false },
{ field: "newColumn", title: "New Column", editor: "input" }
];
const oldDefs: ColumnDefinition[] = [
{ field: "title", title: "Title", width: 300, visible: true },
{ field: "noteId", title: "Note ID", width: 200, visible: true },
{ field: "oldColumn", title: "New Column", editor: "input" }
];
const restored = restoreExistingData(newDefs, oldDefs);
expect(restored.length).toBe(3);
})
});

View File

@ -99,6 +99,7 @@ export function restoreExistingData(newDefs: ColumnDefinition[], oldDefs: Column
newDefs.map(def => [def.field!, def])
);
const existingColumns = oldDefs
.filter(item => item.field && newItemsByField.has(item.field!))
.map(item => {
return {
...newItemsByField.get(item.field!),