mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 01:03:58 +00:00
refresh archive folder after import
This commit is contained in:
@@ -34,7 +34,9 @@ module.exports = {
|
|||||||
|
|
||||||
files_meta: 'get',
|
files_meta: 'get',
|
||||||
async files({ folder }) {
|
async files({ folder }) {
|
||||||
const files = await fs.readdir(path.join(archivedir(), folder));
|
const dir = path.join(archivedir(), folder);
|
||||||
|
if (!(await fs.exists(dir))) return [];
|
||||||
|
const files = await fs.readdir(dir);
|
||||||
return files
|
return files
|
||||||
.filter((name) => name.endsWith('.jsonl'))
|
.filter((name) => name.endsWith('.jsonl'))
|
||||||
.map((name) => ({
|
.map((name) => ({
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import ModalContent from './ModalContent';
|
|||||||
import ImportExportConfigurator from '../impexp/ImportExportConfigurator';
|
import ImportExportConfigurator from '../impexp/ImportExportConfigurator';
|
||||||
import createImpExpScript from '../impexp/createImpExpScript';
|
import createImpExpScript from '../impexp/createImpExpScript';
|
||||||
import { openNewTab } from '../utility/common';
|
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 RunnerOutputPane from '../query/RunnerOutputPane';
|
||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
import WidgetColumnBar, { WidgetColumnBarItem } from '../widgets/WidgetColumnBar';
|
import WidgetColumnBar, { WidgetColumnBarItem } from '../widgets/WidgetColumnBar';
|
||||||
@@ -119,11 +119,20 @@ export default function ImportExportModal({
|
|||||||
const [previewReader, setPreviewReader] = React.useState(0);
|
const [previewReader, setPreviewReader] = React.useState(0);
|
||||||
const targetArchiveFolder = importToArchive ? `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}` : archive;
|
const targetArchiveFolder = importToArchive ? `import-${moment().format('YYYY-MM-DD-hh-mm-ss')}` : archive;
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
|
const refreshArchiveFolderRef = React.useRef(null);
|
||||||
|
const setArchive = useSetCurrentArchive();
|
||||||
|
const setCurrentWidget = useSetCurrentWidget();
|
||||||
|
|
||||||
const [busy, setBusy] = React.useState(false);
|
const [busy, setBusy] = React.useState(false);
|
||||||
|
|
||||||
const handleRunnerDone = React.useCallback(() => {
|
const handleRunnerDone = React.useCallback(() => {
|
||||||
setBusy(false);
|
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(() => {
|
React.useEffect(() => {
|
||||||
@@ -146,6 +155,11 @@ export default function ImportExportModal({
|
|||||||
runid = resp.data.runid;
|
runid = resp.data.runid;
|
||||||
setRunnerId(runid);
|
setRunnerId(runid);
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
|
if (values.targetStorageType == 'archive') {
|
||||||
|
refreshArchiveFolderRef.current = values.targetArchiveFolder;
|
||||||
|
} else {
|
||||||
|
refreshArchiveFolderRef.current = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|||||||
import axios from './axios';
|
import axios from './axios';
|
||||||
import useSocket from './SocketProvider';
|
import useSocket from './SocketProvider';
|
||||||
import stableStringify from 'json-stable-stringify';
|
import stableStringify from 'json-stable-stringify';
|
||||||
import { getCachedPromise, cacheGet, cacheSet } from './cache';
|
import { getCachedPromise, cacheGet, cacheSet, cacheClean } from './cache';
|
||||||
import getAsArray from './getAsArray';
|
import getAsArray from './getAsArray';
|
||||||
|
|
||||||
export default function useFetch({
|
export default function useFetch({
|
||||||
@@ -43,9 +43,17 @@ export default function useFetch({
|
|||||||
if (fromCache) {
|
if (fromCache) {
|
||||||
setValue([fromCache, loadedIndicators]);
|
setValue([fromCache, loadedIndicators]);
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
const res = await getCachedPromise(cacheKey, doLoad);
|
const res = await getCachedPromise(cacheKey, doLoad);
|
||||||
cacheSet(cacheKey, res, reloadTrigger);
|
cacheSet(cacheKey, res, reloadTrigger);
|
||||||
setValue([res, loadedIndicators]);
|
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 {
|
} else {
|
||||||
const res = await doLoad();
|
const res = await doLoad();
|
||||||
|
|||||||
Reference in New Issue
Block a user