fix(views/table): index column ends up in the wrong position

This commit is contained in:
Elian Doran
2025-07-16 09:16:47 +03:00
parent 9d85005255
commit 2244f0368f
2 changed files with 26 additions and 8 deletions

View File

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

View File

@@ -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.