mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 17:55:52 +01:00
fix(views/table): index column ends up in the wrong position
This commit is contained in:
@@ -92,5 +92,20 @@ describe("restoreExistingData", () => {
|
||||
];
|
||||
const restored = restoreExistingData(newDefs, oldDefs);
|
||||
expect(restored.length).toBe(3);
|
||||
})
|
||||
});
|
||||
|
||||
it("doesn't alter the existing order", () => {
|
||||
const newDefs: ColumnDefinition[] = [
|
||||
{ title: "#", headerSort: false, hozAlign: "center", resizable: false, frozen: true, rowHandle: false },
|
||||
{ field: "noteId", title: "Note ID", visible: false },
|
||||
{ field: "title", title: "Title", editor: "input", width: 400 }
|
||||
]
|
||||
const oldDefs: ColumnDefinition[] = [
|
||||
{ title: "#", headerSort: false, hozAlign: "center", resizable: false, rowHandle: false },
|
||||
{ field: "noteId", title: "Note ID", visible: false },
|
||||
{ field: "title", title: "Title", editor: "input", width: 400 }
|
||||
];
|
||||
const restored = restoreExistingData(newDefs, oldDefs);
|
||||
expect(restored).toStrictEqual(newDefs);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -99,13 +99,16 @@ 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!),
|
||||
width: item.width,
|
||||
visible: item.visible,
|
||||
};
|
||||
.filter(item => (item.field && newItemsByField.has(item.field!)) || item.title === "#")
|
||||
.map(oldItem => {
|
||||
const data = newItemsByField.get(oldItem.field!)!;
|
||||
if (oldItem.width) {
|
||||
data.width = oldItem.width;
|
||||
}
|
||||
if (oldItem.visible) {
|
||||
data.visible = oldItem.visible;
|
||||
}
|
||||
return data;
|
||||
}) as ColumnDefinition[];
|
||||
|
||||
// 2. Determine new columns.
|
||||
|
||||
Reference in New Issue
Block a user