mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 04:56:00 +00:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import type { QuickExportDefinition } from 'dbgate-types';
|
|
import { currentArchive, getCurrentArchive, getExtensions } from '../stores';
|
|
import hasPermission from './hasPermission';
|
|
|
|
export function createQuickExportMenuItems(handler: (fmt: QuickExportDefinition) => Function, advancedExportMenuItem) {
|
|
const extensions = getExtensions();
|
|
return [
|
|
{
|
|
text: 'Export advanced...',
|
|
...advancedExportMenuItem,
|
|
},
|
|
{ divider: true },
|
|
...extensions.quickExports.map(fmt => ({
|
|
text: fmt.label,
|
|
onClick: handler(fmt),
|
|
})),
|
|
{ divider: true },
|
|
{
|
|
text: 'Current archive',
|
|
onClick: handler({
|
|
extension: 'jsonl',
|
|
label: 'Current archive',
|
|
noFilenameDependency: true,
|
|
createWriter: (fileName, dataName) => ({
|
|
functionName: 'archiveWriter',
|
|
props: {
|
|
fileName: dataName,
|
|
folderName: getCurrentArchive(),
|
|
},
|
|
}),
|
|
}),
|
|
},
|
|
];
|
|
}
|
|
|
|
export default function createQuickExportMenu(
|
|
handler: (fmt: QuickExportDefinition) => Function,
|
|
advancedExportMenuItem,
|
|
additionalFields = {}
|
|
) {
|
|
if (!hasPermission('dbops/export')) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
text: 'Export',
|
|
submenu: createQuickExportMenuItems(handler, advancedExportMenuItem),
|
|
...additionalFields,
|
|
};
|
|
}
|