quick export - sql data grid

This commit is contained in:
Jan Prochazka 2021-06-06 17:26:50 +02:00
parent 7467dd2f10
commit af7c450f56
3 changed files with 61 additions and 25 deletions

View File

@ -48,7 +48,6 @@
divider: true,
},
electron && {
label: 'Quick export',
isQuickExport: true,
functionName: 'tableReader',
},
@ -116,7 +115,7 @@
},
electron && {
label: 'Quick export',
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
@ -177,7 +176,7 @@
},
electron && {
label: 'Quick export',
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
@ -277,7 +276,7 @@
},
electron && {
label: 'Quick export',
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
@ -348,6 +347,7 @@
import getConnectionLabel from '../utility/getConnectionLabel';
import getElectron from '../utility/getElectron';
import { exportElectronFile } from '../utility/exportElectronFile';
import createQuickExportMenu from '../utility/createQuickExportMenu';
export let data;
@ -397,29 +397,23 @@
if (menu.divider) return menu;
if (menu.isQuickExport) {
return {
text: menu.label,
submenu: $extensions.quickExports.map(fmt => ({
text: fmt.label,
onClick: async () => {
const coninfo = await getConnectionInfo(data);
exportElectronFile(
data.pureName,
{
functionName: menu.functionName,
props: {
connection: {
..._.omit(coninfo, ['_id', 'displayName']),
..._.pick(data, ['database']),
},
..._.pick(data, ['pureName', 'schemaName']),
},
return createQuickExportMenu($extensions, fmt => async () => {
const coninfo = await getConnectionInfo(data);
exportElectronFile(
data.pureName,
{
functionName: menu.functionName,
props: {
connection: {
..._.omit(coninfo, ['_id', 'displayName']),
..._.pick(data, ['database']),
},
fmt
);
..._.pick(data, ['pureName', 'schemaName']),
},
},
})),
};
fmt
);
});
}
return {

View File

@ -68,16 +68,23 @@
return parseInt(response.data.rows[0].count);
}
</script>
<script lang="ts">
import _ from 'lodash';
import registerCommand from '../commands/registerCommand';
import ImportExportModal from '../modals/ImportExportModal.svelte';
import { showModal } from '../modals/modalTools';
import { extensions } from '../stores';
import axiosInstance from '../utility/axiosInstance';
import { registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import createQuickExportMenu from '../utility/createQuickExportMenu';
import { exportElectronFile } from '../utility/exportElectronFile';
import { getConnectionInfo } from '../utility/metadataLoaders';
import openNewTab from '../utility/openNewTab';
import ChangeSetGrider from './ChangeSetGrider';
@ -169,8 +176,29 @@
registerMenu(
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
{
...createQuickExportMenu($extensions, fmt => async () => {
const coninfo = await getConnectionInfo({ conid });
exportElectronFile(
pureName || 'Data',
{
functionName: 'queryReader',
props: {
connection: {
..._.omit(coninfo, ['_id', 'displayName']),
database,
},
sql: display.getExportQuery(),
},
},
fmt
);
}),
tag: 'export',
},
{ command: 'sqlDataGrid.export', tag: 'export' }
);
</script>
<LoadingDataGridCore

View File

@ -0,0 +1,14 @@
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
export default function createQuickExportMenu(
extensions: ExtensionsDirectory,
handler: (fmt: QuickExportDefinition) => Function
) {
return {
text: 'Quick export',
submenu: extensions.quickExports.map(fmt => ({
text: fmt.label,
onClick: handler(fmt),
})),
};
}