mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 05:03:57 +00:00
configurable object actions #255
This commit is contained in:
@@ -340,74 +340,7 @@
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function openDatabaseObjectDetail(
|
async function databaseObjectMenuClickHandler(data, menu) {
|
||||||
tabComponent,
|
|
||||||
scriptTemplate,
|
|
||||||
{ schemaName, pureName, conid, database, objectTypeField },
|
|
||||||
forceNewTab?,
|
|
||||||
initialData?,
|
|
||||||
icon?,
|
|
||||||
appObjectData?
|
|
||||||
) {
|
|
||||||
const connection = await getConnectionInfo({ conid });
|
|
||||||
const tooltip = `${getConnectionLabel(connection)}\n${database}\n${fullDisplayName({
|
|
||||||
schemaName,
|
|
||||||
pureName,
|
|
||||||
})}`;
|
|
||||||
|
|
||||||
openNewTab(
|
|
||||||
{
|
|
||||||
title: scriptTemplate ? 'Query #' : pureName,
|
|
||||||
tooltip,
|
|
||||||
icon: icon || (scriptTemplate ? 'img sql-file' : databaseObjectIcons[objectTypeField]),
|
|
||||||
tabComponent: scriptTemplate ? 'QueryTab' : tabComponent,
|
|
||||||
appObject: 'DatabaseObjectAppObject',
|
|
||||||
appObjectData,
|
|
||||||
props: {
|
|
||||||
schemaName,
|
|
||||||
pureName,
|
|
||||||
conid,
|
|
||||||
database,
|
|
||||||
objectTypeField,
|
|
||||||
initialArgs: scriptTemplate ? { scriptTemplate } : null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
initialData,
|
|
||||||
{ forceNewTab }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function handleDatabaseObjectClick(data, forceNewTab = false) {
|
|
||||||
const { schemaName, pureName, conid, database, objectTypeField } = data;
|
|
||||||
|
|
||||||
openDatabaseObjectDetail(
|
|
||||||
defaultTabs[objectTypeField],
|
|
||||||
defaultTabs[objectTypeField] ? null : 'CREATE OBJECT',
|
|
||||||
{
|
|
||||||
schemaName,
|
|
||||||
pureName,
|
|
||||||
conid,
|
|
||||||
database,
|
|
||||||
objectTypeField,
|
|
||||||
},
|
|
||||||
forceNewTab,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEqual(a, b) {
|
|
||||||
return (
|
|
||||||
a.conid == b.conid &&
|
|
||||||
a.database == b.database &&
|
|
||||||
a.objectTypeField == b.objectTypeField &&
|
|
||||||
a.pureName == b.pureName &&
|
|
||||||
a.schemaName == b.schemaName
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createDatabaseObjectMenu(data) {
|
|
||||||
const getDriver = async () => {
|
const getDriver = async () => {
|
||||||
const conn = await getConnectionInfo(data);
|
const conn = await getConnectionInfo(data);
|
||||||
if (!conn) return;
|
if (!conn) return;
|
||||||
@@ -415,47 +348,6 @@
|
|||||||
return driver;
|
return driver;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { objectTypeField } = data;
|
|
||||||
return menus[objectTypeField]
|
|
||||||
.filter(x => x)
|
|
||||||
.map(menu => {
|
|
||||||
if (menu.divider) return menu;
|
|
||||||
|
|
||||||
if (menu.isExport) {
|
|
||||||
return createQuickExportMenu(
|
|
||||||
fmt => async () => {
|
|
||||||
const coninfo = await getConnectionInfo(data);
|
|
||||||
exportQuickExportFile(
|
|
||||||
data.pureName,
|
|
||||||
{
|
|
||||||
functionName: menu.functionName,
|
|
||||||
props: {
|
|
||||||
connection: extractShellConnection(coninfo, data.database),
|
|
||||||
..._.pick(data, ['pureName', 'schemaName']),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
fmt
|
|
||||||
);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onClick: () => {
|
|
||||||
showModal(ImportExportModal, {
|
|
||||||
initialValues: {
|
|
||||||
sourceStorageType: 'database',
|
|
||||||
sourceConnectionId: data.conid,
|
|
||||||
sourceDatabaseName: data.database,
|
|
||||||
sourceSchemaName: data.schemaName,
|
|
||||||
sourceList: [data.pureName],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
text: menu.label,
|
|
||||||
onClick: async () => {
|
|
||||||
if (menu.isOpenFreeTable) {
|
if (menu.isOpenFreeTable) {
|
||||||
const coninfo = await getConnectionInfo(data);
|
const coninfo = await getConnectionInfo(data);
|
||||||
openNewTab({
|
openNewTab({
|
||||||
@@ -564,9 +456,7 @@
|
|||||||
} else if (menu.isRename) {
|
} else if (menu.isRename) {
|
||||||
const { conid, database } = data;
|
const { conid, database } = data;
|
||||||
renameDatabaseObjectDialog(conid, database, data.pureName, (db, newName) => {
|
renameDatabaseObjectDialog(conid, database, data.pureName, (db, newName) => {
|
||||||
const obj = db[data.objectTypeField].find(
|
const obj = db[data.objectTypeField].find(x => x.schemaName == data.schemaName && x.pureName == data.pureName);
|
||||||
x => x.schemaName == data.schemaName && x.pureName == data.pureName
|
|
||||||
);
|
|
||||||
obj.pureName = newName;
|
obj.pureName = newName;
|
||||||
});
|
});
|
||||||
} else if (menu.isDropCollection) {
|
} else if (menu.isDropCollection) {
|
||||||
@@ -652,6 +542,125 @@
|
|||||||
data
|
data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function openDatabaseObjectDetail(
|
||||||
|
tabComponent,
|
||||||
|
scriptTemplate,
|
||||||
|
{ schemaName, pureName, conid, database, objectTypeField },
|
||||||
|
forceNewTab?,
|
||||||
|
initialData?,
|
||||||
|
icon?,
|
||||||
|
appObjectData?
|
||||||
|
) {
|
||||||
|
const connection = await getConnectionInfo({ conid });
|
||||||
|
const tooltip = `${getConnectionLabel(connection)}\n${database}\n${fullDisplayName({
|
||||||
|
schemaName,
|
||||||
|
pureName,
|
||||||
|
})}`;
|
||||||
|
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: scriptTemplate ? 'Query #' : pureName,
|
||||||
|
tooltip,
|
||||||
|
icon: icon || (scriptTemplate ? 'img sql-file' : databaseObjectIcons[objectTypeField]),
|
||||||
|
tabComponent: scriptTemplate ? 'QueryTab' : tabComponent,
|
||||||
|
appObject: 'DatabaseObjectAppObject',
|
||||||
|
appObjectData,
|
||||||
|
props: {
|
||||||
|
schemaName,
|
||||||
|
pureName,
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
objectTypeField,
|
||||||
|
initialArgs: scriptTemplate ? { scriptTemplate } : null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
initialData,
|
||||||
|
{ forceNewTab }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleDatabaseObjectClick(data, forceNewTab = false) {
|
||||||
|
const { schemaName, pureName, conid, database, objectTypeField } = data;
|
||||||
|
|
||||||
|
const configuredAction = getCurrentSettings()[`defaultAction.dbObjectClick.${objectTypeField}`];
|
||||||
|
const overrideMenu = menus[objectTypeField].find(x => x.label && x.label == configuredAction);
|
||||||
|
if (overrideMenu) {
|
||||||
|
databaseObjectMenuClickHandler(data, overrideMenu);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openDatabaseObjectDetail(
|
||||||
|
defaultTabs[objectTypeField],
|
||||||
|
defaultTabs[objectTypeField] ? null : 'CREATE OBJECT',
|
||||||
|
{
|
||||||
|
schemaName,
|
||||||
|
pureName,
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
objectTypeField,
|
||||||
|
},
|
||||||
|
forceNewTab,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testEqual(a, b) {
|
||||||
|
return (
|
||||||
|
a.conid == b.conid &&
|
||||||
|
a.database == b.database &&
|
||||||
|
a.objectTypeField == b.objectTypeField &&
|
||||||
|
a.pureName == b.pureName &&
|
||||||
|
a.schemaName == b.schemaName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createDatabaseObjectMenu(data) {
|
||||||
|
const { objectTypeField } = data;
|
||||||
|
return menus[objectTypeField]
|
||||||
|
.filter(x => x)
|
||||||
|
.map(menu => {
|
||||||
|
if (menu.divider) return menu;
|
||||||
|
|
||||||
|
if (menu.isExport) {
|
||||||
|
return createQuickExportMenu(
|
||||||
|
fmt => async () => {
|
||||||
|
const coninfo = await getConnectionInfo(data);
|
||||||
|
exportQuickExportFile(
|
||||||
|
data.pureName,
|
||||||
|
{
|
||||||
|
functionName: menu.functionName,
|
||||||
|
props: {
|
||||||
|
connection: extractShellConnection(coninfo, data.database),
|
||||||
|
..._.pick(data, ['pureName', 'schemaName']),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fmt
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onClick: () => {
|
||||||
|
showModal(ImportExportModal, {
|
||||||
|
initialValues: {
|
||||||
|
sourceStorageType: 'database',
|
||||||
|
sourceConnectionId: data.conid,
|
||||||
|
sourceDatabaseName: data.database,
|
||||||
|
sourceSchemaName: data.schemaName,
|
||||||
|
sourceList: [data.pureName],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
text: menu.label,
|
||||||
|
onClick: () => {
|
||||||
|
databaseObjectMenuClickHandler(data, menu);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -671,7 +680,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import AppObjectCore from './AppObjectCore.svelte';
|
import AppObjectCore from './AppObjectCore.svelte';
|
||||||
import { currentDatabase, extensions, getExtensions, openedConnections, pinnedTables } from '../stores';
|
import {
|
||||||
|
currentDatabase,
|
||||||
|
extensions,
|
||||||
|
getCurrentSettings,
|
||||||
|
getExtensions,
|
||||||
|
openedConnections,
|
||||||
|
pinnedTables,
|
||||||
|
} from '../stores';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import { filterName, generateDbPairingId, getAlterDatabaseScript } from 'dbgate-tools';
|
import { filterName, generateDbPairingId, getAlterDatabaseScript } from 'dbgate-tools';
|
||||||
import { getConnectionInfo, getDatabaseInfo } from '../utility/metadataLoaders';
|
import { getConnectionInfo, getDatabaseInfo } from '../utility/metadataLoaders';
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ ORDER BY
|
|||||||
tabs={[
|
tabs={[
|
||||||
{ label: 'General', slot: 1 },
|
{ label: 'General', slot: 1 },
|
||||||
{ label: 'Themes', slot: 2 },
|
{ label: 'Themes', slot: 2 },
|
||||||
|
{ label: 'Actions', slot: 3 },
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="1">
|
<svelte:fragment slot="1">
|
||||||
@@ -102,18 +103,6 @@ ORDER BY
|
|||||||
defaultValue="30"
|
defaultValue="30"
|
||||||
disabled={values['connection.autoRefresh'] === false}
|
disabled={values['connection.autoRefresh'] === false}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="heading">Default actions</div>
|
|
||||||
<FormSelectField
|
|
||||||
label="Connection click"
|
|
||||||
name="defaultAction.connectionClick"
|
|
||||||
isNative
|
|
||||||
defaultValue='openDetails'
|
|
||||||
options={[
|
|
||||||
{ value: 'openDetails', label: 'Edit / open details' },
|
|
||||||
{ value: 'connect', label: 'Connect' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
<svelte:fragment slot="2">
|
<svelte:fragment slot="2">
|
||||||
<div class="heading">Application theme</div>
|
<div class="heading">Application theme</div>
|
||||||
@@ -161,6 +150,70 @@ ORDER BY
|
|||||||
<SqlEditor value={sqlPreview} readOnly />
|
<SqlEditor value={sqlPreview} readOnly />
|
||||||
</div>
|
</div>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
|
<svelte:fragment slot="3">
|
||||||
|
<div class="heading">Default actions</div>
|
||||||
|
<FormSelectField
|
||||||
|
label="Connection click"
|
||||||
|
name="defaultAction.connectionClick"
|
||||||
|
isNative
|
||||||
|
defaultValue="openDetails"
|
||||||
|
options={[
|
||||||
|
{ value: 'openDetails', label: 'Edit / open details' },
|
||||||
|
{ value: 'connect', label: 'Connect' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormSelectField
|
||||||
|
label="Table click"
|
||||||
|
name="defaultAction.dbObjectClick.tables"
|
||||||
|
isNative
|
||||||
|
defaultValue=""
|
||||||
|
options={[
|
||||||
|
{ value: '', label: 'Open data, or open existing' },
|
||||||
|
{ value: 'Open data', label: 'Open data (always new tab)' },
|
||||||
|
{ value: 'Open form', label: 'Open form (always new tab)' },
|
||||||
|
{ value: 'Open structure', label: 'Open structure' },
|
||||||
|
{ value: 'SQL: CREATE TABLE', label: 'SQL: CREATE' },
|
||||||
|
{ value: 'SQL: SELECT', label: 'SQL: SELECT' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormSelectField
|
||||||
|
label="View click"
|
||||||
|
name="defaultAction.dbObjectClick.views"
|
||||||
|
isNative
|
||||||
|
defaultValue=""
|
||||||
|
options={[
|
||||||
|
{ value: '', label: 'Open data, or open existing' },
|
||||||
|
{ value: 'Open data', label: 'Open data (always new tab)' },
|
||||||
|
{ value: 'SQL: CREATE VIEW', label: 'SQL: CREATE' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormSelectField
|
||||||
|
label="Materialized view click"
|
||||||
|
name="defaultAction.dbObjectClick.matviews"
|
||||||
|
isNative
|
||||||
|
defaultValue=""
|
||||||
|
options={[
|
||||||
|
{ value: '', label: 'Open data, or open existing' },
|
||||||
|
{ value: 'Open data', label: 'Open data (always new tab)' },
|
||||||
|
{ value: 'SQL: CREATE MATERIALIZED VIEW', label: 'SQL: CREATE' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormSelectField
|
||||||
|
label="Procedure click"
|
||||||
|
name="defaultAction.dbObjectClick.procedures"
|
||||||
|
isNative
|
||||||
|
defaultValue=""
|
||||||
|
options={[
|
||||||
|
{ value: '', label: 'SQL: CREATE' },
|
||||||
|
{ value: 'SQL: EXECUTE', label: 'SQL: EXECUTE' },
|
||||||
|
// { value: 'SQL: CREATE PROCEDURE', label: 'SQL: CREATE' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</svelte:fragment>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
</FormValues>
|
</FormValues>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user