25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(grid): refresh data after deleting rows
t8y2933c1fd803d4
diff --git a/src/composables/useDataGridEditor.ts b/src/composables/useDataGridEditor.tsindex a39084cdc3..d5de63882a 100644--- a/src/composables/useDataGridEditor.ts+++ b/src/composables/useDataGridEditor.ts@@ -101,9 +101,15 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {canEditExistingRows = computed(() => true),onExecuteSql,customSave,+ sql,+ searchText,+ whereFilterInput,+ orderByInput,rowStatusFilter,initialEditColumn,getRowItem,+ pageSize,+ currentPage,} = options;const editingCell = ref<{ rowId: number; col: number } | null>(null);@@ -557,9 +563,22 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {});}+ function reloadCurrentData() {+ options.emit(+ "reload",+ sql.value,+ searchText.value,+ whereFilterInput.value.trim() || undefined,+ orderByInput.value.trim() || undefined,+ pageSize.value,+ (currentPage.value - 1) * pageSize.value,+ );+ }+async function saveChanges() {saveError.value = "";isSaving.value = true;+ const shouldReloadAfterSave = deletedRows.value.size > 0;if (customSave?.value) {try {@@ -580,6 +599,9 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {deletedRows.value.clear();exitTransaction();isSaving.value = false;+ if (shouldReloadAfterSave) {+ reloadCurrentData();+ }return;}@@ -669,6 +691,9 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {deletedRows.value.clear();exitTransaction();isSaving.value = false;+ if (shouldReloadAfterSave) {+ reloadCurrentData();+ }}function discardChanges() {diff --git a/tests/dataGridEditor.test.ts b/tests/dataGridEditor.test.tsindex 3fa7dae319..1d5d3b765b 100644--- a/tests/dataGridEditor.test.ts+++ b/tests/dataGridEditor.test.ts@@ -160,3 +160,113 @@ test("cloning a row clears auto-generated key columns", async () => {assert.deepEqual(editor.newRows.value, [[null, "Ada"]]);});++test("saving deleted 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[][] = [];+ let editor: ReturnType<typeof useDataGridEditor>;++ editor = useDataGridEditor({+ result,+ editable: computed(() => true),+ databaseType: computed(() => "postgres"),+ connectionId: computed(() => "conn-1"),+ database: computed(() => "main"),+ tableMeta: computed(() => ({+ tableName: "people",+ columns: [column("id", true), column("name")],+ primaryKeys: ["id"],+ })),+ onExecuteSql: computed(() => undefined),+ customSave: computed(() => async () => {}),+ sql: computed(() => "SELECT id, name FROM people"),+ searchText: ref("ada"),+ whereFilterInput: ref("name ILIKE '%a%'"),+ orderByInput: ref("id DESC"),+ rowStatusFilter,+ pageSize: ref(50),+ currentPage: ref(3),+ getRowItem: (rowId) => {+ if (rowId !== 0) return undefined;+ return {+ id: 0,+ sourceIndex: 0,+ data: result.value.rows[0],+ isNew: false,+ isDeleted: false,+ isDirtyCol: [false, false],+ status: "clean",+ };+ },+ emit: (...args) => {+ emitted.push(args);+ },+ });++ editor.applyDeleteRow(0);+ await editor.saveChanges();++ assert.deepEqual(emitted, [["reload", "SELECT id, name FROM people", "ada", "name ILIKE '%a%'", "id DESC", 50, 100]]);+});++test("saving edited rows without deletes does not reload 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[][] = [];+ let editor: ReturnType<typeof useDataGridEditor>;++ editor = useDataGridEditor({+ result,+ editable: computed(() => true),+ databaseType: computed(() => "postgres"),+ connectionId: computed(() => "conn-1"),+ database: computed(() => "main"),+ tableMeta: computed(() => ({+ tableName: "people",+ columns: [column("id", true), column("name")],+ primaryKeys: ["id"],+ })),+ onExecuteSql: computed(() => undefined),+ customSave: computed(() => async () => {}),+ sql: computed(() => "SELECT id, name FROM people"),+ searchText: ref(""),+ whereFilterInput: ref(""),+ orderByInput: ref(""),+ rowStatusFilter,+ pageSize: ref(50),+ currentPage: ref(1),+ getRowItem: (rowId) => {+ if (rowId !== 0) return undefined;+ return {+ id: 0,+ sourceIndex: 0,+ data: result.value.rows[0],+ isNew: false,+ isDeleted: false,+ isDirtyCol: [false, false],+ status: "clean",+ };+ },+ emit: (...args) => {+ emitted.push(args);+ },+ });++ editor.applyCellValue(0, 1, "Ada Lovelace");+ await editor.saveChanges();++ assert.deepEqual(emitted, []);+});