From f54ee00e4a5a3bf6fbecd8e62ab1c338541df399 Mon Sep 17 00:00:00 2001 From: Naumov Alexey Date: Tue, 22 Mar 2022 00:21:06 +0300 Subject: [PATCH 1/2] feat(plugin-ddl-viewer): CB-1756 option to open sql editor from the ddl tab --- .../src/DdlViewer/DDLViewerFooterService.ts | 32 +++++++++++++++++-- .../src/SqlEditorNavigatorService.ts | 4 ++- .../src/SqlEditorTabService.ts | 3 +- .../src/index.ts | 6 +++- .../plugin-sql-editor/src/SqlEditorService.ts | 3 +- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts b/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts index 1feda65c7b..69409c35fd 100644 --- a/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts +++ b/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts @@ -7,9 +7,11 @@ */ import { NavNodeManagerService } from '@cloudbeaver/core-app'; +import { ConnectionInfoResource } from '@cloudbeaver/core-connections'; import { injectable } from '@cloudbeaver/core-di'; import { download, generateFileName } from '@cloudbeaver/core-utils'; import { ActionService, ACTION_SAVE, DATA_CONTEXT_MENU, MenuService } from '@cloudbeaver/core-view'; +import { ACTION_SQL_EDITOR_OPEN, SqlEditorNavigatorService } from '@cloudbeaver/plugin-sql-editor-navigation-tab'; import { DATA_CONTEXT_DDL_VIEWER_NODE } from './DATA_CONTEXT_DDL_VIEWER_NODE'; import { DATA_CONTEXT_DDL_VIEWER_VALUE } from './DATA_CONTEXT_DDL_VIEWER_VALUE'; @@ -21,6 +23,8 @@ export class DDLViewerFooterService { private readonly navNodeManagerService: NavNodeManagerService, private readonly actionsService: ActionService, private readonly menuService: MenuService, + private readonly sqlEditorNavigatorService: SqlEditorNavigatorService, + private readonly connectionInfoResource: ConnectionInfoResource ) { } register(): void { @@ -34,14 +38,14 @@ export class DDLViewerFooterService { return false; } - if (action === ACTION_SAVE) { + if (action === ACTION_SAVE || action === ACTION_SQL_EDITOR_OPEN) { const ddl = context.tryGet(DATA_CONTEXT_DDL_VIEWER_VALUE); return !!ddl; } return false; }, - handler: (context, action) => { + handler: async (context, action) => { switch (action) { case ACTION_SAVE: { const ddl = context.get(DATA_CONTEXT_DDL_VIEWER_VALUE); @@ -57,8 +61,31 @@ export class DDLViewerFooterService { download(blob, generateFileName(name, '.sql')); break; } + case ACTION_SQL_EDITOR_OPEN: { + const ddl = context.get(DATA_CONTEXT_DDL_VIEWER_VALUE); + const nodeId = context.get(DATA_CONTEXT_DDL_VIEWER_NODE); + + const connection = this.connectionInfoResource.getConnectionForNode(nodeId); + const container = this.navNodeManagerService.getNodeContainerInfo(nodeId); + const name = `${container.catalogId ? '<' + container.catalogId + '> ' : ''}DDL${container.schemaId ? ' of <' + container.schemaId + '>' : ''}`; + + await this.sqlEditorNavigatorService.openNewEditor({ + name, + connectionId: connection?.id, + catalogId: container.catalogId, + schemaId: container.schemaId, + query: ddl, + }); + break; + } } }, + getActionInfo: (context, action) => { + if (action === ACTION_SQL_EDITOR_OPEN) { + return { ...action.info, icon: '/icons/sql_script_m.svg' }; + } + return action.info; + }, }); this.menuService.addCreator({ @@ -66,6 +93,7 @@ export class DDLViewerFooterService { getItems: (context, items) => [ ...items, ACTION_SAVE, + ACTION_SQL_EDITOR_OPEN, ], }); } diff --git a/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorNavigatorService.ts b/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorNavigatorService.ts index b470dd6ffc..324626745f 100644 --- a/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorNavigatorService.ts +++ b/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorNavigatorService.ts @@ -32,6 +32,7 @@ export interface ISQLEditorOptions { catalogId?: string; schemaId?: string; source?: string; + query?: string; } export interface SQLCreateAction extends SQLEditorActionContext, ISQLEditorOptions { @@ -107,7 +108,8 @@ export class SqlEditorNavigatorService { if (!tab) { const tabOptions = this.sqlEditorTabService.createNewEditor( data.name, - data.source + data.source, + data.query ); if (tabOptions) { diff --git a/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorTabService.ts b/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorTabService.ts index 7a70a16dbb..2b512bbb61 100644 --- a/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorTabService.ts +++ b/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorTabService.ts @@ -93,13 +93,14 @@ export class SqlEditorTabService extends Bootstrap { createNewEditor( name?: string, source?: string, + query?: string, ): ITabOptions | null { const order = this.getFreeEditorId(); return { handlerId: sqlEditorTabHandlerKey, - handlerState: this.sqlEditorService.getState(order, name, source), + handlerState: this.sqlEditorService.getState(order, name, source, query), }; } diff --git a/webapp/packages/plugin-sql-editor-navigation-tab/src/index.ts b/webapp/packages/plugin-sql-editor-navigation-tab/src/index.ts index 56610816f4..f0756eece6 100644 --- a/webapp/packages/plugin-sql-editor-navigation-tab/src/index.ts +++ b/webapp/packages/plugin-sql-editor-navigation-tab/src/index.ts @@ -1,4 +1,8 @@ import { sqlEditorTabPluginManifest } from './manifest'; -export { DATA_CONTEXT_SQL_EDITOR_TAB } from './DATA_CONTEXT_SQL_EDITOR_TAB'; export default sqlEditorTabPluginManifest; + +export { DATA_CONTEXT_SQL_EDITOR_TAB } from './DATA_CONTEXT_SQL_EDITOR_TAB'; +export { ACTION_SQL_EDITOR_OPEN } from './ACTION_SQL_EDITOR_OPEN'; + +export * from './SqlEditorNavigatorService'; diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts b/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts index 76b63517f2..036d7d356c 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts @@ -27,12 +27,13 @@ export class SqlEditorService { order: number, name?: string, source?: string, + query?: string, contextInfo?: IConnectionExecutionContextInfo ): ISqlEditorTabState { return { name, source, - query: '', + query: query ?? '', order, executionContext: contextInfo ? { ...contextInfo } : undefined, tabs: [], From cbba7e126ccc84cec681693aa86ab2d636caf0f9 Mon Sep 17 00:00:00 2001 From: Naumov Alexey Date: Tue, 22 Mar 2022 10:48:57 +0300 Subject: [PATCH 2/2] feat(plugin-ddl-viewer): CB-1756 add node name to the tab name --- .../src/DdlViewer/DDLViewerFooterService.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts b/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts index 69409c35fd..88014aa30b 100644 --- a/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts +++ b/webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerFooterService.ts @@ -67,7 +67,17 @@ export class DDLViewerFooterService { const connection = this.connectionInfoResource.getConnectionForNode(nodeId); const container = this.navNodeManagerService.getNodeContainerInfo(nodeId); - const name = `${container.catalogId ? '<' + container.catalogId + '> ' : ''}DDL${container.schemaId ? ' of <' + container.schemaId + '>' : ''}`; + const node = this.navNodeManagerService.getNode(nodeId); + const path = []; + + if (container.schemaId) { + path.push(container.schemaId); + } + if (node?.name && node.name !== container.schemaId) { + path.push(node.name); + } + + const name = `${container.catalogId ? '<' + container.catalogId + '> ' : ''}DDL${path.length ? ' of <' + path.join('.') + '>' : ''}`; await this.sqlEditorNavigatorService.openNewEditor({ name,