mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 19:53:57 +00:00
extensions refactor
This commit is contained in:
@@ -28,18 +28,18 @@ function App() {
|
|||||||
<OpenedConnectionsProvider>
|
<OpenedConnectionsProvider>
|
||||||
<LeftPanelWidthProvider>
|
<LeftPanelWidthProvider>
|
||||||
<ConnectionsPinger>
|
<ConnectionsPinger>
|
||||||
<ModalLayerProvider>
|
<PluginsProvider>
|
||||||
<CurrentArchiveProvider>
|
<ModalLayerProvider>
|
||||||
<CurrentThemeProvider>
|
<CurrentArchiveProvider>
|
||||||
<UploadsProvider>
|
<CurrentThemeProvider>
|
||||||
<PluginsProvider>
|
<UploadsProvider>
|
||||||
<ThemeHelmet />
|
<ThemeHelmet />
|
||||||
</PluginsProvider>
|
<Screen />
|
||||||
<Screen />
|
</UploadsProvider>
|
||||||
</UploadsProvider>
|
</CurrentThemeProvider>
|
||||||
</CurrentThemeProvider>
|
</CurrentArchiveProvider>
|
||||||
</CurrentArchiveProvider>
|
</ModalLayerProvider>
|
||||||
</ModalLayerProvider>
|
</PluginsProvider>
|
||||||
</ConnectionsPinger>
|
</ConnectionsPinger>
|
||||||
</LeftPanelWidthProvider>
|
</LeftPanelWidthProvider>
|
||||||
</OpenedConnectionsProvider>
|
</OpenedConnectionsProvider>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { fileformats } from './fileformats';
|
|
||||||
import { FontIcon } from './icons';
|
import { FontIcon } from './icons';
|
||||||
import useTheme from './theme/useTheme';
|
import useTheme from './theme/useTheme';
|
||||||
|
import useExtensions from './utility/useExtensions';
|
||||||
|
|
||||||
const TargetStyled = styled.div`
|
const TargetStyled = styled.div`
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -40,6 +40,7 @@ const TitleWrapper = styled.div`
|
|||||||
|
|
||||||
export default function DragAndDropFileTarget({ isDragActive, inputProps }) {
|
export default function DragAndDropFileTarget({ isDragActive, inputProps }) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { fileFormats } = useExtensions();
|
||||||
return (
|
return (
|
||||||
!!isDragActive && (
|
!!isDragActive && (
|
||||||
<TargetStyled theme={theme}>
|
<TargetStyled theme={theme}>
|
||||||
@@ -50,7 +51,7 @@ export default function DragAndDropFileTarget({ isDragActive, inputProps }) {
|
|||||||
<TitleWrapper>Drop the files to upload to DbGate</TitleWrapper>
|
<TitleWrapper>Drop the files to upload to DbGate</TitleWrapper>
|
||||||
<InfoWrapper>
|
<InfoWrapper>
|
||||||
Supported file types:{' '}
|
Supported file types:{' '}
|
||||||
{fileformats
|
{fileFormats
|
||||||
.filter((x) => x.readerFunc)
|
.filter((x) => x.readerFunc)
|
||||||
.map((x) => x.name)
|
.map((x) => x.name)
|
||||||
.join(', ')}
|
.join(', ')}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import _ from 'lodash';
|
|||||||
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
||||||
import { openNewTab } from '../utility/common';
|
import { openNewTab } from '../utility/common';
|
||||||
import ImportExportModal from '../modals/ImportExportModal';
|
import ImportExportModal from '../modals/ImportExportModal';
|
||||||
import { defaultFileFormat } from '../fileformats';
|
import { getDefaultFileFormat } from '../utility/fileformats';
|
||||||
|
|
||||||
function Menu({ data, setOpenedTabs, showModal }) {
|
function Menu({ data, setOpenedTabs, showModal, extensions }) {
|
||||||
const { connection, name } = data;
|
const { connection, name } = data;
|
||||||
const tooltip = `${connection.displayName || connection.server}\n${name}`;
|
const tooltip = `${connection.displayName || connection.server}\n${name}`;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ function Menu({ data, setOpenedTabs, showModal }) {
|
|||||||
<ImportExportModal
|
<ImportExportModal
|
||||||
modalState={modalState}
|
modalState={modalState}
|
||||||
initialValues={{
|
initialValues={{
|
||||||
sourceStorageType: defaultFileFormat.storageType,
|
sourceStorageType: getDefaultFileFormat(extensions).storageType,
|
||||||
targetStorageType: 'database',
|
targetStorageType: 'database',
|
||||||
targetConnectionId: data.connection._id,
|
targetConnectionId: data.connection._id,
|
||||||
targetDatabaseName: data.name,
|
targetDatabaseName: data.name,
|
||||||
@@ -41,7 +41,7 @@ function Menu({ data, setOpenedTabs, showModal }) {
|
|||||||
<ImportExportModal
|
<ImportExportModal
|
||||||
modalState={modalState}
|
modalState={modalState}
|
||||||
initialValues={{
|
initialValues={{
|
||||||
targetStorageType: defaultFileFormat.storageType,
|
targetStorageType: getDefaultFileFormat(extensions).storageType,
|
||||||
sourceStorageType: 'database',
|
sourceStorageType: 'database',
|
||||||
sourceConnectionId: data.connection._id,
|
sourceConnectionId: data.connection._id,
|
||||||
sourceDatabaseName: data.name,
|
sourceDatabaseName: data.name,
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
import { FileFormatDefinition } from './types';
|
|
||||||
|
|
||||||
const csvFormat: FileFormatDefinition = {
|
|
||||||
storageType: 'csv',
|
|
||||||
extension: 'csv',
|
|
||||||
name: 'CSV',
|
|
||||||
readerFunc: 'csvReader',
|
|
||||||
writerFunc: 'csvWriter',
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
type: 'select',
|
|
||||||
name: 'delimiter',
|
|
||||||
label: 'Delimiter',
|
|
||||||
options: [
|
|
||||||
{ name: 'Comma (,)', value: ',' },
|
|
||||||
{ name: 'Semicolon (;)', value: ';' },
|
|
||||||
{ name: 'Tab', value: '\t' },
|
|
||||||
{ name: 'Pipe (|)', value: '|' },
|
|
||||||
],
|
|
||||||
apiName: 'delimiter',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'checkbox',
|
|
||||||
name: 'quoted',
|
|
||||||
label: 'Quoted',
|
|
||||||
apiName: 'quoted',
|
|
||||||
direction: 'target',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'checkbox',
|
|
||||||
name: 'header',
|
|
||||||
label: 'Has header row',
|
|
||||||
apiName: 'header',
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export default csvFormat;
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
import axios from '../utility/axios';
|
|
||||||
import { FileFormatDefinition } from './types';
|
|
||||||
|
|
||||||
const excelFormat: FileFormatDefinition = {
|
|
||||||
storageType: 'excel',
|
|
||||||
extension: 'xlsx',
|
|
||||||
name: 'MS Excel',
|
|
||||||
readerFunc: 'excelSheetReader',
|
|
||||||
writerFunc: 'excelSheetWriter',
|
|
||||||
|
|
||||||
addFilesToSourceList: async (file, newSources, newValues) => {
|
|
||||||
const resp = await axios.get(`files/analyse-excel?filePath=${encodeURIComponent(file.full)}`);
|
|
||||||
const sheetNames = resp.data;
|
|
||||||
for (const sheetName of sheetNames) {
|
|
||||||
newSources.push(sheetName);
|
|
||||||
newValues[`sourceFile_${sheetName}`] = {
|
|
||||||
fileName: file.full,
|
|
||||||
sheetName,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
type: 'checkbox',
|
|
||||||
name: 'singleFile',
|
|
||||||
label: 'Create single file',
|
|
||||||
direction: 'target',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
|
|
||||||
getDefaultOutputName: (sourceName, values) => {
|
|
||||||
if (values.target_excel_singleFile) {
|
|
||||||
return sourceName;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
|
|
||||||
getOutputParams: (sourceName, values) => {
|
|
||||||
if (values.target_excel_singleFile) {
|
|
||||||
return {
|
|
||||||
sheetName: values[`targetName_${sourceName}`] || sourceName,
|
|
||||||
fileName:'data.xlsx'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default excelFormat;
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import csv from './csv';
|
|
||||||
import jsonl from './jsonl';
|
|
||||||
import excel from './excel';
|
|
||||||
import { FileFormatDefinition } from './types';
|
|
||||||
|
|
||||||
export const fileformats = [csv, jsonl, excel];
|
|
||||||
|
|
||||||
export function findFileFormat(storageType): FileFormatDefinition {
|
|
||||||
return fileformats.find((x) => x.storageType == storageType);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getFileFormatDirections(format: FileFormatDefinition) {
|
|
||||||
if (!format) return [];
|
|
||||||
const res = [];
|
|
||||||
if (format.readerFunc) res.push('source');
|
|
||||||
if (format.writerFunc) res.push('target');
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const defaultFileFormat = csv;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { FileFormatDefinition } from './types';
|
|
||||||
|
|
||||||
const jsonlFormat: FileFormatDefinition = {
|
|
||||||
storageType: 'jsonl',
|
|
||||||
extension: 'jsonl',
|
|
||||||
name: 'JSON lines',
|
|
||||||
readerFunc: 'jsonLinesReader',
|
|
||||||
writerFunc: 'jsonLinesWriter',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default jsonlFormat;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
export interface FileFormatDefinition {
|
|
||||||
storageType: string;
|
|
||||||
extension: string;
|
|
||||||
name: string;
|
|
||||||
readerFunc?: string;
|
|
||||||
writerFunc?: string;
|
|
||||||
args?: any[];
|
|
||||||
addFilesToSourceList?: (
|
|
||||||
file: {
|
|
||||||
full: string;
|
|
||||||
},
|
|
||||||
newSources: string[],
|
|
||||||
newValues: {
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
) => void;
|
|
||||||
getDefaultOutputName?: (sourceName, values) => string;
|
|
||||||
getOutputParams?: (sourceName, values) => any;
|
|
||||||
}
|
|
||||||
@@ -12,10 +12,10 @@ import {
|
|||||||
FormArchiveFolderSelect,
|
FormArchiveFolderSelect,
|
||||||
FormArchiveFilesSelect,
|
FormArchiveFilesSelect,
|
||||||
} from '../utility/forms';
|
} from '../utility/forms';
|
||||||
import { useArchiveFiles, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
import { useArchiveFiles, useConnectionInfo, useDatabaseInfo, useInstalledPlugins } from '../utility/metadataLoaders';
|
||||||
import TableControl, { TableColumn } from '../utility/TableControl';
|
import TableControl, { TableColumn } from '../utility/TableControl';
|
||||||
import { TextField, SelectField, CheckboxField } from '../utility/inputs';
|
import { TextField, SelectField, CheckboxField } from '../utility/inputs';
|
||||||
import { createPreviewReader, getActionOptions, getTargetName, isFileStorage } from './createImpExpScript';
|
import { createPreviewReader, getActionOptions, getTargetName } from './createImpExpScript';
|
||||||
import getElectron from '../utility/getElectron';
|
import getElectron from '../utility/getElectron';
|
||||||
import ErrorInfo from '../widgets/ErrorInfo';
|
import ErrorInfo from '../widgets/ErrorInfo';
|
||||||
import getAsArray from '../utility/getAsArray';
|
import getAsArray from '../utility/getAsArray';
|
||||||
@@ -25,8 +25,9 @@ import SqlEditor from '../sqleditor/SqlEditor';
|
|||||||
import { useUploadsProvider } from '../utility/UploadsProvider';
|
import { useUploadsProvider } from '../utility/UploadsProvider';
|
||||||
import { FontIcon } from '../icons';
|
import { FontIcon } from '../icons';
|
||||||
import useTheme from '../theme/useTheme';
|
import useTheme from '../theme/useTheme';
|
||||||
import { fileformats, findFileFormat, getFileFormatDirections } from '../fileformats';
|
import { findFileFormat, getFileFormatDirections } from '../utility/fileformats';
|
||||||
import FormArgumentList from '../utility/FormArgumentList';
|
import FormArgumentList from '../utility/FormArgumentList';
|
||||||
|
import useExtensions from '../utility/useExtensions';
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
// max-height: 50vh;
|
// max-height: 50vh;
|
||||||
@@ -89,9 +90,9 @@ const Title = styled.div`
|
|||||||
margin: 10px 0px;
|
margin: 10px 0px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function getFileFilters(storageType) {
|
function getFileFilters(extensions, storageType) {
|
||||||
const res = [];
|
const res = [];
|
||||||
const format = findFileFormat(storageType);
|
const format = findFileFormat(extensions, storageType);
|
||||||
if (format) res.push({ name: format.name, extensions: [format.extension] });
|
if (format) res.push({ name: format.name, extensions: [format.extension] });
|
||||||
res.push({ name: 'All Files', extensions: ['*'] });
|
res.push({ name: 'All Files', extensions: ['*'] });
|
||||||
return res;
|
return res;
|
||||||
@@ -105,12 +106,12 @@ async function addFilesToSourceListDefault(file, newSources, newValues) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addFilesToSourceList(files, values, setValues, preferedStorageType, setPreviewSource) {
|
async function addFilesToSourceList(extensions, files, values, setValues, preferedStorageType, setPreviewSource) {
|
||||||
const newSources = [];
|
const newSources = [];
|
||||||
const newValues = {};
|
const newValues = {};
|
||||||
const storage = preferedStorageType || values.sourceStorageType;
|
const storage = preferedStorageType || values.sourceStorageType;
|
||||||
for (const file of getAsArray(files)) {
|
for (const file of getAsArray(files)) {
|
||||||
const format = findFileFormat(storage);
|
const format = findFileFormat(extensions, storage);
|
||||||
if (format) {
|
if (format) {
|
||||||
await (format.addFilesToSourceList || addFilesToSourceListDefault)(file, newSources, newValues);
|
await (format.addFilesToSourceList || addFilesToSourceListDefault)(file, newSources, newValues);
|
||||||
}
|
}
|
||||||
@@ -132,17 +133,19 @@ function ElectronFilesInput() {
|
|||||||
const { values, setValues } = useFormikContext();
|
const { values, setValues } = useFormikContext();
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
const [isLoading, setIsLoading] = React.useState(false);
|
const [isLoading, setIsLoading] = React.useState(false);
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
const handleClick = async () => {
|
const handleClick = async () => {
|
||||||
const files = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
|
const files = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
|
||||||
properties: ['openFile', 'multiSelections'],
|
properties: ['openFile', 'multiSelections'],
|
||||||
filters: getFileFilters(values.sourceStorageType),
|
filters: getFileFilters(extensions, values.sourceStorageType),
|
||||||
});
|
});
|
||||||
if (files) {
|
if (files) {
|
||||||
const path = window.require('path');
|
const path = window.require('path');
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await addFilesToSourceList(
|
await addFilesToSourceList(
|
||||||
|
extensions,
|
||||||
files.map((full) => ({
|
files.map((full) => ({
|
||||||
full,
|
full,
|
||||||
...path.parse(full),
|
...path.parse(full),
|
||||||
@@ -183,6 +186,7 @@ function SourceTargetConfig({
|
|||||||
tablesField = undefined,
|
tablesField = undefined,
|
||||||
engine = undefined,
|
engine = undefined,
|
||||||
}) {
|
}) {
|
||||||
|
const extensions = useExtensions();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { values, setFieldValue } = useFormikContext();
|
const { values, setFieldValue } = useFormikContext();
|
||||||
const types =
|
const types =
|
||||||
@@ -190,7 +194,7 @@ function SourceTargetConfig({
|
|||||||
? [{ value: 'jsldata', label: 'Query result data', directions: ['source'] }]
|
? [{ value: 'jsldata', label: 'Query result data', directions: ['source'] }]
|
||||||
: [
|
: [
|
||||||
{ value: 'database', label: 'Database', directions: ['source', 'target'] },
|
{ value: 'database', label: 'Database', directions: ['source', 'target'] },
|
||||||
...fileformats.map((format) => ({
|
...extensions.fileFormats.map((format) => ({
|
||||||
value: format.storageType,
|
value: format.storageType,
|
||||||
label: `${format.name} files(s)`,
|
label: `${format.name} files(s)`,
|
||||||
directions: getFileFormatDirections(format),
|
directions: getFileFormatDirections(format),
|
||||||
@@ -201,7 +205,7 @@ function SourceTargetConfig({
|
|||||||
const storageType = values[storageTypeField];
|
const storageType = values[storageTypeField];
|
||||||
const dbinfo = useDatabaseInfo({ conid: values[connectionIdField], database: values[databaseNameField] });
|
const dbinfo = useDatabaseInfo({ conid: values[connectionIdField], database: values[databaseNameField] });
|
||||||
const archiveFiles = useArchiveFiles({ folder: values[archiveFolderField] });
|
const archiveFiles = useArchiveFiles({ folder: values[archiveFolderField] });
|
||||||
const format = findFileFormat(storageType);
|
const format = findFileFormat(extensions, storageType);
|
||||||
return (
|
return (
|
||||||
<Column>
|
<Column>
|
||||||
{direction == 'source' && (
|
{direction == 'source' && (
|
||||||
@@ -348,10 +352,17 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC
|
|||||||
const { setUploadListener } = useUploadsProvider();
|
const { setUploadListener } = useUploadsProvider();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [previewSource, setPreviewSource] = React.useState(null);
|
const [previewSource, setPreviewSource] = React.useState(null);
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
|
console.log('ImportExportConfigurator', extensions);
|
||||||
|
const installed = useInstalledPlugins();
|
||||||
|
console.log('installed', installed);
|
||||||
|
|
||||||
const handleUpload = React.useCallback(
|
const handleUpload = React.useCallback(
|
||||||
(file) => {
|
(file) => {
|
||||||
|
console.log('UPLOAD', extensions);
|
||||||
addFilesToSourceList(
|
addFilesToSourceList(
|
||||||
|
extensions,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
full: file.filePath,
|
full: file.filePath,
|
||||||
@@ -365,7 +376,7 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC
|
|||||||
);
|
);
|
||||||
// setFieldValue('sourceList', [...(sourceList || []), file.originalName]);
|
// setFieldValue('sourceList', [...(sourceList || []), file.originalName]);
|
||||||
},
|
},
|
||||||
[setFieldValue, sourceList, values]
|
[extensions, setFieldValue, sourceList, values]
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -381,11 +392,11 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const supportsPreview = !!findFileFormat(values.sourceStorageType);
|
const supportsPreview = !!findFileFormat(extensions, values.sourceStorageType);
|
||||||
|
|
||||||
const handleChangePreviewSource = async () => {
|
const handleChangePreviewSource = async () => {
|
||||||
if (previewSource && supportsPreview) {
|
if (previewSource && supportsPreview) {
|
||||||
const reader = await createPreviewReader(values, previewSource);
|
const reader = await createPreviewReader(extensions, values, previewSource);
|
||||||
if (onChangePreview) onChangePreview(reader);
|
if (onChangePreview) onChangePreview(reader);
|
||||||
} else {
|
} else {
|
||||||
onChangePreview(null);
|
onChangePreview(null);
|
||||||
@@ -444,8 +455,8 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC
|
|||||||
header="Action"
|
header="Action"
|
||||||
formatter={(row) => (
|
formatter={(row) => (
|
||||||
<SelectField
|
<SelectField
|
||||||
options={getActionOptions(row, values, targetDbinfo)}
|
options={getActionOptions(extensions, row, values, targetDbinfo)}
|
||||||
value={values[`actionType_${row}`] || getActionOptions(row, values, targetDbinfo)[0].value}
|
value={values[`actionType_${row}`] || getActionOptions(extensions, row, values, targetDbinfo)[0].value}
|
||||||
onChange={(e) => setFieldValue(`actionType_${row}`, e.target.value)}
|
onChange={(e) => setFieldValue(`actionType_${row}`, e.target.value)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -455,7 +466,7 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC
|
|||||||
header="Target"
|
header="Target"
|
||||||
formatter={(row) => (
|
formatter={(row) => (
|
||||||
<TextField
|
<TextField
|
||||||
value={getTargetName(row, values)}
|
value={getTargetName(extensions, row, values)}
|
||||||
onChange={(e) => setFieldValue(`targetName_${row}`, e.target.value)}
|
onChange={(e) => setFieldValue(`targetName_${row}`, e.target.value)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import getAsArray from '../utility/getAsArray';
|
|||||||
import { getConnectionInfo } from '../utility/metadataLoaders';
|
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import engines from 'dbgate-engines';
|
import engines from 'dbgate-engines';
|
||||||
import { findObjectLike } from 'dbgate-tools';
|
import { findObjectLike } from 'dbgate-tools';
|
||||||
import { findFileFormat } from '../fileformats';
|
import { findFileFormat } from '../utility/fileformats';
|
||||||
|
|
||||||
export function getTargetName(source, values) {
|
export function getTargetName(extensions, source, values) {
|
||||||
const key = `targetName_${source}`;
|
const key = `targetName_${source}`;
|
||||||
if (values[key]) return values[key];
|
if (values[key]) return values[key];
|
||||||
const format = findFileFormat(values.targetStorageType);
|
const format = findFileFormat(extensions, values.targetStorageType);
|
||||||
if (format) {
|
if (format) {
|
||||||
const res = format.getDefaultOutputName ? format.getDefaultOutputName(source, values) : null;
|
const res = format.getDefaultOutputName ? format.getDefaultOutputName(source, values) : null;
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
@@ -18,10 +18,6 @@ export function getTargetName(source, values) {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isFileStorage(storageType) {
|
|
||||||
return !!findFileFormat(storageType);
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractApiParameters(values, direction, format) {
|
function extractApiParameters(values, direction, format) {
|
||||||
const pairs = (format.args || [])
|
const pairs = (format.args || [])
|
||||||
.filter((arg) => arg.apiName)
|
.filter((arg) => arg.apiName)
|
||||||
@@ -45,7 +41,7 @@ async function getConnection(storageType, conid, database) {
|
|||||||
return [null, null];
|
return [null, null];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSourceExpr(sourceName, values, sourceConnection, sourceDriver) {
|
function getSourceExpr(extensions, sourceName, values, sourceConnection, sourceDriver) {
|
||||||
const { sourceStorageType } = values;
|
const { sourceStorageType } = values;
|
||||||
if (sourceStorageType == 'database') {
|
if (sourceStorageType == 'database') {
|
||||||
const fullName = { schemaName: values.sourceSchemaName, pureName: sourceName };
|
const fullName = { schemaName: values.sourceSchemaName, pureName: sourceName };
|
||||||
@@ -66,9 +62,9 @@ function getSourceExpr(sourceName, values, sourceConnection, sourceDriver) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (isFileStorage(sourceStorageType)) {
|
if (findFileFormat(extensions, sourceStorageType)) {
|
||||||
const sourceFile = values[`sourceFile_${sourceName}`];
|
const sourceFile = values[`sourceFile_${sourceName}`];
|
||||||
const format = findFileFormat(sourceStorageType);
|
const format = findFileFormat(extensions, sourceStorageType);
|
||||||
if (format && format.readerFunc) {
|
if (format && format.readerFunc) {
|
||||||
return [
|
return [
|
||||||
format.readerFunc,
|
format.readerFunc,
|
||||||
@@ -113,9 +109,9 @@ function getFlagsFroAction(action) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTargetExpr(sourceName, values, targetConnection, targetDriver) {
|
function getTargetExpr(extensions, sourceName, values, targetConnection, targetDriver) {
|
||||||
const { targetStorageType } = values;
|
const { targetStorageType } = values;
|
||||||
const format = findFileFormat(targetStorageType);
|
const format = findFileFormat(extensions, targetStorageType);
|
||||||
if (format && format.writerFunc) {
|
if (format && format.writerFunc) {
|
||||||
const outputParams = format.getOutputParams && format.getOutputParams(sourceName, values);
|
const outputParams = format.getOutputParams && format.getOutputParams(sourceName, values);
|
||||||
return [
|
return [
|
||||||
@@ -124,7 +120,7 @@ function getTargetExpr(sourceName, values, targetConnection, targetDriver) {
|
|||||||
...(outputParams
|
...(outputParams
|
||||||
? outputParams
|
? outputParams
|
||||||
: {
|
: {
|
||||||
fileName: getTargetName(sourceName, values),
|
fileName: getTargetName(extensions, sourceName, values),
|
||||||
}),
|
}),
|
||||||
...extractApiParameters(values, 'target', format),
|
...extractApiParameters(values, 'target', format),
|
||||||
},
|
},
|
||||||
@@ -136,7 +132,7 @@ function getTargetExpr(sourceName, values, targetConnection, targetDriver) {
|
|||||||
{
|
{
|
||||||
connection: targetConnection,
|
connection: targetConnection,
|
||||||
schemaName: values.targetSchemaName,
|
schemaName: values.targetSchemaName,
|
||||||
pureName: getTargetName(sourceName, values),
|
pureName: getTargetName(extensions, sourceName, values),
|
||||||
...getFlagsFroAction(values[`actionType_${sourceName}`]),
|
...getFlagsFroAction(values[`actionType_${sourceName}`]),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -146,7 +142,7 @@ function getTargetExpr(sourceName, values, targetConnection, targetDriver) {
|
|||||||
'archiveWriter',
|
'archiveWriter',
|
||||||
{
|
{
|
||||||
folderName: values.targetArchiveFolder,
|
folderName: values.targetArchiveFolder,
|
||||||
fileName: getTargetName(sourceName, values),
|
fileName: getTargetName(extensions, sourceName, values),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -154,7 +150,7 @@ function getTargetExpr(sourceName, values, targetConnection, targetDriver) {
|
|||||||
throw new Error(`Unknown target storage type: ${targetStorageType}`);
|
throw new Error(`Unknown target storage type: ${targetStorageType}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function createImpExpScript(values, addEditorInfo = true) {
|
export default async function createImpExpScript(extensions, values, addEditorInfo = true) {
|
||||||
const script = new ScriptWriter();
|
const script = new ScriptWriter();
|
||||||
|
|
||||||
const [sourceConnection, sourceDriver] = await getConnection(
|
const [sourceConnection, sourceDriver] = await getConnection(
|
||||||
@@ -172,11 +168,11 @@ export default async function createImpExpScript(values, addEditorInfo = true) {
|
|||||||
for (const sourceName of sourceList) {
|
for (const sourceName of sourceList) {
|
||||||
const sourceVar = script.allocVariable();
|
const sourceVar = script.allocVariable();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
script.assign(sourceVar, ...getSourceExpr(sourceName, values, sourceConnection, sourceDriver));
|
script.assign(sourceVar, ...getSourceExpr(extensions, sourceName, values, sourceConnection, sourceDriver));
|
||||||
|
|
||||||
const targetVar = script.allocVariable();
|
const targetVar = script.allocVariable();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
script.assign(targetVar, ...getTargetExpr(sourceName, values, targetConnection, targetDriver));
|
script.assign(targetVar, ...getTargetExpr(extensions, sourceName, values, targetConnection, targetDriver));
|
||||||
|
|
||||||
script.copyStream(sourceVar, targetVar);
|
script.copyStream(sourceVar, targetVar);
|
||||||
script.put();
|
script.put();
|
||||||
@@ -188,9 +184,9 @@ export default async function createImpExpScript(values, addEditorInfo = true) {
|
|||||||
return script.s;
|
return script.s;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getActionOptions(source, values, targetDbinfo) {
|
export function getActionOptions(extensions, source, values, targetDbinfo) {
|
||||||
const res = [];
|
const res = [];
|
||||||
const targetName = getTargetName(source, values);
|
const targetName = getTargetName(extensions, source, values);
|
||||||
if (values.targetStorageType == 'database') {
|
if (values.targetStorageType == 'database') {
|
||||||
let existing = findObjectLike(
|
let existing = findObjectLike(
|
||||||
{ schemaName: values.targetSchemaName, pureName: targetName },
|
{ schemaName: values.targetSchemaName, pureName: targetName },
|
||||||
@@ -225,13 +221,13 @@ export function getActionOptions(source, values, targetDbinfo) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createPreviewReader(values, sourceName) {
|
export async function createPreviewReader(extensions, values, sourceName) {
|
||||||
const [sourceConnection, sourceDriver] = await getConnection(
|
const [sourceConnection, sourceDriver] = await getConnection(
|
||||||
values.sourceStorageType,
|
values.sourceStorageType,
|
||||||
values.sourceConnectionId,
|
values.sourceConnectionId,
|
||||||
values.sourceDatabaseName
|
values.sourceDatabaseName
|
||||||
);
|
);
|
||||||
const [functionName, props] = getSourceExpr(sourceName, values, sourceConnection, sourceDriver);
|
const [functionName, props] = getSourceExpr(extensions, sourceName, values, sourceConnection, sourceDriver);
|
||||||
return {
|
return {
|
||||||
functionName,
|
functionName,
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ import useSocket from '../utility/SocketProvider';
|
|||||||
import LoadingInfo from '../widgets/LoadingInfo';
|
import LoadingInfo from '../widgets/LoadingInfo';
|
||||||
import { FontIcon } from '../icons';
|
import { FontIcon } from '../icons';
|
||||||
import LargeButton from '../widgets/LargeButton';
|
import LargeButton from '../widgets/LargeButton';
|
||||||
import { defaultFileFormat } from '../fileformats';
|
import { getDefaultFileFormat } from '../utility/fileformats';
|
||||||
|
import useExtensions from '../utility/useExtensions';
|
||||||
|
|
||||||
const headerHeight = '60px';
|
const headerHeight = '60px';
|
||||||
const footerHeight = '100px';
|
const footerHeight = '100px';
|
||||||
@@ -92,9 +93,10 @@ const FooterButtons = styled.div`
|
|||||||
function GenerateSctriptButton({ modalState }) {
|
function GenerateSctriptButton({ modalState }) {
|
||||||
const setOpenedTabs = useSetOpenedTabs();
|
const setOpenedTabs = useSetOpenedTabs();
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
const handleGenerateScript = async () => {
|
const handleGenerateScript = async () => {
|
||||||
const code = await createImpExpScript(values);
|
const code = await createImpExpScript(extensions, values);
|
||||||
openNewTab(setOpenedTabs, {
|
openNewTab(setOpenedTabs, {
|
||||||
title: 'Shell',
|
title: 'Shell',
|
||||||
icon: 'img shell',
|
icon: 'img shell',
|
||||||
@@ -141,6 +143,7 @@ export default function ImportExportModal({
|
|||||||
const refreshArchiveFolderRef = React.useRef(null);
|
const refreshArchiveFolderRef = React.useRef(null);
|
||||||
const setArchive = useSetCurrentArchive();
|
const setArchive = useSetCurrentArchive();
|
||||||
const setCurrentWidget = useSetCurrentWidget();
|
const setCurrentWidget = useSetCurrentWidget();
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
const [busy, setBusy] = React.useState(false);
|
const [busy, setBusy] = React.useState(false);
|
||||||
|
|
||||||
@@ -165,9 +168,9 @@ export default function ImportExportModal({
|
|||||||
|
|
||||||
const handleExecute = async (values) => {
|
const handleExecute = async (values) => {
|
||||||
if (busy) return;
|
if (busy) return;
|
||||||
|
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
const script = await createImpExpScript(values);
|
const script = await createImpExpScript(extensions, values);
|
||||||
|
|
||||||
setExecuteNumber((num) => num + 1);
|
setExecuteNumber((num) => num + 1);
|
||||||
|
|
||||||
@@ -194,7 +197,7 @@ export default function ImportExportModal({
|
|||||||
onSubmit={handleExecute}
|
onSubmit={handleExecute}
|
||||||
initialValues={{
|
initialValues={{
|
||||||
sourceStorageType: 'database',
|
sourceStorageType: 'database',
|
||||||
targetStorageType: importToArchive ? 'archive' : defaultFileFormat.storageType,
|
targetStorageType: importToArchive ? 'archive' : getDefaultFileFormat(extensions).storageType,
|
||||||
sourceArchiveFolder: archive,
|
sourceArchiveFolder: archive,
|
||||||
targetArchiveFolder,
|
targetArchiveFolder,
|
||||||
...initialValues,
|
...initialValues,
|
||||||
|
|||||||
@@ -9,12 +9,7 @@ export default function PluginsProvider({ children }) {
|
|||||||
const installedPlugins = useInstalledPlugins();
|
const installedPlugins = useInstalledPlugins();
|
||||||
const [plugins, setPlugins] = React.useState({});
|
const [plugins, setPlugins] = React.useState({});
|
||||||
const handleLoadPlugins = async () => {
|
const handleLoadPlugins = async () => {
|
||||||
setPlugins((x) =>
|
const newPlugins = {};
|
||||||
_.pick(
|
|
||||||
x,
|
|
||||||
installedPlugins.map((y) => y.name)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
for (const installed of installedPlugins) {
|
for (const installed of installedPlugins) {
|
||||||
if (!_.keys(plugins).includes(installed.name)) {
|
if (!_.keys(plugins).includes(installed.name)) {
|
||||||
console.log('Loading module', installed.name);
|
console.log('Loading module', installed.name);
|
||||||
@@ -26,12 +21,16 @@ export default function PluginsProvider({ children }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const module = eval(resp.data);
|
const module = eval(resp.data);
|
||||||
setPlugins((v) => ({
|
console.log('Loaded plugin', module);
|
||||||
...v,
|
newPlugins[installed.name] = module.__esModule ? module.default : module;
|
||||||
[installed.name]: module,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setPlugins((x) =>
|
||||||
|
_.pick(
|
||||||
|
{ ...x, ...newPlugins },
|
||||||
|
installedPlugins.map((y) => y.name)
|
||||||
|
)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
handleLoadPlugins();
|
handleLoadPlugins();
|
||||||
@@ -42,11 +41,16 @@ export default function PluginsProvider({ children }) {
|
|||||||
export function usePlugins() {
|
export function usePlugins() {
|
||||||
const installed = useInstalledPlugins();
|
const installed = useInstalledPlugins();
|
||||||
const loaded = React.useContext(PluginsContext);
|
const loaded = React.useContext(PluginsContext);
|
||||||
return installed
|
|
||||||
.map((manifest) => ({
|
return React.useMemo(
|
||||||
packageName: manifest.name,
|
() =>
|
||||||
manifest,
|
installed
|
||||||
content: loaded[manifest.name],
|
.map((manifest) => ({
|
||||||
}))
|
packageName: manifest.name,
|
||||||
.filter((x) => x.content);
|
manifest,
|
||||||
|
content: loaded[manifest.name],
|
||||||
|
}))
|
||||||
|
.filter((x) => x.content),
|
||||||
|
[installed, loaded]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useDropzone } from 'react-dropzone';
|
import { useDropzone } from 'react-dropzone';
|
||||||
import { findFileFormat } from '../fileformats';
|
|
||||||
import ImportExportModal from '../modals/ImportExportModal';
|
import ImportExportModal from '../modals/ImportExportModal';
|
||||||
import useShowModal from '../modals/showModal';
|
import useShowModal from '../modals/showModal';
|
||||||
|
import { findFileFormat } from './fileformats';
|
||||||
import resolveApi from './resolveApi';
|
import resolveApi from './resolveApi';
|
||||||
|
import useExtensions from './useExtensions';
|
||||||
|
|
||||||
const UploadsContext = React.createContext(null);
|
const UploadsContext = React.createContext(null);
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ export function useUploadsProvider() {
|
|||||||
export function useUploadsZone() {
|
export function useUploadsZone() {
|
||||||
const { uploadListener } = useUploadsProvider();
|
const { uploadListener } = useUploadsProvider();
|
||||||
const showModal = useShowModal();
|
const showModal = useShowModal();
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
const onDrop = React.useCallback(
|
const onDrop = React.useCallback(
|
||||||
(files) => {
|
(files) => {
|
||||||
@@ -43,7 +45,7 @@ export function useUploadsZone() {
|
|||||||
if (uploadListener) {
|
if (uploadListener) {
|
||||||
uploadListener(fileData);
|
uploadListener(fileData);
|
||||||
} else {
|
} else {
|
||||||
if (findFileFormat(fileData.storageType)) {
|
if (findFileFormat(extensions, fileData.storageType)) {
|
||||||
showModal((modalState) => (
|
showModal((modalState) => (
|
||||||
<ImportExportModal
|
<ImportExportModal
|
||||||
uploadedFile={fileData}
|
uploadedFile={fileData}
|
||||||
@@ -73,7 +75,7 @@ export function useUploadsZone() {
|
|||||||
// reader.readAsArrayBuffer(file);
|
// reader.readAsArrayBuffer(file);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[uploadListener]
|
[uploadListener, extensions]
|
||||||
);
|
);
|
||||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,82 @@
|
|||||||
import { usePlugins } from '../plugins/PluginsProvider';
|
import { usePlugins } from '../plugins/PluginsProvider';
|
||||||
|
import axios from './axios';
|
||||||
|
import { FormSchemaSelect } from './forms';
|
||||||
|
|
||||||
export function useFileFormats() {
|
const excelFormat = {
|
||||||
const plugins = usePlugins();
|
storageType: 'excel',
|
||||||
return [];
|
extension: 'xlsx',
|
||||||
|
name: 'MS Excel',
|
||||||
|
readerFunc: 'excelSheetReader',
|
||||||
|
writerFunc: 'excelSheetWriter',
|
||||||
|
|
||||||
|
addFilesToSourceList: async (file, newSources, newValues) => {
|
||||||
|
const resp = await axios.get(`files/analyse-excel?filePath=${encodeURIComponent(file.full)}`);
|
||||||
|
const sheetNames = resp.data;
|
||||||
|
for (const sheetName of sheetNames) {
|
||||||
|
newSources.push(sheetName);
|
||||||
|
newValues[`sourceFile_${sheetName}`] = {
|
||||||
|
fileName: file.full,
|
||||||
|
sheetName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
name: 'singleFile',
|
||||||
|
label: 'Create single file',
|
||||||
|
direction: 'target',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
getDefaultOutputName: (sourceName, values) => {
|
||||||
|
if (values.target_excel_singleFile) {
|
||||||
|
return sourceName;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
getOutputParams: (sourceName, values) => {
|
||||||
|
if (values.target_excel_singleFile) {
|
||||||
|
return {
|
||||||
|
sheetName: values[`targetName_${sourceName}`] || sourceName,
|
||||||
|
fileName: 'data.xlsx',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const jsonlFormat = {
|
||||||
|
storageType: 'jsonl',
|
||||||
|
extension: 'jsonl',
|
||||||
|
name: 'JSON lines',
|
||||||
|
readerFunc: 'jsonLinesReader',
|
||||||
|
writerFunc: 'jsonLinesWriter',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function buildFileFormats(plugins) {
|
||||||
|
const res = [excelFormat, jsonlFormat];
|
||||||
|
for (const { content } of plugins) {
|
||||||
|
const { fileFormats } = content;
|
||||||
|
if (fileFormats) res.push(...fileFormats);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findFileFormat(extensions, storageType) {
|
||||||
|
return extensions.fileFormats.find((x) => x.storageType == storageType);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFileFormatDirections(format) {
|
||||||
|
if (!format) return [];
|
||||||
|
const res = [];
|
||||||
|
if (format.readerFunc) res.push('source');
|
||||||
|
if (format.writerFunc) res.push('target');
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultFileFormat(extensions) {
|
||||||
|
return extensions.fileFormats.find((x) => x.storageType == 'csv') || jsonlFormat;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useConnectionInfo, useConfig } from './metadataLoaders';
|
|||||||
import usePrevious from './usePrevious';
|
import usePrevious from './usePrevious';
|
||||||
import useNewQuery from '../query/useNewQuery';
|
import useNewQuery from '../query/useNewQuery';
|
||||||
import useShowModal from '../modals/showModal';
|
import useShowModal from '../modals/showModal';
|
||||||
|
import useExtensions from './useExtensions';
|
||||||
|
|
||||||
function createGlobalState(defaultValue) {
|
function createGlobalState(defaultValue) {
|
||||||
const Context = React.createContext(null);
|
const Context = React.createContext(null);
|
||||||
@@ -90,6 +91,7 @@ export function useAppObjectParams() {
|
|||||||
const currentArchive = useCurrentArchive();
|
const currentArchive = useCurrentArchive();
|
||||||
const showModal = useShowModal();
|
const showModal = useShowModal();
|
||||||
const config = useConfig();
|
const config = useConfig();
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setOpenedTabs,
|
setOpenedTabs,
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ const connectionListLoader = () => ({
|
|||||||
reloadTrigger: `connection-list-changed`,
|
reloadTrigger: `connection-list-changed`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const insttalledPluginsLoader = () => ({
|
const installedPluginsLoader = () => ({
|
||||||
url: 'plugins/installed',
|
url: 'plugins/installed',
|
||||||
params: {},
|
params: {},
|
||||||
reloadTrigger: `installed-plugins-changed`,
|
reloadTrigger: `installed-plugins-changed`,
|
||||||
@@ -251,8 +251,8 @@ export function useArchiveFolders(args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getInstalledPlugins(args) {
|
export function getInstalledPlugins(args) {
|
||||||
return getCore(insttalledPluginsLoader, args) || [];
|
return getCore(installedPluginsLoader, args) || [];
|
||||||
}
|
}
|
||||||
export function useInstalledPlugins(args) {
|
export function useInstalledPlugins(args) {
|
||||||
return useCore(insttalledPluginsLoader, args) || [];
|
return useCore(installedPluginsLoader, args) || [];
|
||||||
}
|
}
|
||||||
|
|||||||
15
packages/web/src/utility/useExtensions.js
Normal file
15
packages/web/src/utility/useExtensions.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { usePlugins } from '../plugins/PluginsProvider';
|
||||||
|
import { buildFileFormats } from './fileformats';
|
||||||
|
|
||||||
|
export default function useExtensions() {
|
||||||
|
const plugins = usePlugins();
|
||||||
|
const extensions = React.useMemo(
|
||||||
|
() => ({
|
||||||
|
plugins,
|
||||||
|
fileFormats: buildFileFormats(plugins),
|
||||||
|
}),
|
||||||
|
[plugins]
|
||||||
|
);
|
||||||
|
return extensions;
|
||||||
|
}
|
||||||
@@ -10,7 +10,8 @@ import { openNewTab } from '../utility/common';
|
|||||||
import useNewFreeTable from '../freetable/useNewFreeTable';
|
import useNewFreeTable from '../freetable/useNewFreeTable';
|
||||||
import ImportExportModal from '../modals/ImportExportModal';
|
import ImportExportModal from '../modals/ImportExportModal';
|
||||||
import useShowModal from '../modals/showModal';
|
import useShowModal from '../modals/showModal';
|
||||||
import { defaultFileFormat } from '../fileformats';
|
import useExtensions from '../utility/useExtensions';
|
||||||
|
import { getDefaultFileFormat } from '../utility/fileformats';
|
||||||
|
|
||||||
const ToolbarContainer = styled.div`
|
const ToolbarContainer = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -28,6 +29,7 @@ export default function ToolBar({ toolbarPortalRef }) {
|
|||||||
const showModal = useShowModal();
|
const showModal = useShowModal();
|
||||||
const currentTheme = useCurrentTheme();
|
const currentTheme = useCurrentTheme();
|
||||||
const setCurrentTheme = useSetCurrentTheme();
|
const setCurrentTheme = useSetCurrentTheme();
|
||||||
|
const extensions = useExtensions();
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
window['dbgate_createNewConnection'] = modalState.open;
|
window['dbgate_createNewConnection'] = modalState.open;
|
||||||
@@ -41,7 +43,7 @@ export default function ToolBar({ toolbarPortalRef }) {
|
|||||||
modalState={modalState}
|
modalState={modalState}
|
||||||
importToArchive
|
importToArchive
|
||||||
initialValues={{
|
initialValues={{
|
||||||
sourceStorageType: defaultFileFormat.storageType,
|
sourceStorageType: getDefaultFileFormat(extensions).storageType,
|
||||||
// sourceConnectionId: data.conid,
|
// sourceConnectionId: data.conid,
|
||||||
// sourceDatabaseName: data.database,
|
// sourceDatabaseName: data.database,
|
||||||
// sourceSchemaName: data.schemaName,
|
// sourceSchemaName: data.schemaName,
|
||||||
|
|||||||
Reference in New Issue
Block a user