refresh archive folder after import

This commit is contained in:
Jan Prochazka
2020-11-15 20:46:42 +01:00
parent 801bf05a31
commit 72776f3297
3 changed files with 30 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ import ModalContent from './ModalContent';
import ImportExportConfigurator from '../impexp/ImportExportConfigurator';
import createImpExpScript from '../impexp/createImpExpScript';
import { openNewTab } from '../utility/common';
import { useCurrentArchive, useSetOpenedTabs } from '../utility/globalState';
import { useCurrentArchive, useSetCurrentArchive, useSetCurrentWidget, useSetOpenedTabs } from '../utility/globalState';
import RunnerOutputPane from '../query/RunnerOutputPane';
import axios from '../utility/axios';
import WidgetColumnBar, { WidgetColumnBarItem } from '../widgets/WidgetColumnBar';
@@ -119,11 +119,20 @@ export default function ImportExportModal({
const [previewReader, setPreviewReader] = React.useState(0);
const targetArchiveFolder = importToArchive ? `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}` : archive;
const socket = useSocket();
const refreshArchiveFolderRef = React.useRef(null);
const setArchive = useSetCurrentArchive();
const setCurrentWidget = useSetCurrentWidget();
const [busy, setBusy] = React.useState(false);
const handleRunnerDone = React.useCallback(() => {
setBusy(false);
if (refreshArchiveFolderRef.current) {
axios.post('archive/refresh-folders', {});
axios.post('archive/refresh-files', { folder: refreshArchiveFolderRef.current });
setArchive(refreshArchiveFolderRef.current);
setCurrentWidget('archive');
}
}, []);
React.useEffect(() => {
@@ -146,6 +155,11 @@ export default function ImportExportModal({
runid = resp.data.runid;
setRunnerId(runid);
setBusy(true);
if (values.targetStorageType == 'archive') {
refreshArchiveFolderRef.current = values.targetArchiveFolder;
} else {
refreshArchiveFolderRef.current = null;
}
};
const handleCancel = () => {

View File

@@ -3,7 +3,7 @@ import _ from 'lodash';
import axios from './axios';
import useSocket from './SocketProvider';
import stableStringify from 'json-stable-stringify';
import { getCachedPromise, cacheGet, cacheSet } from './cache';
import { getCachedPromise, cacheGet, cacheSet, cacheClean } from './cache';
import getAsArray from './getAsArray';
export default function useFetch({
@@ -43,9 +43,17 @@ export default function useFetch({
if (fromCache) {
setValue([fromCache, loadedIndicators]);
} else {
const res = await getCachedPromise(cacheKey, doLoad);
cacheSet(cacheKey, res, reloadTrigger);
setValue([res, loadedIndicators]);
try {
const res = await getCachedPromise(cacheKey, doLoad);
cacheSet(cacheKey, res, reloadTrigger);
setValue([res, loadedIndicators]);
} catch (err) {
console.error('Error when using cached promise', err);
cacheClean(cacheKey);
const res = await doLoad();
cacheSet(cacheKey, res, reloadTrigger);
setValue([res, loadedIndicators]);
}
}
} else {
const res = await doLoad();