export menu refactor

This commit is contained in:
Jan Prochazka 2022-03-10 11:13:25 +01:00
parent ddff3d2b89
commit 35792a024a
7 changed files with 95 additions and 111 deletions

View File

@ -169,31 +169,33 @@
{ text: 'Delete', onClick: handleDelete },
{ text: 'Rename', onClick: handleRename },
data.fileType == 'jsonl' &&
createQuickExportMenu(fmt => async () => {
exportQuickExportFile(
data.fileName,
{
functionName: 'archiveReader',
props: {
fileName: data.fileName,
folderName: data.folderName,
createQuickExportMenu(
fmt => async () => {
exportQuickExportFile(
data.fileName,
{
functionName: 'archiveReader',
props: {
fileName: data.fileName,
folderName: data.folderName,
},
},
fmt
);
},
{
text: 'Export',
onClick: () => {
showModal(ImportExportModal, {
initialValues: {
sourceStorageType: 'archive',
sourceArchiveFolder: data.folderName,
sourceList: [data.fileName],
},
});
},
fmt
);
}),
data.fileType == 'jsonl' && {
text: 'Export',
onClick: () => {
showModal(ImportExportModal, {
initialValues: {
sourceStorageType: 'archive',
sourceArchiveFolder: data.folderName,
sourceList: [data.fileName],
},
});
},
},
}
),
data.fileType.endsWith('.sql') && { text: 'Open SQL', onClick: handleOpenSqlFile },
data.fileType.endsWith('.yaml') && { text: 'Open YAML', onClick: handleOpenYamlFile },
];

View File

@ -60,12 +60,9 @@
{
divider: true,
},
{
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
functionName: 'tableReader',
isExport: true,
},
{
@ -131,13 +128,10 @@
{
divider: true,
},
{
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
isExport: true,
functionName: 'tableReader',
},
{
label: 'Open as data sheet',
@ -196,13 +190,10 @@
{
divider: true,
},
{
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
isExport: true,
functionName: 'tableReader',
},
{
label: 'Open as data sheet',
@ -304,13 +295,10 @@
},
},
},
{
isQuickExport: true,
functionName: 'tableReader',
},
{
label: 'Export',
isExport: true,
functionName: 'tableReader',
},
{
label: 'Drop collection',
@ -411,40 +399,45 @@
.map(menu => {
if (menu.divider) return menu;
if (menu.isQuickExport) {
return createQuickExportMenu(fmt => async () => {
const coninfo = await getConnectionInfo(data);
exportQuickExportFile(
data.pureName,
{
functionName: menu.functionName,
props: {
connection: {
..._.omit(coninfo, ['_id', 'displayName']),
..._.pick(data, ['database']),
if (menu.isExport) {
return createQuickExportMenu(
fmt => async () => {
const coninfo = await getConnectionInfo(data);
exportQuickExportFile(
data.pureName,
{
functionName: menu.functionName,
props: {
connection: {
..._.omit(coninfo, ['_id', 'displayName']),
..._.pick(data, ['database']),
},
..._.pick(data, ['pureName', 'schemaName']),
},
..._.pick(data, ['pureName', 'schemaName']),
},
fmt
);
},
{
onClick: () => {
showModal(ImportExportModal, {
initialValues: {
sourceStorageType: 'database',
sourceConnectionId: data.conid,
sourceDatabaseName: data.database,
sourceSchemaName: data.schemaName,
sourceList: [data.pureName],
},
});
},
fmt
);
});
}
);
}
return {
text: menu.label,
onClick: async () => {
if (menu.isExport) {
showModal(ImportExportModal, {
initialValues: {
sourceStorageType: 'database',
sourceConnectionId: data.conid,
sourceDatabaseName: data.database,
sourceSchemaName: data.schemaName,
sourceList: [data.pureName],
},
});
} else if (menu.isOpenFreeTable) {
if (menu.isOpenFreeTable) {
const coninfo = await getConnectionInfo(data);
openNewTab({
title: data.pureName,

View File

@ -23,23 +23,21 @@
import ToolStripCommandButton from './ToolStripCommandButton.svelte';
import ToolStripDropDownButton from './ToolStripDropDownButton.svelte';
const electron = getElectron();
export let quickExportHandlerRef = null;
export let command = 'sqlDataGrid.export';
export let label = 'Advanced settings';
export let label = 'Export';
function getExportMenu() {
return [
quickExportHandlerRef?.value ? createQuickExportMenuItems(quickExportHandlerRef?.value) : null,
{ divider: true },
{ command, text: label },
quickExportHandlerRef?.value
? createQuickExportMenuItems(quickExportHandlerRef?.value, { command })
: { command },
];
}
</script>
{#if quickExportHandlerRef && electron}
<ToolStripDropDownButton menu={getExportMenu} label="Export" icon="icon export" />
{#if quickExportHandlerRef}
<ToolStripDropDownButton menu={getExportMenu} {label} icon="icon export" />
{:else}
<ToolStripCommandButton {command} />
{/if}

View File

@ -214,15 +214,10 @@
registerQuickExportHandler(quickExportHandler);
registerMenu(
{ command: 'collectionDataGrid.openQuery', tag: 'export' },
() => ({
...createQuickExportMenu(quickExportHandler),
tag: 'export',
}),
{ command: 'collectionDataGrid.export', tag: 'export' }
);
registerMenu({ command: 'collectionDataGrid.openQuery', tag: 'export' }, () => ({
...createQuickExportMenu(quickExportHandler, { command: 'collectionDataGrid.export' }),
tag: 'export',
}));
</script>
<LoadingDataGridCore

View File

@ -130,13 +130,10 @@
};
registerQuickExportHandler(quickExportHandler);
registerMenu(
() => ({
...createQuickExportMenu(quickExportHandler),
tag: 'export',
}),
{ command: 'jslTableGrid.export', tag: 'export' }
);
registerMenu(() => ({
...createQuickExportMenu(quickExportHandler, { command: 'jslTableGrid.export' }),
tag: 'export',
}));
</script>
<LoadingDataGridCore

View File

@ -202,10 +202,9 @@
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
() => ({
...createQuickExportMenu(quickExportHandler),
...createQuickExportMenu(quickExportHandler, { command: 'sqlDataGrid.export' }),
tag: 'export',
}),
{ command: 'sqlDataGrid.export', tag: 'export' }
})
);
</script>

View File

@ -1,27 +1,27 @@
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
import { QuickExportDefinition } from 'dbgate-types';
import { getExtensions } from '../stores';
import getElectron from './getElectron';
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function) {
// const electron = getElectron();
// if (!electron) {
// return null;
// }
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function, advancedExportMenuItem) {
const extensions = getExtensions();
console.log('extensions', extensions);
return extensions.quickExports.map(fmt => ({
text: fmt.label,
onClick: handler(fmt),
}));
return [
...extensions.quickExports.map(fmt => ({
text: fmt.label,
onClick: handler(fmt),
})),
{ divider: true },
{
text: 'More...',
...advancedExportMenuItem,
},
];
}
export default function createQuickExportMenu(handler: (fmt: QuickExportDefinition) => Function) {
// const electron = getElectron();
// if (!electron) {
// return { _skip: true };
// }
export default function createQuickExportMenu(
handler: (fmt: QuickExportDefinition) => Function,
advancedExportMenuItem
) {
return {
text: 'Quick export',
submenu: createQuickExportMenuItems(handler),
text: 'Export',
submenu: createQuickExportMenuItems(handler, advancedExportMenuItem),
};
}