feat(mongo): preserve BSON types when cloning and saving documents
This commit is contained in:
12 files changed
+239
-36
No files matched your search
+43
-1
@@ -109,7 +109,7 @@ function createQuickEntryEditor(options: {
|
||||
rowStatusFilter?: ReturnType<typeof ref<RowStatusFilter>>;
|
||||
filterRowsInGetRowItem?: boolean;
|
||||
supportsInsert?: boolean;
|
||||
save?: (changes: { dirtyRows: Map<number, Map<number, CellValue>>; newRows: CellValue[][] }) => Promise<void>;
|
||||
save?: (changes: { dirtyRows: Map<number, Map<number, CellValue>>; newRows: CellValue[][]; newRowMeta: Array<{ sourceIndex?: number; editedColumns?: number[] }> }) => Promise<void>;
|
||||
}) {
|
||||
const result = computed(() => ({
|
||||
columns: ["id", "name"],
|
||||
@@ -376,6 +376,48 @@ test("cloning a row copies non-generated primary key values without executing sa
|
||||
assert.deepEqual(editor.newRows.value, []);
|
||||
});
|
||||
|
||||
test("cloning a row preserves its source and edited columns for custom saves", async () => {
|
||||
setActivePinia(createPinia());
|
||||
installBrowserTestGlobals();
|
||||
|
||||
let savedMeta: Array<{ sourceIndex?: number; editedColumns?: number[] }> | undefined;
|
||||
const editor = createQuickEntryEditor({
|
||||
quickEntryEnabled: false,
|
||||
save: async (changes) => {
|
||||
savedMeta = changes.newRowMeta;
|
||||
},
|
||||
});
|
||||
|
||||
editor.cloneRow(0);
|
||||
assert.equal(editor.newRowMeta.value[0]?.sourceIndex, 0);
|
||||
assert.deepEqual(editor.newRowMeta.value[0]?.editedColumns, undefined);
|
||||
|
||||
editor.applyCellValue(-1, 1, "Grace");
|
||||
assert.deepEqual(editor.newRowMeta.value[0]?.editedColumns, [1]);
|
||||
|
||||
await editor.saveChanges();
|
||||
assert.deepEqual(savedMeta, [
|
||||
{
|
||||
token: 1,
|
||||
placement: null,
|
||||
sourceIndex: 0,
|
||||
editedColumns: [1],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("cloning an edited source row marks its pending changes as explicit", () => {
|
||||
setActivePinia(createPinia());
|
||||
installBrowserTestGlobals();
|
||||
|
||||
const editor = createQuickEntryEditor({ quickEntryEnabled: false });
|
||||
editor.applyCellValue(0, 1, "Lin");
|
||||
editor.cloneRow(0);
|
||||
|
||||
assert.deepEqual(editor.newRows.value, [[1, "Lin"]]);
|
||||
assert.deepEqual(editor.newRowMeta.value[0]?.editedColumns, [1]);
|
||||
});
|
||||
|
||||
test("cloning a row clears auto-generated key columns", async () => {
|
||||
setActivePinia(createPinia());
|
||||
installBrowserTestGlobals();
|
||||
|
||||
+10
@@ -31,6 +31,16 @@ test("mongo document table passes copy context to the data grid", () => {
|
||||
assert.match(source, /props\.databaseType === "mongodb" && mongoCopyDocumentsAvailable\.value/);
|
||||
});
|
||||
|
||||
test("mongo document row clones reuse the type-preserving source document for saves and previews", () => {
|
||||
const source = documentBrowserSource();
|
||||
assert.match(source, /type DocumentGridChanges = \{[\s\S]*?newRowMeta: GridNewRowMeta\[\];/);
|
||||
assert.match(source, /function buildMongoGridInsertDocument\([\s\S]*?copyDocuments\.value\[sourceIndex\][\s\S]*?buildMongoCopyDocumentFromOriginal\([\s\S]*?excludePrimaryKeys: true/);
|
||||
assert.match(source, /buildMongoGridInsertDocument\(newRow, cols, newRowMeta\)/);
|
||||
assert.match(source, /buildMongoGridInsertDocument\(newRow, columns, newRowMeta\[newRowIndex\]\)/);
|
||||
assert.match(source, /preserveBsonTypes = sourceIndex !== undefined && copyDocuments\.value\[sourceIndex\] !== undefined/);
|
||||
assert.match(source, /documentInsertDocument\(props\.connectionId, props\.database, props\.collection, JSON\.stringify\(doc\), undefined, preserveBsonTypes\)/);
|
||||
});
|
||||
|
||||
test("document edit mode toggles whole JSON editing for insert and save", () => {
|
||||
const source = documentBrowserSource();
|
||||
assert.match(source, /documentEditMode = ref<"fields" \| "json">\("json"\)/);
|
||||
|
||||
Reference in new issue
Block a user