feat(import): add table import wizard
This commit is contained in:
1 parent
4b6a588354
commit
4666f8a5f2
16 files changed
+1871
-205
No files matched your search
@@ -501,7 +501,11 @@ export type {
|
||||
TransferTableNameCase,
|
||||
TableImportMode,
|
||||
TableImportStatus,
|
||||
TableImportSourceFormat,
|
||||
TableImportJsonShape,
|
||||
TableImportColumnMapping,
|
||||
TableImportParseOptions,
|
||||
TableImportPreviewRequest,
|
||||
TableImportPreview,
|
||||
TableImportRequest,
|
||||
TableImportSummary,
|
||||
|
||||
@@ -74,6 +74,7 @@ import type {
|
||||
SqlFileProgress,
|
||||
TransferRequest,
|
||||
TransferProgress,
|
||||
TableImportPreviewRequest,
|
||||
TableImportPreview,
|
||||
TableImportRequest,
|
||||
TableImportSummary,
|
||||
@@ -1313,12 +1314,27 @@ export async function sortTablesByFkDependency(options: SortTablesByFkOptions):
|
||||
// Table File Import
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function previewTableImportFile(fileOrPath: string | File): Promise<TableImportPreview> {
|
||||
export async function previewTableImportFile(fileOrPath: string | File | TableImportPreviewRequest, options: Partial<TableImportPreviewRequest> = {}): Promise<TableImportPreview> {
|
||||
if (typeof fileOrPath === "object" && !(fileOrPath instanceof File)) {
|
||||
throw new Error("previewTableImportFile in web mode requires a File object for upload previews");
|
||||
}
|
||||
if (typeof fileOrPath === "string") {
|
||||
throw new Error("previewTableImportFile in web mode requires a File object, not a file path");
|
||||
if (!options.sourceRef) {
|
||||
throw new Error("previewTableImportFile in web mode requires a File object for new uploads");
|
||||
}
|
||||
const res = await fetch(apiUrl("/api/import/preview"), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ request: { ...options, filePath: fileOrPath } }),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append("file", fileOrPath);
|
||||
if (options.sourceFormat) formData.append("sourceFormat", options.sourceFormat);
|
||||
if (options.parseOptions) formData.append("parseOptions", JSON.stringify(options.parseOptions));
|
||||
if (options.previewLimit != null) formData.append("previewLimit", String(options.previewLimit));
|
||||
const res = await fetch(apiUrl("/api/import/preview"), { method: "POST", body: formData });
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return res.json();
|
||||
|
||||
@@ -1898,20 +1898,42 @@ export async function sortTablesByFkDependency(options: SortTablesByFkOptions):
|
||||
// --- Table File Import ---
|
||||
export type TableImportMode = "append" | "truncate";
|
||||
export type TableImportStatus = "running" | "done" | "error" | "cancelled";
|
||||
export type TableImportSourceFormat = "csv" | "tsv" | "delimited" | "json" | "excel";
|
||||
export type TableImportJsonShape = "auto" | "objects" | "arrays";
|
||||
|
||||
export interface TableImportColumnMapping {
|
||||
sourceColumn: string;
|
||||
targetColumn: string;
|
||||
}
|
||||
|
||||
export interface TableImportParseOptions {
|
||||
delimiter?: string | null;
|
||||
hasHeader?: boolean | null;
|
||||
trimValues?: boolean | null;
|
||||
emptyStringAsNull?: boolean | null;
|
||||
sheetName?: string | null;
|
||||
sheetIndex?: number | null;
|
||||
jsonShape?: TableImportJsonShape | null;
|
||||
}
|
||||
|
||||
export interface TableImportPreviewRequest {
|
||||
filePath: string;
|
||||
sourceRef?: string | null;
|
||||
sourceFormat?: TableImportSourceFormat | null;
|
||||
parseOptions?: TableImportParseOptions | null;
|
||||
previewLimit?: number | null;
|
||||
}
|
||||
|
||||
export interface TableImportPreview {
|
||||
fileName: string;
|
||||
filePath: string;
|
||||
sourceRef?: string | null;
|
||||
fileType: string;
|
||||
sizeBytes: number;
|
||||
columns: string[];
|
||||
rows: unknown[][];
|
||||
totalRows: number;
|
||||
sheets?: string[];
|
||||
}
|
||||
|
||||
export interface TableImportRequest {
|
||||
@@ -1921,6 +1943,9 @@ export interface TableImportRequest {
|
||||
schema: string;
|
||||
table: string;
|
||||
filePath: string;
|
||||
sourceRef?: string | null;
|
||||
sourceFormat?: TableImportSourceFormat | null;
|
||||
parseOptions?: TableImportParseOptions | null;
|
||||
mappings: TableImportColumnMapping[];
|
||||
mode: TableImportMode;
|
||||
batchSize: number;
|
||||
@@ -1940,8 +1965,12 @@ export interface TableImportProgress {
|
||||
error?: string | null;
|
||||
}
|
||||
|
||||
export async function previewTableImportFile(filePath: string): Promise<TableImportPreview> {
|
||||
return invoke("preview_table_import_file", { filePath });
|
||||
export async function previewTableImportFile(filePathOrRequest: string | File | TableImportPreviewRequest, options: Partial<TableImportPreviewRequest> = {}): Promise<TableImportPreview> {
|
||||
if (typeof filePathOrRequest !== "string" && !("filePath" in filePathOrRequest)) {
|
||||
throw new Error("previewTableImportFile in desktop mode requires a file path, not a File object");
|
||||
}
|
||||
const request: TableImportPreviewRequest = typeof filePathOrRequest === "string" ? { ...options, filePath: filePathOrRequest } : filePathOrRequest;
|
||||
return invoke("preview_table_import_file", { request });
|
||||
}
|
||||
|
||||
export async function importTableFile(request: TableImportRequest, onProgress: (progress: TableImportProgress) => void): Promise<TableImportSummary> {
|
||||
|
||||
Reference in new issue
Block a user