try to guess desired import target+preselect it

This commit is contained in:
Jan Prochazka 2021-12-09 08:29:54 +01:00
parent a96851b38f
commit 5cc78c4e50
4 changed files with 33 additions and 8 deletions

View File

@ -272,7 +272,7 @@ registerCommand({
icon: 'icon import',
onClick: () =>
showModal(ImportExportModal, {
importToArchive: true,
importToCurrentTarget: true,
initialValues: { sourceStorageType: getDefaultFileFormat(get(extensions)).storageType },
}),
});

View File

@ -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 @@
<FormProvider
initialValues={{
sourceStorageType: 'database',
targetStorageType: importToArchive ? 'archive' : getDefaultFileFormat($extensions).storageType,
targetStorageType: getDefaultFileFormat($extensions).storageType,
targetArchiveFolder: $currentArchive,
sourceArchiveFolder: $currentArchive,
targetArchiveFolder,
...detectCurrentTarget(),
...initialValues,
}}
>

View File

@ -89,7 +89,7 @@ export function openElectronFileCore(filePath, extensions) {
storageType: format.storageType,
shortName: parsed.name,
},
importToArchive: true,
importToCurrentTarget: true,
initialValues: {
sourceStorageType: format.storageType,
},

View File

@ -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,
},