mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 18:16:00 +00:00
better loading free table data
This commit is contained in:
@@ -9,14 +9,33 @@ import FreeTableGrid from '../freetable/FreeTableGrid';
|
||||
import SaveArchiveModal from '../modals/SaveArchiveModal';
|
||||
import useModalState from '../modals/useModalState';
|
||||
import axios from '../utility/axios';
|
||||
import LoadingInfo from '../widgets/LoadingInfo';
|
||||
import { changeTab } from '../utility/common';
|
||||
import ErrorInfo from '../widgets/ErrorInfo';
|
||||
|
||||
export default function FreeDataTab({ archiveFolder, archiveFile, tabVisible, toolbarPortalRef, tabid, initialData }) {
|
||||
const [config, setConfig] = useGridConfig(tabid);
|
||||
const [modelState, dispatchModel] = useUndoReducer(initialData || createFreeTableModel());
|
||||
const [modelState, dispatchModel] = useUndoReducer(createFreeTableModel());
|
||||
const storageKey = `tabdata_freetable_${tabid}`;
|
||||
const saveSqlFileModalState = useModalState();
|
||||
const setOpenedTabs = useSetOpenedTabs();
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const [errorMessage, setErrorMessage] = React.useState(null);
|
||||
|
||||
const handleLoadInitialData = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const resp = await axios.post('runners/load-reader', initialData);
|
||||
// @ts-ignore
|
||||
dispatchModel({ type: 'reset', value: resp.data });
|
||||
setIsLoading(false);
|
||||
} catch (err) {
|
||||
setIsLoading(false);
|
||||
const errorMessage = (err && err.response && err.response.data && err.response.data.error) || 'Loading failed';
|
||||
setErrorMessage(errorMessage);
|
||||
console.error(err.response);
|
||||
}
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
const existingData = localStorage.getItem(storageKey);
|
||||
@@ -24,6 +43,8 @@ export default function FreeDataTab({ archiveFolder, archiveFile, tabVisible, to
|
||||
const value = JSON.parse(existingData);
|
||||
// @ts-ignore
|
||||
dispatchModel({ type: 'reset', value });
|
||||
} else if (initialData) {
|
||||
handleLoadInitialData();
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -40,6 +61,13 @@ export default function FreeDataTab({ archiveFolder, archiveFile, tabVisible, to
|
||||
}));
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingInfo wrapper message="Loading data" />;
|
||||
}
|
||||
if (errorMessage) {
|
||||
return <ErrorInfo message={errorMessage} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<FreeTableGrid
|
||||
|
||||
Reference in New Issue
Block a user