From ab6c73c6877e0e98c3c12dfb6df5c4d5ee4130e0 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 21 May 2026 10:23:37 +0800 Subject: [PATCH] fix(grid): reload after inserted rows save --- .../src/composables/useDataGridEditor.ts | 2 +- packages/app-tests/dataGridEditor.test.ts | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/composables/useDataGridEditor.ts b/apps/desktop/src/composables/useDataGridEditor.ts index 6cf8cc362..fece519a4 100644 --- a/apps/desktop/src/composables/useDataGridEditor.ts +++ b/apps/desktop/src/composables/useDataGridEditor.ts @@ -608,7 +608,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) { async function saveChanges() { saveError.value = ""; isSaving.value = true; - const shouldReloadAfterSave = deletedRows.value.size > 0; + const shouldReloadAfterSave = newRows.value.length > 0 || deletedRows.value.size > 0; if (customSave?.value) { try { diff --git a/packages/app-tests/dataGridEditor.test.ts b/packages/app-tests/dataGridEditor.test.ts index 848c9c787..5926793a1 100644 --- a/packages/app-tests/dataGridEditor.test.ts +++ b/packages/app-tests/dataGridEditor.test.ts @@ -216,6 +216,56 @@ test("saving deleted rows reloads current table data", async () => { assert.deepEqual(emitted, [["reload", "SELECT id, name FROM people", "ada", "name ILIKE '%a%'", "id DESC", 50, 100]]); }); +test("saving inserted rows reloads current table data", async () => { + setActivePinia(createPinia()); + installBrowserTestGlobals(); + + const result = computed(() => ({ + columns: ["id", "name"], + rows: [[1, "Ada"] as CellValue[]], + })); + const rowStatusFilter = ref<"all" | "changed" | "edited" | "new" | "deleted">("all"); + const emitted: unknown[][] = []; + const executedSql: string[] = []; + + const editor = useDataGridEditor({ + result, + editable: computed(() => true), + databaseType: computed(() => "postgres"), + connectionId: computed(() => undefined), + database: computed(() => undefined), + tableMeta: computed(() => ({ + schema: "public", + tableName: "people", + columns: [column("id", true), column("name")], + primaryKeys: ["id"], + })), + onExecuteSql: computed(() => async (sql: string) => { + executedSql.push(sql); + }), + customSave: computed(() => undefined), + sql: computed(() => "SELECT id, name FROM people"), + searchText: ref("linus"), + whereFilterInput: ref("name ILIKE '%l%'"), + orderByInput: ref("id DESC"), + rowStatusFilter, + pageSize: ref(50), + currentPage: ref(2), + getRowItem: () => undefined, + emit: (...args) => { + emitted.push(args); + }, + }); + + editor.newRows.value = [[2, "Linus"]]; + await editor.saveChanges(); + + assert.deepEqual(executedSql, [`INSERT INTO "public"."people" ("id", "name") VALUES (2, 'Linus');`]); + assert.deepEqual(emitted, [ + ["reload", "SELECT id, name FROM people", "linus", "name ILIKE '%l%'", "id DESC", 50, 50], + ]); +}); + test("saving edited rows without deletes does not reload table data", async () => { setActivePinia(createPinia()); installBrowserTestGlobals();