Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(import): recover preview reload after invalid row range

lxk9558786c76ff452
diff --git a/apps/desktop/src/components/import/TableImportDialog.vue b/apps/desktop/src/components/import/TableImportDialog.vue
index f462c24adf..b1ca5720b4 100644
--- a/apps/desktop/src/components/import/TableImportDialog.vue
+++ b/apps/desktop/src/components/import/TableImportDialog.vue
@@ -813,6 +813,7 @@ function assignSelectedSource(source: string | File) {
delimiter.value = sourceFormat.value === "tsv" ? "\\t" : ",";
selectedSheet.value = "";
wizardStep.value = "options";
+ void loadPreview(source);
}
function activateBatchTask(index: number) {
@@ -1019,6 +1020,10 @@ function wizardStepCircleClass(step: TableImportWizardStep) {
}
async function goNext() {
+ if (wizardStep.value === "source" && !preview.value && selectedSource.value && !isBatchImport.value) {
+ await loadPreview();
+ if (!preview.value) return;
+ }
if (wizardStep.value === "options" && !preview.value) {
await loadPreview();
if (!preview.value) return;
@@ -1246,7 +1251,7 @@ async function cancelImport() {
function schedulePreviewReload() {
// Batch tasks own independent previews and mappings; reloading the active task would overwrite its saved configuration.
- if (isBatchImport.value || !preview.value || !selectedSource.value || loadingPreview.value || running.value) return;
+ if (isBatchImport.value || !selectedSource.value || running.value) return;
if (previewReloadTimer) clearTimeout(previewReloadTimer);
previewReloadTimer = setTimeout(() => {
void loadPreview();
@@ -1338,6 +1343,9 @@ watch(wizardStep, (step) => {
if (step === "options") {
if (showSchemaSelector.value) void loadSchemaOptions();
void loadExistingTables();
+ if (!preview.value && selectedSource.value && !isBatchImport.value && !loadingPreview.value) {
+ void loadPreview();
+ }
}
});
watch(targetMode, (mode) => {
diff --git a/apps/desktop/src/components/import/__tests__/TableImportDialog.batchSelection.spec.ts b/apps/desktop/src/components/import/__tests__/TableImportDialog.batchSelection.spec.ts
index f8391e9889..35b0691374 100644
--- a/apps/desktop/src/components/import/__tests__/TableImportDialog.batchSelection.spec.ts
+++ b/apps/desktop/src/components/import/__tests__/TableImportDialog.batchSelection.spec.ts
@@ -595,4 +595,59 @@ describe("TableImportDialog batch selection", () => {
expect(mocks.importTableFile.mock.calls[0]![0]).toMatchObject({ table: "second", sourceFormat: "csv", parseOptions: { encoding: "utf8", sheetName: null } });
expect(mocks.releaseTableImportSource.mock.calls.map(([source]) => source).sort()).toEqual(["first.csv-source", "second.csv-source"]);
});
+
+ it("recovers preview and enables next step when data start row is adjusted after an invalid title row (#11689)", async () => {
+ mocks.previewTableImportFile.mockImplementation((_source, options) => {
+ const { titleRow, dataStartRow } = options.parseOptions;
+ if (titleRow !== null && titleRow !== undefined && titleRow >= dataStartRow) {
+ return Promise.reject(new Error("Title row must be before the data start row"));
+ }
+ return Promise.resolve(delimitedPreview());
+ });
+ await mountDialog([new File(["id,name\n1,alice\n2,bob"], "rows.csv")]);
+ expect(button("Next").disabled).toBe(false);
+
+ await editInputWithValue("1", "3");
+ await new Promise((resolve) => setTimeout(resolve, 300));
+ await flushAsyncUpdates();
+
+ expect(document.body.textContent).toContain("Title row must be before the data start row");
+ expect(button("Next").disabled).toBe(true);
+
+ await editInputWithValue("2", "4");
+ await new Promise((resolve) => setTimeout(resolve, 300));
+ await flushAsyncUpdates();
+
+ expect(document.body.textContent).not.toContain("Title row must be before the data start row");
+ expect(button("Next").disabled).toBe(false);
+ });
+
+ it("reloads preview when returning to options step after preview was cleared by error (#11689)", async () => {
+ let failPreview = false;
+ mocks.previewTableImportFile.mockImplementation((_source, _options) => {
+ if (failPreview) {
+ return Promise.reject(new Error("Title row must be before the data start row"));
+ }
+ return Promise.resolve(delimitedPreview());
+ });
+ await mountDialog([new File(["id,name\n1,alice"], "rows.csv")]);
+ expect(button("Next").disabled).toBe(false);
+
+ failPreview = true;
+ await editInputWithValue("1", "3");
+ await new Promise((resolve) => setTimeout(resolve, 300));
+ await flushAsyncUpdates();
+
+ expect(document.body.textContent).toContain("Title row must be before the data start row");
+ expect(button("Next").disabled).toBe(true);
+
+ failPreview = false;
+ await click("Back");
+ expect(button("Next").disabled).toBe(false);
+ await click("Next");
+ await flushAsyncUpdates();
+
+ expect(document.body.textContent).not.toContain("Title row must be before the data start row");
+ expect(button("Next").disabled).toBe(false);
+ });
});