fix(import): preserve selected Excel sheet during execution

This commit is contained in:
t8y2 committed 2026-07-21 13:59:30 +08:00
1 parent cda8c4c8e2
commit 177545dca8
4 files changed
+69 -20

No files matched your search

+29
View File
@@ -1,4 +1,5 @@
import type { DatabaseType } from "@/types/database";
import type { TableImportJsonShape, TableImportParseOptions, TableImportSourceFormat, TableImportTextEncoding } from "@/lib/backend/api";
export const IMPORT_SKIP_TARGET = "";
@@ -26,6 +27,34 @@ export type TableImportWizardStep = "source" | "options" | "mapping" | "review"
export const TABLE_IMPORT_WIZARD_STEPS: TableImportWizardStep[] = ["source", "options", "mapping", "review", "execution"];
export interface TableImportParseSettings {
format: TableImportSourceFormat;
delimiter: string;
textEncoding: TableImportTextEncoding;
titleRow: number;
dataStartRow: number;
lastDataRow: number;
trimValues: boolean;
emptyStringAsNull: boolean;
sheetName?: string;
jsonShape: TableImportJsonShape;
}
export function buildTableImportParseOptions(settings: TableImportParseSettings): TableImportParseOptions {
const isDelimited = settings.format === "csv" || settings.format === "tsv" || settings.format === "delimited";
return {
delimiter: settings.format === "tsv" ? "\\t" : settings.format === "csv" ? "," : settings.delimiter,
encoding: isDelimited ? settings.textEncoding : null,
titleRow: settings.titleRow,
dataStartRow: settings.dataStartRow,
lastDataRow: settings.lastDataRow,
trimValues: settings.trimValues,
emptyStringAsNull: settings.emptyStringAsNull,
sheetName: settings.format === "excel" ? settings.sheetName || null : null,
jsonShape: settings.format === "json" ? settings.jsonShape : null,
};
}
export function normalizeImportColumnName(name: string): string {
return name.trim().toLowerCase().replace(/[_-]+/g, " ").replace(/\s+/g, " ");
}