Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
Expand All @@ -20,4 +20,5 @@ export enum EObjectFeature {
'dataSourceConnected' = 'dataSourceConnected',
'entityContainer' = 'entityContainer',
'supportsDataFilter' = 'supportsDataFilter',
'supportsFullDdl' = 'supportsFullDdl', // some connections may not have the full DDL feature
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation asyncSqlGenerateEntityQuery($generatorId: String!, $nodePathList: [String!]!, $generatorOptions: SQLQueryGeneratorOptions) {
taskInfo: asyncSqlGenerateEntityQuery(generatorId: $generatorId, nodePathList: $nodePathList, generatorOptions: $generatorOptions) {
...AsyncTaskInfo
}
}
3 changes: 0 additions & 3 deletions webapp/packages/core-sdk/src/queries/metadataGetNodeDDL.gql

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class DataGridContextMenuGenerateSqlService {
query,
nodeId: nodePath ?? connectionId,
nodeName: this.getEntityNameFromNodePath(containerNodePath, model.name),
generatorId,
generatorName: this.localizationService.translate(generatorLabel),
options: getDefaultQueryGeneratorOptions(),
regenerateQuery: options =>
Expand Down Expand Up @@ -234,6 +235,7 @@ export class DataGridContextMenuGenerateSqlService {
query,
nodeId: nodePathList,
nodeName: this.getEntityNameFromNodePath(nodePathList, model.name),
generatorId: createGenerator.id,
generatorName: createGenerator.label,
options: getDefaultQueryGeneratorOptions(),
regenerateQuery: genOptions => this.sqlGenerationResource.generateEntityQuery(createGenerator.id, nodePathList, genOptions),
Expand Down
3 changes: 3 additions & 0 deletions webapp/packages/plugin-ddl-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@cloudbeaver/core-connections": "workspace:*",
"@cloudbeaver/core-data-context": "workspace:*",
"@cloudbeaver/core-di": "workspace:*",
"@cloudbeaver/core-events": "workspace:*",
"@cloudbeaver/core-localization": "workspace:*",
"@cloudbeaver/core-navigation-tree": "workspace:*",
"@cloudbeaver/core-resource": "workspace:*",
"@cloudbeaver/core-sdk": "workspace:*",
Expand All @@ -36,6 +38,7 @@
"@cloudbeaver/plugin-sql-editor": "workspace:*",
"@cloudbeaver/plugin-sql-editor-codemirror": "workspace:*",
"@cloudbeaver/plugin-sql-editor-navigation-tab": "workspace:*",
"@cloudbeaver/plugin-sql-generator": "workspace:*",
"mobx": "^6",
"mobx-react-lite": "^4",
"react": "^19",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { createAction } from '@cloudbeaver/core-view';

export const ACTION_DDL_VIEWER_FULL_DDL = createAction('ddl-viewer-full-ddl', {
label: 'plugin_ddl_viewer_full_ddl',
tooltip: 'plugin_ddl_viewer_full_ddl',
type: 'checkbox',
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { createDataContext } from '@cloudbeaver/core-data-context';

export const DATA_CONTEXT_DDL_VIEWER_VALUE = createDataContext<string>('ddl-value');
export const DATA_CONTEXT_DDL_VIEWER_QUERY = createDataContext<string>('ddl-query');
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { injectable } from '@cloudbeaver/core-di';
import { MetadataMap } from '@cloudbeaver/core-utils';

@injectable()
export class DDLQueryStateService {
Comment thread
devnaumov marked this conversation as resolved.
Outdated
private readonly fullDdlState = new MetadataMap<string, boolean>(() => false);

isFullDdlEnabled(nodeId: string): boolean {
return this.fullDdlState.get(nodeId);
}

setFullDdlEnabled(nodeId: string, value: boolean): void {
this.fullDdlState.set(nodeId, value);
}

toggleFullDdl(nodeId: string): void {
this.setFullDdlEnabled(nodeId, !this.isFullDdlEnabled(nodeId));
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2025 DBeaver Corp and others
* Copyright (C) 2020-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { ConnectionInfoResource, createConnectionParam } from '@cloudbeaver/core-connections';
import { injectable } from '@cloudbeaver/core-di';
import { NavNodeManagerService } from '@cloudbeaver/core-navigation-tree';
import { EObjectFeature, NavNodeInfoResource, NavNodeManagerService } from '@cloudbeaver/core-navigation-tree';
import { download, withTimestamp } from '@cloudbeaver/core-utils';
import { ACTION_SAVE, ActionService, MenuService } from '@cloudbeaver/core-view';
import { DDL_GENERATOR_ID, SqlGeneratorsResource } from '@cloudbeaver/plugin-sql-generator';
import { LocalStorageSqlDataSource } from '@cloudbeaver/plugin-sql-editor';
import { ACTION_SQL_EDITOR_OPEN, SqlEditorNavigatorService } from '@cloudbeaver/plugin-sql-editor-navigation-tab';

import { ACTION_DDL_VIEWER_FULL_DDL } from './ACTION_DDL_VIEWER_FULL_DDL.js';
import { DATA_CONTEXT_DDL_VIEWER_NODE } from './DATA_CONTEXT_DDL_VIEWER_NODE.js';
import { DATA_CONTEXT_DDL_VIEWER_VALUE } from './DATA_CONTEXT_DDL_VIEWER_VALUE.js';
import { DATA_CONTEXT_DDL_VIEWER_QUERY } from './DATA_CONTEXT_DDL_VIEWER_QUERY.js';
import { DDLQueryStateService } from './DDLQueryStateService.js';
import { MENU_DDL_VIEWER_FOOTER } from './MENU_DDL_VIEWER_FOOTER.js';

@injectable(() => [NavNodeManagerService, ActionService, MenuService, SqlEditorNavigatorService, ConnectionInfoResource])
@injectable(() => [
NavNodeManagerService,
ActionService,
MenuService,
SqlEditorNavigatorService,
ConnectionInfoResource,
DDLQueryStateService,
NavNodeInfoResource,
SqlGeneratorsResource,
])
export class DDLViewerFooterService {
constructor(
private readonly navNodeManagerService: NavNodeManagerService,
private readonly actionsService: ActionService,
private readonly menuService: MenuService,
private readonly sqlEditorNavigatorService: SqlEditorNavigatorService,
private readonly connectionInfoResource: ConnectionInfoResource,
private readonly ddlQueryStateService: DDLQueryStateService,
private readonly navNodeInfoResource: NavNodeInfoResource,
private readonly sqlGeneratorsResource: SqlGeneratorsResource,
) {}

register(): void {
this.actionsService.addHandler({
id: 'ddl-viewer-footer-base-handler',
menus: [MENU_DDL_VIEWER_FOOTER],
contexts: [DATA_CONTEXT_DDL_VIEWER_NODE, DATA_CONTEXT_DDL_VIEWER_VALUE],
contexts: [DATA_CONTEXT_DDL_VIEWER_NODE, DATA_CONTEXT_DDL_VIEWER_QUERY],
actions: [ACTION_SAVE, ACTION_SQL_EDITOR_OPEN],
handler: async (context, action) => {
switch (action) {
case ACTION_SAVE: {
const ddl = context.get(DATA_CONTEXT_DDL_VIEWER_VALUE)!;
const ddl = context.get(DATA_CONTEXT_DDL_VIEWER_QUERY)!;
const nodeId = context.get(DATA_CONTEXT_DDL_VIEWER_NODE);

const blob = new Blob([ddl], {
Expand All @@ -50,7 +65,7 @@ export class DDLViewerFooterService {
break;
}
case ACTION_SQL_EDITOR_OPEN: {
const ddl = context.get(DATA_CONTEXT_DDL_VIEWER_VALUE)!;
const ddl = context.get(DATA_CONTEXT_DDL_VIEWER_QUERY)!;
const nodeId = context.get(DATA_CONTEXT_DDL_VIEWER_NODE)!;

const connection = this.connectionInfoResource.getConnectionForNode(nodeId);
Expand Down Expand Up @@ -92,5 +107,34 @@ export class DDLViewerFooterService {
menus: [MENU_DDL_VIEWER_FOOTER],
getItems: (context, items) => [...items, ACTION_SAVE, ACTION_SQL_EDITOR_OPEN],
});

this.menuService.addCreator({
menus: [MENU_DDL_VIEWER_FOOTER],
contexts: [DATA_CONTEXT_DDL_VIEWER_NODE],
isApplicable: context => this.hasFullDdl(context.get(DATA_CONTEXT_DDL_VIEWER_NODE)!),
getItems: (context, items) => [...items, ACTION_DDL_VIEWER_FULL_DDL],
});

this.actionsService.addHandler({
id: 'ddl-viewer-footer-full-ddl-handler',
menus: [MENU_DDL_VIEWER_FOOTER],
actions: [ACTION_DDL_VIEWER_FULL_DDL],
contexts: [DATA_CONTEXT_DDL_VIEWER_NODE],
isChecked: context => this.ddlQueryStateService.isFullDdlEnabled(context.get(DATA_CONTEXT_DDL_VIEWER_NODE)!),
handler: (context, action) => {
if (action === ACTION_DDL_VIEWER_FULL_DDL) {
this.ddlQueryStateService.toggleFullDdl(context.get(DATA_CONTEXT_DDL_VIEWER_NODE)!);
}
},
});
}

private hasFullDdl(nodeId: string): boolean {
const supportsFullDdl = this.navNodeInfoResource.get(nodeId)?.objectFeatures.includes(EObjectFeature.supportsFullDdl) ?? false;
const ddlGenerator = this.sqlGeneratorsResource
.get(nodeId)
?.find(generator => generator.id.toLowerCase().includes(DDL_GENERATOR_ID.toLowerCase()));

return supportsFullDdl && !!ddlGenerator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { observer } from 'mobx-react-lite';

import { s, useResource, useS } from '@cloudbeaver/core-blocks';
import { s, useAutoLoad, useResource, useS } from '@cloudbeaver/core-blocks';
import {
ConnectionDialectResource,
ConnectionInfoActiveProjectKey,
Expand All @@ -22,17 +22,15 @@
import { SQLCodeEditor, useSqlDialectExtension } from '@cloudbeaver/plugin-sql-editor-codemirror';

import { DATA_CONTEXT_DDL_VIEWER_NODE } from './DATA_CONTEXT_DDL_VIEWER_NODE.js';
import { DATA_CONTEXT_DDL_VIEWER_VALUE } from './DATA_CONTEXT_DDL_VIEWER_VALUE.js';
import { DdlResource } from './DdlResource.js';
import { DATA_CONTEXT_DDL_VIEWER_QUERY } from './DATA_CONTEXT_DDL_VIEWER_QUERY.js';
import style from './DDLViewerTabPanel.module.css';
import { MENU_DDL_VIEWER_FOOTER } from './MENU_DDL_VIEWER_FOOTER.js';
import { useDdlEntityQuery } from './useDdlEntityQuery.js';

export const DDLViewerTabPanel: NavNodeTransformViewComponent = observer(function DDLViewerTabPanel({ nodeId, folderId }) {

Check warning on line 30 in webapp/packages/plugin-ddl-viewer/src/DdlViewer/DDLViewerTabPanel.tsx

View workflow job for this annotation

GitHub Actions / Frontend / Lint

'folderId' is defined but never used
const styles = useS(style, MenuBarStyles, MenuBarItemStyles, MenuBarGroupStyles);
const menu = useMenu({ menu: MENU_DDL_VIEWER_FOOTER });

const ddlResource = useResource(DDLViewerTabPanel, DdlResource, nodeId);

const connectionInfoResource = useResource(DDLViewerTabPanel, ConnectionInfoResource, ConnectionInfoActiveProjectKey);
const connection = connectionInfoResource.resource.getConnectionForNode(nodeId);
const connectionParam = connection ? createConnectionParam(connection) : null;
Expand All @@ -42,16 +40,21 @@
if (sqlDialect) {
extensions.set(...sqlDialect);
}
const ddlData = ddlResource.data;

const ddlQueryState = useDdlEntityQuery(nodeId);

useAutoLoad(DDLViewerTabPanel, ddlQueryState);

const query = ddlQueryState.query ?? '';

useDataContextLink(menu.context, (context, id) => {
context.set(DATA_CONTEXT_DDL_VIEWER_NODE, nodeId, id);
context.set(DATA_CONTEXT_DDL_VIEWER_VALUE, ddlData, id);
context.set(DATA_CONTEXT_DDL_VIEWER_QUERY, query, id);
});

return (
<div className={s(styles, { wrapper: true })}>
<SQLCodeEditor className={s(styles, { sqlCodeEditorLoader: true })} value={ddlResource.data ?? ''} extensions={extensions} readonly />
<SQLCodeEditor className={s(styles, { sqlCodeEditorLoader: true })} value={query} extensions={extensions} readonly />
<MenuBar className={s(styles, { menuBar: true, floating: true, withLabel: true })} menu={menu} compact={false} />
</div>
);
Expand Down
47 changes: 0 additions & 47 deletions webapp/packages/plugin-ddl-viewer/src/DdlViewer/DdlResource.ts

This file was deleted.

Loading
Loading