mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 08:13:57 +00:00
export menu refactor
This commit is contained in:
@@ -169,7 +169,8 @@
|
|||||||
{ text: 'Delete', onClick: handleDelete },
|
{ text: 'Delete', onClick: handleDelete },
|
||||||
{ text: 'Rename', onClick: handleRename },
|
{ text: 'Rename', onClick: handleRename },
|
||||||
data.fileType == 'jsonl' &&
|
data.fileType == 'jsonl' &&
|
||||||
createQuickExportMenu(fmt => async () => {
|
createQuickExportMenu(
|
||||||
|
fmt => async () => {
|
||||||
exportQuickExportFile(
|
exportQuickExportFile(
|
||||||
data.fileName,
|
data.fileName,
|
||||||
{
|
{
|
||||||
@@ -181,8 +182,8 @@
|
|||||||
},
|
},
|
||||||
fmt
|
fmt
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
data.fileType == 'jsonl' && {
|
{
|
||||||
text: 'Export',
|
text: 'Export',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
showModal(ImportExportModal, {
|
showModal(ImportExportModal, {
|
||||||
@@ -193,7 +194,8 @@
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
),
|
||||||
data.fileType.endsWith('.sql') && { text: 'Open SQL', onClick: handleOpenSqlFile },
|
data.fileType.endsWith('.sql') && { text: 'Open SQL', onClick: handleOpenSqlFile },
|
||||||
data.fileType.endsWith('.yaml') && { text: 'Open YAML', onClick: handleOpenYamlFile },
|
data.fileType.endsWith('.yaml') && { text: 'Open YAML', onClick: handleOpenYamlFile },
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -60,12 +60,9 @@
|
|||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
isQuickExport: true,
|
|
||||||
functionName: 'tableReader',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Export',
|
label: 'Export',
|
||||||
|
functionName: 'tableReader',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -131,13 +128,10 @@
|
|||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
isQuickExport: true,
|
|
||||||
functionName: 'tableReader',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
|
functionName: 'tableReader',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Open as data sheet',
|
label: 'Open as data sheet',
|
||||||
@@ -196,13 +190,10 @@
|
|||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
isQuickExport: true,
|
|
||||||
functionName: 'tableReader',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
|
functionName: 'tableReader',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Open as data sheet',
|
label: 'Open as data sheet',
|
||||||
@@ -304,13 +295,10 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
isQuickExport: true,
|
|
||||||
functionName: 'tableReader',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
|
functionName: 'tableReader',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Drop collection',
|
label: 'Drop collection',
|
||||||
@@ -411,8 +399,9 @@
|
|||||||
.map(menu => {
|
.map(menu => {
|
||||||
if (menu.divider) return menu;
|
if (menu.divider) return menu;
|
||||||
|
|
||||||
if (menu.isQuickExport) {
|
if (menu.isExport) {
|
||||||
return createQuickExportMenu(fmt => async () => {
|
return createQuickExportMenu(
|
||||||
|
fmt => async () => {
|
||||||
const coninfo = await getConnectionInfo(data);
|
const coninfo = await getConnectionInfo(data);
|
||||||
exportQuickExportFile(
|
exportQuickExportFile(
|
||||||
data.pureName,
|
data.pureName,
|
||||||
@@ -428,13 +417,9 @@
|
|||||||
},
|
},
|
||||||
fmt
|
fmt
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
}
|
{
|
||||||
|
onClick: () => {
|
||||||
return {
|
|
||||||
text: menu.label,
|
|
||||||
onClick: async () => {
|
|
||||||
if (menu.isExport) {
|
|
||||||
showModal(ImportExportModal, {
|
showModal(ImportExportModal, {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
sourceStorageType: 'database',
|
sourceStorageType: 'database',
|
||||||
@@ -444,7 +429,15 @@
|
|||||||
sourceList: [data.pureName],
|
sourceList: [data.pureName],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (menu.isOpenFreeTable) {
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
text: menu.label,
|
||||||
|
onClick: async () => {
|
||||||
|
if (menu.isOpenFreeTable) {
|
||||||
const coninfo = await getConnectionInfo(data);
|
const coninfo = await getConnectionInfo(data);
|
||||||
openNewTab({
|
openNewTab({
|
||||||
title: data.pureName,
|
title: data.pureName,
|
||||||
|
|||||||
@@ -23,23 +23,21 @@
|
|||||||
import ToolStripCommandButton from './ToolStripCommandButton.svelte';
|
import ToolStripCommandButton from './ToolStripCommandButton.svelte';
|
||||||
import ToolStripDropDownButton from './ToolStripDropDownButton.svelte';
|
import ToolStripDropDownButton from './ToolStripDropDownButton.svelte';
|
||||||
|
|
||||||
const electron = getElectron();
|
|
||||||
|
|
||||||
export let quickExportHandlerRef = null;
|
export let quickExportHandlerRef = null;
|
||||||
export let command = 'sqlDataGrid.export';
|
export let command = 'sqlDataGrid.export';
|
||||||
export let label = 'Advanced settings';
|
export let label = 'Export';
|
||||||
|
|
||||||
function getExportMenu() {
|
function getExportMenu() {
|
||||||
return [
|
return [
|
||||||
quickExportHandlerRef?.value ? createQuickExportMenuItems(quickExportHandlerRef?.value) : null,
|
quickExportHandlerRef?.value
|
||||||
{ divider: true },
|
? createQuickExportMenuItems(quickExportHandlerRef?.value, { command })
|
||||||
{ command, text: label },
|
: { command },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if quickExportHandlerRef && electron}
|
{#if quickExportHandlerRef}
|
||||||
<ToolStripDropDownButton menu={getExportMenu} label="Export" icon="icon export" />
|
<ToolStripDropDownButton menu={getExportMenu} {label} icon="icon export" />
|
||||||
{:else}
|
{:else}
|
||||||
<ToolStripCommandButton {command} />
|
<ToolStripCommandButton {command} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -214,15 +214,10 @@
|
|||||||
|
|
||||||
registerQuickExportHandler(quickExportHandler);
|
registerQuickExportHandler(quickExportHandler);
|
||||||
|
|
||||||
registerMenu(
|
registerMenu({ command: 'collectionDataGrid.openQuery', tag: 'export' }, () => ({
|
||||||
{ command: 'collectionDataGrid.openQuery', tag: 'export' },
|
...createQuickExportMenu(quickExportHandler, { command: 'collectionDataGrid.export' }),
|
||||||
() => ({
|
|
||||||
...createQuickExportMenu(quickExportHandler),
|
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
}),
|
}));
|
||||||
|
|
||||||
{ command: 'collectionDataGrid.export', tag: 'export' }
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<LoadingDataGridCore
|
<LoadingDataGridCore
|
||||||
|
|||||||
@@ -130,13 +130,10 @@
|
|||||||
};
|
};
|
||||||
registerQuickExportHandler(quickExportHandler);
|
registerQuickExportHandler(quickExportHandler);
|
||||||
|
|
||||||
registerMenu(
|
registerMenu(() => ({
|
||||||
() => ({
|
...createQuickExportMenu(quickExportHandler, { command: 'jslTableGrid.export' }),
|
||||||
...createQuickExportMenu(quickExportHandler),
|
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
}),
|
}));
|
||||||
{ command: 'jslTableGrid.export', tag: 'export' }
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<LoadingDataGridCore
|
<LoadingDataGridCore
|
||||||
|
|||||||
@@ -202,10 +202,9 @@
|
|||||||
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
|
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
|
||||||
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
|
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
|
||||||
() => ({
|
() => ({
|
||||||
...createQuickExportMenu(quickExportHandler),
|
...createQuickExportMenu(quickExportHandler, { command: 'sqlDataGrid.export' }),
|
||||||
tag: 'export',
|
tag: 'export',
|
||||||
}),
|
})
|
||||||
{ command: 'sqlDataGrid.export', tag: 'export' }
|
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import { ExtensionsDirectory, QuickExportDefinition } from 'dbgate-types';
|
import { QuickExportDefinition } from 'dbgate-types';
|
||||||
import { getExtensions } from '../stores';
|
import { getExtensions } from '../stores';
|
||||||
import getElectron from './getElectron';
|
|
||||||
|
|
||||||
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function) {
|
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function, advancedExportMenuItem) {
|
||||||
// const electron = getElectron();
|
|
||||||
// if (!electron) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
const extensions = getExtensions();
|
const extensions = getExtensions();
|
||||||
console.log('extensions', extensions);
|
return [
|
||||||
return extensions.quickExports.map(fmt => ({
|
...extensions.quickExports.map(fmt => ({
|
||||||
text: fmt.label,
|
text: fmt.label,
|
||||||
onClick: handler(fmt),
|
onClick: handler(fmt),
|
||||||
}));
|
})),
|
||||||
|
{ divider: true },
|
||||||
|
{
|
||||||
|
text: 'More...',
|
||||||
|
...advancedExportMenuItem,
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function createQuickExportMenu(handler: (fmt: QuickExportDefinition) => Function) {
|
export default function createQuickExportMenu(
|
||||||
// const electron = getElectron();
|
handler: (fmt: QuickExportDefinition) => Function,
|
||||||
// if (!electron) {
|
advancedExportMenuItem
|
||||||
// return { _skip: true };
|
) {
|
||||||
// }
|
|
||||||
return {
|
return {
|
||||||
text: 'Quick export',
|
text: 'Export',
|
||||||
submenu: createQuickExportMenuItems(handler),
|
submenu: createQuickExportMenuItems(handler, advancedExportMenuItem),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user