mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
feat(views/table): support renaming columns
This commit is contained in:
parent
cf8063f311
commit
14cdc52670
@ -10,6 +10,7 @@ export default class TableColumnEditing extends Component {
|
|||||||
|
|
||||||
private attributeDetailWidget: AttributeDetailWidget;
|
private attributeDetailWidget: AttributeDetailWidget;
|
||||||
private newAttributePosition?: number;
|
private newAttributePosition?: number;
|
||||||
|
private existingAttributeToEdit?: Attribute;
|
||||||
private api: Tabulator;
|
private api: Tabulator;
|
||||||
private newAttribute?: Attribute;
|
private newAttribute?: Attribute;
|
||||||
private parentNote: FNote;
|
private parentNote: FNote;
|
||||||
@ -30,7 +31,9 @@ export default class TableColumnEditing extends Component {
|
|||||||
|
|
||||||
if (columnToEdit) {
|
if (columnToEdit) {
|
||||||
attr = this.getAttributeFromField(columnToEdit.getField());
|
attr = this.getAttributeFromField(columnToEdit.getField());
|
||||||
console.log("Built ", attr);
|
this.existingAttributeToEdit = { ...attr };
|
||||||
|
} else {
|
||||||
|
this.existingAttributeToEdit = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!attr) {
|
if (!attr) {
|
||||||
@ -71,6 +74,11 @@ export default class TableColumnEditing extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { name, value } = this.newAttribute;
|
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);
|
attributes.setLabel(this.parentNote.noteId, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,4 +78,19 @@ describe("restoreExistingData", () => {
|
|||||||
expect(restored[1].field).toBe("noteId");
|
expect(restored[1].field).toBe("noteId");
|
||||||
expect(restored[2].field).toBe("newColumn");
|
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);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
@ -99,6 +99,7 @@ export function restoreExistingData(newDefs: ColumnDefinition[], oldDefs: Column
|
|||||||
newDefs.map(def => [def.field!, def])
|
newDefs.map(def => [def.field!, def])
|
||||||
);
|
);
|
||||||
const existingColumns = oldDefs
|
const existingColumns = oldDefs
|
||||||
|
.filter(item => item.field && newItemsByField.has(item.field!))
|
||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
...newItemsByField.get(item.field!),
|
...newItemsByField.get(item.field!),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user