fix(import): preserve selected Excel sheet during execution
This commit is contained in:
1 parent
cda8c4c8e2
commit
177545dca8
4 files changed
+69
-20
No files matched your search
+17
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { autoMapImportColumns, nextTableImportWizardStep, previousTableImportWizardStep, requiredImportTargetColumns, suggestImportTargetDataTypes, validateImportMappings } from "@/lib/table/tableImport";
|
||||
import { autoMapImportColumns, buildTableImportParseOptions, nextTableImportWizardStep, previousTableImportWizardStep, requiredImportTargetColumns, suggestImportTargetDataTypes, validateImportMappings } from "@/lib/table/tableImport";
|
||||
|
||||
describe("tableImport", () => {
|
||||
it("auto maps exact and normalized column names", () => {
|
||||
@@ -54,6 +54,22 @@ describe("tableImport", () => {
|
||||
expect(previousTableImportWizardStep("source")).toBe("source");
|
||||
});
|
||||
|
||||
it("keeps the selected Excel worksheet in execution parse options", () => {
|
||||
const baseSettings = {
|
||||
delimiter: ",",
|
||||
textEncoding: "auto" as const,
|
||||
titleRow: 1,
|
||||
dataStartRow: 2,
|
||||
lastDataRow: 0,
|
||||
trimValues: false,
|
||||
emptyStringAsNull: true,
|
||||
jsonShape: "auto" as const,
|
||||
};
|
||||
|
||||
expect(buildTableImportParseOptions({ ...baseSettings, format: "excel", sheetName: "Second" }).sheetName).toBe("Second");
|
||||
expect(buildTableImportParseOptions({ ...baseSettings, format: "csv", sheetName: "Second" }).sheetName).toBeNull();
|
||||
});
|
||||
|
||||
it("suggests create-table data types from preview rows", () => {
|
||||
expect(
|
||||
suggestImportTargetDataTypes(
|
||||
|
||||
@@ -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, " ");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user