MCPcopy Index your code
hub / github.com/TabularisDB/tabularis / ImportDatabaseModal

Function ImportDatabaseModal

src/components/modals/ImportDatabaseModal.tsx:27–276  ·  view source on GitHub ↗
({
  isOpen,
  onClose,
  connectionId,
  databaseName,
  filePath,
  onSuccess,
}: ImportDatabaseModalProps)

Source from the content-addressed store, hash-verified

25}
26
27export const ImportDatabaseModal = ({
28 isOpen,
29 onClose,
30 connectionId,
31 databaseName,
32 filePath,
33 onSuccess,
34}: ImportDatabaseModalProps) => {
35 const { t } = useTranslation();
36 const { activeSchema } = useDatabase();
37 const { showAlert } = useAlert();
38 const [isImporting, setIsImporting] = useState(false);
39 const [progress, setProgress] = useState<ImportProgress | null>(null);
40 const [error, setError] = useState<string | null>(null);
41 const [success, setSuccess] = useState(false);
42 const [elapsedTime, setElapsedTime] = useState(0); // in seconds
43 const [startTime, setStartTime] = useState<number | null>(null);
44
45 const startImport = useCallback(async () => {
46 setIsImporting(true);
47 setError(null);
48 setSuccess(false);
49 setStartTime(Date.now());
50 setElapsedTime(0);
51
52 try {
53 await invoke("import_database", {
54 connectionId,
55 filePath,
56 ...(activeSchema ? { schema: activeSchema } : {}),
57 });
58
59 setSuccess(true);
60 setIsImporting(false);
61
62 if (onSuccess) {
63 onSuccess();
64 }
65
66 // Auto-close after 2 seconds on success
67 setTimeout(() => {
68 onClose();
69 }, 2000);
70 } catch (e) {
71 const errorMsg = String(e);
72 setError(errorMsg);
73 setIsImporting(false);
74
75 if (!errorMsg.includes("cancelled")) {
76 showAlert(t("dump.importFailure") + ": " + errorMsg, {
77 kind: "error",
78 });
79 }
80 }
81 }, [connectionId, filePath, activeSchema, onSuccess, onClose, t, showAlert]);
82
83 useEffect(() => {
84 if (!isOpen) {

Callers

nothing calls this directly

Calls 3

useDatabaseFunction · 0.90
useAlertFunction · 0.90
formatElapsedTimeFunction · 0.90

Tested by

no test coverage detected