MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / useDirectFileImport

Function useDirectFileImport

frontend/src/hooks/useDirectFileImport.ts:10–384  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { DataLoadWithDuckDBResult } from "@/components/layout/Sidebar";
9
10export function useDirectFileImport() {
11 const [isProcessing, setIsProcessing] = useState(false);
12 const [loadingStatus, setLoadingStatus] = useState<string>("");
13 const [loadingProgress, setLoadingProgress] = useState(0);
14 const [processingError, setProcessingError] = useState<string | null>(null);
15
16 const {
17 importFileDirectly,
18 importFileDirectlyStreaming,
19 executeQuery,
20 processingProgress,
21 } = useDuckDBStore();
22
23 const { addRecentFile } = useFileAccess();
24
25 /**
26 * Create UI-ready sample data from DuckDB query results
27 */
28 const createSampleData = useCallback(
29 (schemaResult: any, sampleResult: any): string[][] => {
30 const headers = schemaResult.toArray().map((col: any) => col.name);
31 const sampleData = [
32 headers,
33 ...sampleResult.toArray().map((row: any) =>
34 headers.map((col: string) => {
35 if (row[col] === null || row[col] === undefined) return "";
36 return String(row[col]);
37 })
38 ),
39 ];
40 return sampleData;
41 },
42 []
43 );
44
45 const processFileStreaming = useCallback(
46 async (
47 fileHandle: FileSystemFileHandle,
48 file: File,
49 onDataLoad?: (result: DataLoadWithDuckDBResult) => void
50 ) => {
51 try {
52 setIsProcessing(true);
53 setProcessingError(null);
54
55 const sizeCategory = DataProcessingUtil.getFileSizeCategory(file.size);
56 const formattedSize = DataProcessingUtil.formatFileSize(file.size);
57 const shouldUseStreaming = DataProcessingUtil.shouldUseStreaming(
58 file.size
59 );
60
61 setLoadingStatus(
62 `Starting ${shouldUseStreaming ? "streaming " : ""}import for: ${
63 file.name
64 } (${formattedSize})`
65 );
66
67 console.log(

Callers 3

useLazyFileLoaderFunction · 0.85
useFileImportFunction · 0.85
useHomePageLogicFunction · 0.85

Calls 8

convertDuckDBColumnTypesFunction · 0.90
useFileAccessFunction · 0.85
getFileSizeCategoryMethod · 0.80
formatFileSizeMethod · 0.80
shouldUseStreamingMethod · 0.80
detectSourceTypeMethod · 0.80
validateFileMethod · 0.80
isFileTooLargeMethod · 0.80

Tested by

no test coverage detected