Merge branch 'master' into redis

This commit is contained in:
Jan Prochazka 2022-03-10 11:22:39 +01:00
commit 98a9859216
19 changed files with 188 additions and 168 deletions

View File

@ -1,6 +1,6 @@
{
"private": true,
"version": "4.7.2",
"version": "4.7.3-beta.1",
"name": "dbgate-all",
"workspaces": [
"packages/*",

View File

@ -141,8 +141,8 @@ module.exports = {
},
generateUploadsFile_meta: true,
async generateUploadsFile() {
const fileName = `${uuidv1()}.html`;
async generateUploadsFile({ extension }) {
const fileName = `${uuidv1()}.${extension || 'html'}`;
return {
fileName,
filePath: path.join(uploadsdir(), fileName),

View File

@ -70,7 +70,7 @@
import { archiveFilesAsDataSheets, currentArchive, extensions, getCurrentDatabase } from '../stores';
import createQuickExportMenu from '../utility/createQuickExportMenu';
import { exportElectronFile } from '../utility/exportElectronFile';
import { exportQuickExportFile } from '../utility/exportFileTools';
import openNewTab from '../utility/openNewTab';
import AppObjectCore from './AppObjectCore.svelte';
import getConnectionLabel from '../utility/getConnectionLabel';
@ -169,31 +169,33 @@
{ text: 'Delete', onClick: handleDelete },
{ text: 'Rename', onClick: handleRename },
data.fileType == 'jsonl' &&
createQuickExportMenu($extensions, fmt => async () => {
exportElectronFile(
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

@ -1,6 +1,6 @@
<script lang="ts" context="module">
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
export const createMatcher = ({ pureName }) => filter => filterName(filter, pureName);
export const createMatcher = ({ schemaName, pureName }) => filter => filterName(filter, pureName, schemaName);
const electron = getElectron();
export const databaseObjectIcons = {
@ -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(getExtensions(), fmt => async () => {
const coninfo = await getConnectionInfo(data);
exportElectronFile(
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,
@ -620,7 +613,7 @@
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
import getConnectionLabel from '../utility/getConnectionLabel';
import getElectron from '../utility/getElectron';
import { exportElectronFile } from '../utility/exportElectronFile';
import { exportQuickExportFile } from '../utility/exportFileTools';
import createQuickExportMenu from '../utility/createQuickExportMenu';
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
import { alterDatabaseDialog, renameDatabaseObjectDialog } from '../utility/alterDatabaseTools';

View File

@ -1,6 +1,5 @@
<script lang="ts" context="module">
import { getContext, setContext } from 'svelte';
import { extensions } from '../stores';
import { createQuickExportMenuItems } from '../utility/createQuickExportMenu';
import createRef from '../utility/createRef';
@ -24,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($extensions, 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

@ -28,7 +28,7 @@
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import { saveFileToDisk } from '../utility/exportElectronFile';
import { saveFileToDisk } from '../utility/exportFileTools';
export let data;
export let title;

View File

@ -26,7 +26,7 @@ import { removeLocalStorage } from '../utility/storageCache';
import { showSnackbarSuccess } from '../utility/snackbar';
import { apiCall } from '../utility/api';
import runCommand from './runCommand';
import { openWebLink } from '../utility/exportElectronFile';
import { openWebLink } from '../utility/exportFileTools';
import { getSettings } from '../utility/metadataLoaders';
// function themeCommand(theme: ThemeDefinition) {

View File

@ -109,6 +109,7 @@
import { parseFilter } from 'dbgate-filterparser';
import { scriptToSql } from 'dbgate-sqltree';
import _ from 'lodash';
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
import registerCommand from '../commands/registerCommand';
import ErrorInfo from '../elements/ErrorInfo.svelte';
import ConfirmNoSqlModal from '../modals/ConfirmNoSqlModal.svelte';
@ -121,7 +122,7 @@
import { registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import createQuickExportMenu from '../utility/createQuickExportMenu';
import { exportElectronFile } from '../utility/exportElectronFile';
import { exportQuickExportFile } from '../utility/exportFileTools';
import { getConnectionInfo } from '../utility/metadataLoaders';
import openNewTab from '../utility/openNewTab';
import ChangeSetGrider from './ChangeSetGrider';
@ -193,31 +194,30 @@
);
}
registerMenu(
{ command: 'collectionDataGrid.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: getExportQuery(),
},
const quickExportHandler = fmt => async () => {
const coninfo = await getConnectionInfo({ conid });
exportQuickExportFile(
pureName || 'Data',
{
functionName: 'queryReader',
props: {
connection: {
..._.omit(coninfo, ['_id', 'displayName']),
database,
},
fmt
);
}),
tag: 'export',
},
sql: getExportQuery(),
},
},
fmt
);
};
{ command: 'collectionDataGrid.export', tag: 'export' }
);
registerQuickExportHandler(quickExportHandler);
registerMenu({ command: 'collectionDataGrid.openQuery', tag: 'export' }, () => ({
...createQuickExportMenu(quickExportHandler, { command: 'collectionDataGrid.export' }),
tag: 'export',
}));
</script>
<LoadingDataGridCore

View File

@ -48,7 +48,7 @@
import { registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import createQuickExportMenu from '../utility/createQuickExportMenu';
import { exportElectronFile } from '../utility/exportElectronFile';
import { exportQuickExportFile } from '../utility/exportFileTools';
import useEffect from '../utility/useEffect';
import LoadingDataGridCore from './LoadingDataGridCore.svelte';
@ -104,7 +104,7 @@
const quickExportHandler = fmt => async () => {
const archiveMatch = jslid.match(/^archive:\/\/([^/]+)\/(.*)$/);
if (archiveMatch) {
exportElectronFile(
exportQuickExportFile(
archiveMatch[2],
{
functionName: 'archiveReader',
@ -116,7 +116,7 @@
fmt
);
} else {
exportElectronFile(
exportQuickExportFile(
'Query',
{
functionName: 'jslDataReader',
@ -130,13 +130,10 @@
};
registerQuickExportHandler(quickExportHandler);
registerMenu(
{
...createQuickExportMenu($extensions, quickExportHandler),
tag: 'export',
},
{ command: 'jslTableGrid.export', tag: 'export' }
);
registerMenu(() => ({
...createQuickExportMenu(quickExportHandler, { command: 'jslTableGrid.export' }),
tag: 'export',
}));
</script>
<LoadingDataGridCore

View File

@ -66,18 +66,17 @@
<script lang="ts">
import _ from 'lodash';
import { getContext } from 'svelte';
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.svelte';
import registerCommand from '../commands/registerCommand';
import ImportExportModal from '../modals/ImportExportModal.svelte';
import { showModal } from '../modals/modalTools';
import { extensions } from '../stores';
import { apiCall } from '../utility/api';
import { registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import createQuickExportMenu from '../utility/createQuickExportMenu';
import { exportElectronFile } from '../utility/exportElectronFile';
import { exportQuickExportFile } from '../utility/exportFileTools';
import { getConnectionInfo } from '../utility/metadataLoaders';
import openNewTab from '../utility/openNewTab';
import ChangeSetGrider from './ChangeSetGrider';
@ -182,7 +181,7 @@ import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.sve
const quickExportHandler = fmt => async () => {
const coninfo = await getConnectionInfo({ conid });
exportElectronFile(
exportQuickExportFile(
pureName || 'Data',
{
functionName: 'queryReader',
@ -202,11 +201,10 @@ import { registerQuickExportHandler } from '../buttons/ToolStripExportButton.sve
registerMenu(
{ command: 'sqlDataGrid.openActiveChart', tag: 'chart' },
{ command: 'sqlDataGrid.openQuery', tag: 'export' },
{
...createQuickExportMenu($extensions, quickExportHandler),
() => ({
...createQuickExportMenu(quickExportHandler, { command: 'sqlDataGrid.export' }),
tag: 'export',
},
{ command: 'sqlDataGrid.export', tag: 'export' }
})
);
</script>

View File

@ -39,7 +39,7 @@
import registerCommand from '../commands/registerCommand';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import { GraphDefinition, GraphLayout } from './GraphLayout';
import { saveFileToDisk } from '../utility/exportElectronFile';
import { saveFileToDisk } from '../utility/exportFileTools';
import { apiCall } from '../utility/api';
import moveDrag from '../utility/moveDrag';
import { rectanglesHaveIntersection } from './designerMath';

View File

@ -1,5 +1,5 @@
<script lang="ts">
import { openWebLink } from '../utility/exportElectronFile';
import { openWebLink } from '../utility/exportFileTools';
export let href = undefined;
export let onClick = undefined;

View File

@ -9,7 +9,7 @@
import SelectField from '../forms/SelectField.svelte';
import _ from 'lodash';
import { useDatabaseInfo, useTableInfo } from '../utility/metadataLoaders';
import { onMount } from 'svelte';
import { onMount, tick } from 'svelte';
import TargetApplicationSelect from '../forms/TargetApplicationSelect.svelte';
import { apiCall } from '../utility/api';
import { saveDbToApp } from '../utility/appTools';
@ -34,6 +34,19 @@
// ..._.sortBy($dbInfo?.views || [], ['schemaName', 'pureName']),
];
let tableOptions = [];
$: (async () => {
// without this has svelte problem, doesn't invalidate SelectField options
await tick();
// to replicate try to invoke VFK editor after page refresh, when active widget without DB, eg. application layers
// and comment line above. Tables list in vFK editor will be empty
tableOptions = tableList.map(tbl => ({
label: fullNameToLabel(tbl),
value: fullNameToString(tbl),
}));
})();
$: refTableInfo = tableList.find(x => x.pureName == refTableName && x.schemaName == refSchemaName);
// $dbInfo?.views?.find(x => x.pureName == refTableName && x.schemaName == refSchemaName);
@ -50,6 +63,8 @@
// $: console.log('conid, database', conid, database);
// $: console.log('$dbInfo?.tables', $dbInfo?.tables);
// $: console.log('tableList', tableList);
// $: console.log('tableOptions', tableOptions);
</script>
<FormProvider>
@ -64,15 +79,23 @@
value={fullNameToString({ pureName: refTableName, schemaName: refSchemaName })}
isNative
notSelected
options={tableList.map(tbl => ({
label: fullNameToLabel(tbl),
value: fullNameToString(tbl),
}))}
options={tableOptions}
on:change={e => {
if (e.detail) {
const name = fullNameFromString(e.detail);
refTableName = name.pureName;
refSchemaName = name.schemaName;
if (columns?.length == 1) {
const table = $dbInfo?.tables?.find(x => x.pureName == refTableName && x.schemaName == refSchemaName);
if (table?.primaryKey?.columns?.length == 1) {
columns = [
{
...columns[0],
refColumnName: table.primaryKey.columns[0].columnName,
},
];
}
}
}
}}
/>

View File

@ -158,7 +158,7 @@
import { changeTab } from '../utility/common';
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import { saveFileToDisk } from '../utility/exportElectronFile';
import { saveFileToDisk } from '../utility/exportFileTools';
import { useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
import resolveApi from '../utility/resolveApi';
import { showSnackbarSuccess } from '../utility/snackbar';

View File

@ -50,14 +50,11 @@
import { showSnackbarSuccess } from '../utility/snackbar';
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
import openNewTab from '../utility/openNewTab';
import { getBoolSettingsValue } from '../settings/settingsTools';
import { setContext } from 'svelte';
import { apiCall } from '../utility/api';
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
import ToolStripDropDownButton from '../buttons/ToolStripDropDownButton.svelte';
import { createQuickExportMenuItems } from '../utility/createQuickExportMenu';
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
export let tabid;

View File

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

View File

@ -4,16 +4,23 @@ import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from
import resolveApi from './resolveApi';
import { apiCall, apiOff, apiOn } from './api';
export async function exportElectronFile(dataName, reader, format) {
export async function exportQuickExportFile(dataName, reader, format) {
const electron = getElectron();
const filters = [{ name: format.label, extensions: [format.extension] }];
const filePath = await electron.showSaveDialog({
filters,
defaultPath: `${dataName}.${format.extension}`,
properties: ['showOverwriteConfirmation'],
});
if (!filePath) return;
let filePath;
let pureFileName;
if (electron) {
const filters = [{ name: format.label, extensions: [format.extension] }];
filePath = electron.showSaveDialog({
filters,
defaultPath: `${dataName}.${format.extension}`,
properties: ['showOverwriteConfirmation'],
});
} else {
const resp = await apiCall('files/generate-uploads-file', { extension: format.extension });
filePath = resp.filePath;
pureFileName = resp.fileName;
}
const script = new ScriptWriter();
@ -50,6 +57,10 @@ export async function exportElectronFile(dataName, reader, format) {
apiOff(`runner-done-${runid}`, handleRunnerDone);
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
else showSnackbarInfo(`Export ${dataName} finished`);
if (!electron) {
window.open(`${resolveApi()}/uploads/get?file=${pureFileName}`, '_blank');
}
}
apiOn(`runner-done-${runid}`, handleRunnerDone);

View File

@ -387,7 +387,7 @@
draggingDbGroupTarget = null;
}}
>
<FontIcon icon={getDbIcon(tabGroup.tabDbKey)} />
<FontIcon icon={getDbIcon(tabGroup.tabDbKey)} padRight />
{tabGroup.tabDbName}
<span
@ -493,6 +493,7 @@
align-items: stretch;
}
.db-name {
display: flex;
text-align: center;
font-size: 8pt;
border-bottom: 1px solid var(--theme-border);
@ -501,10 +502,10 @@
user-select: none;
padding: 1px;
position: relative;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
justify-content: center;
}
/* .db-name:hover {
background-color: var(--theme-bg-3);

View File

@ -47,6 +47,10 @@ class StringifyStream extends stream.Transform {
}
_transform(chunk, encoding, done) {
if (chunk.__isStreamHeader) {
done();
return;
}
this.startElement(this.itemElementName);
this.push('\n');
for (const key of Object.keys(chunk)) {