mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 02:05:53 +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);
|
const restored = restoreExistingData(newDefs, oldDefs);
|
||||||
expect(restored.length).toBe(3);
|
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])
|
newDefs.map(def => [def.field!, def])
|
||||||
);
|
);
|
||||||
const existingColumns = oldDefs
|
const existingColumns = oldDefs
|
||||||
.filter(item => item.field && newItemsByField.has(item.field!))
|
.filter(item => (item.field && newItemsByField.has(item.field!)) || item.title === "#")
|
||||||
.map(item => {
|
.map(oldItem => {
|
||||||
return {
|
const data = newItemsByField.get(oldItem.field!)!;
|
||||||
...newItemsByField.get(item.field!),
|
if (oldItem.width) {
|
||||||
width: item.width,
|
data.width = oldItem.width;
|
||||||
visible: item.visible,
|
}
|
||||||
};
|
if (oldItem.visible) {
|
||||||
|
data.visible = oldItem.visible;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}) as ColumnDefinition[];
|
}) as ColumnDefinition[];
|
||||||
|
|
||||||
// 2. Determine new columns.
|
// 2. Determine new columns.
|
||||||
|
|||||||
Reference in New Issue
Block a user