diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index 1b684d2c..826df60b 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -272,7 +272,7 @@ registerCommand({ icon: 'icon import', onClick: () => showModal(ImportExportModal, { - importToArchive: true, + importToCurrentTarget: true, initialValues: { sourceStorageType: getDefaultFileFormat(get(extensions)).storageType }, }), }); diff --git a/packages/web/src/modals/ImportExportModal.svelte b/packages/web/src/modals/ImportExportModal.svelte index b0a000bb..6f98a282 100644 --- a/packages/web/src/modals/ImportExportModal.svelte +++ b/packages/web/src/modals/ImportExportModal.svelte @@ -15,7 +15,7 @@ import { getDefaultFileFormat } from '../plugins/fileformats'; import RunnerOutputFiles from '../query/RunnerOutputFiles.svelte'; import SocketMessageView from '../query/SocketMessageView.svelte'; - import { currentArchive, extensions, selectedWidget } from '../stores'; + import { currentArchive, currentDatabase, extensions, selectedWidget } from '../stores'; import axiosInstance from '../utility/axiosInstance'; import createRef from '../utility/createRef'; import openNewTab from '../utility/openNewTab'; @@ -35,11 +35,35 @@ export let initialValues; export let uploadedFile = undefined; export let openedFile = undefined; - export let importToArchive = false; + export let importToCurrentTarget = false; const refreshArchiveFolderRef = createRef(null); - $: targetArchiveFolder = importToArchive ? `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}` : $currentArchive; + function detectCurrentTarget() { + if (!importToCurrentTarget) return {}; + + if ($currentDatabase && $selectedWidget != 'archive') { + return { + targetStorageType: 'database', + targetConnectionId: $currentDatabase?.connection?._id, + targetDatabaseName: $currentDatabase?.name, + }; + } + + if ($currentArchive == 'default') { + return { + targetStorageType: 'archive', + targetArchiveFolder: `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}`, + }; + } else { + return { + targetStorageType: 'archive', + targetArchiveFolder: $currentArchive, + }; + } + } + + // $: targetArchiveFolder = importToArchive ? `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}` : $currentArchive; $: effect = useEffect(() => registerRunnerDone(runnerId)); @@ -107,9 +131,10 @@ diff --git a/packages/web/src/utility/openElectronFile.ts b/packages/web/src/utility/openElectronFile.ts index f39d9fba..c4e458cb 100644 --- a/packages/web/src/utility/openElectronFile.ts +++ b/packages/web/src/utility/openElectronFile.ts @@ -89,7 +89,7 @@ export function openElectronFileCore(filePath, extensions) { storageType: format.storageType, shortName: parsed.name, }, - importToArchive: true, + importToCurrentTarget: true, initialValues: { sourceStorageType: format.storageType, }, diff --git a/packages/web/src/utility/uploadFiles.ts b/packages/web/src/utility/uploadFiles.ts index c067b16e..6530e21b 100644 --- a/packages/web/src/utility/uploadFiles.ts +++ b/packages/web/src/utility/uploadFiles.ts @@ -66,7 +66,7 @@ export default function uploadFiles(files) { if (findFileFormat(ext, fileData.storageType)) { showModal(ImportExportModal, { uploadedFile: fileData, - importToArchive: true, + importToCurrentTarget: true, initialValues: { sourceStorageType: fileData.storageType, },