From 25fe13dd455626e8d168d6059310e678a181fd65 Mon Sep 17 00:00:00 2001 From: akleinas Date: Fri, 14 Feb 2025 16:03:58 +0200 Subject: [PATCH 1/5] 544 partial implementation of RO mode --- package.json | 5 +++++ src/common/OpenEdgeJsonReaded.ts | 1 + src/extension.ts | 8 ++++++++ src/view/app/utils/PfParser.ts | 10 ++++++++++ src/webview/QueryEditor.ts | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 45964db7..b8733b62 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,11 @@ "Small" ], "description": "Set the grid text size." + }, + "pro-bro.readOnlyMode": { + "type": "boolean", + "default": false, + "markdownDescription": "Connect to all databases in read-only mode" } } }, diff --git a/src/common/OpenEdgeJsonReaded.ts b/src/common/OpenEdgeJsonReaded.ts index 18508957..bb555122 100644 --- a/src/common/OpenEdgeJsonReaded.ts +++ b/src/common/OpenEdgeJsonReaded.ts @@ -25,6 +25,7 @@ export function parseOEFile(fileContent: string, filePath: string) { const directoryPath = path.dirname(filePath); + console.warn('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'); dbConnections.forEach((connection: { name: string; connect: string }) => { const { name, connect } = connection; diff --git a/src/extension.ts b/src/extension.ts index 2ce31e81..1518763c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -197,27 +197,35 @@ export async function activate(context: vscode.ExtensionContext) { }); vscode.workspace.onDidChangeConfiguration((event) => { + console.warn('OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO'); if ( event.affectsConfiguration( `${Constants.globalExtensionKey}.importConnections` + ) || + event.affectsConfiguration( + `${Constants.globalExtensionKey}.readOnlyMode` ) ) { + console.warn('YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'); importConnections = vscode.workspace .getConfiguration(Constants.globalExtensionKey) .get('importConnections'); if (importConnections) { + console.warn('UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU'); vscode.workspace .findFiles('**/openedge-project.json') .then((list) => { list.forEach((uri) => createJsonDatabases(uri)); }); } else { + console.warn('IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'); clearDatabaseConfigState(); } } }); function createJsonDatabases(uri: vscode.Uri) { + console.warn('VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'); allFileContent = readFile(uri.fsPath); const configs = parseOEFile(allFileContent, uri.fsPath); diff --git a/src/view/app/utils/PfParser.ts b/src/view/app/utils/PfParser.ts index dcedfc86..d8599b6f 100644 --- a/src/view/app/utils/PfParser.ts +++ b/src/view/app/utils/PfParser.ts @@ -1,4 +1,5 @@ import { IConfig } from '../model'; +import * as vscode from 'vscode'; export class PfParser { public parse(pfFile: string): IConfig { @@ -36,6 +37,15 @@ export class PfParser { '-crTXDisplay', '-Sn', ]; + console.warn('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'); + const vsConfiguration = vscode.workspace.getConfiguration('pro-bro'); + if (vsConfiguration) { + console.log('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ' + pfFile); + if (vsConfiguration.readOnlyMode) { + console.log('AAAAAAAAAAAAAAAAAAAAAAAAAreadOnlyMode ' + pfFile); + config.isReadOnly = true; + } + } pfFile .split('\n') diff --git a/src/webview/QueryEditor.ts b/src/webview/QueryEditor.ts index 9bac80ee..e972c777 100644 --- a/src/webview/QueryEditor.ts +++ b/src/webview/QueryEditor.ts @@ -29,7 +29,7 @@ export class QueryEditor { private readonly configuration = vscode.workspace.getConfiguration( Constants.globalExtensionKey ); - private readOnly = false; + private readOnly = this.configuration.readOnlyMode; private logger = new Logger( this.configuration.get('logging.node') ?? false ); From 0ff40732c25ea6c21c2b4cf60ca445bf70a2cc84 Mon Sep 17 00:00:00 2001 From: Aldas Kleinas Date: Thu, 17 Apr 2025 11:05:26 +0300 Subject: [PATCH 2/5] 544 made RO mode configureable with restart --- package-lock.json | 4 +- package.json | 2 +- src/common/IExtensionSettings.ts | 1 + src/extension.ts | 96 +++--- src/view/app/Connection/connectionForm.tsx | 13 +- src/view/app/Query/Update/update.tsx | 4 +- src/view/app/Query/query.tsx | 4 +- src/view/app/Query/test.tsx | 8 + src/view/app/utils/PfParser.ts | 9 +- src/webview/ConnectionEditor.ts | 8 +- src/webview/QueryEditor.ts | 333 ++++++++++----------- 11 files changed, 245 insertions(+), 237 deletions(-) create mode 100644 src/view/app/Query/test.tsx diff --git a/package-lock.json b/package-lock.json index f83f1837..0c97a612 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pro-bro", - "version": "1.8.0", + "version": "1.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pro-bro", - "version": "1.8.0", + "version": "1.9.0", "dependencies": { "@emotion/react": "^11.10.0", "@emotion/styled": "^11.10.0", diff --git a/package.json b/package.json index b8733b62..434219ba 100644 --- a/package.json +++ b/package.json @@ -131,7 +131,7 @@ "pro-bro.readOnlyMode": { "type": "boolean", "default": false, - "markdownDescription": "Connect to all databases in read-only mode" + "markdownDescription": "Connect to all databases in read-only mode (requires restart)" } } }, diff --git a/src/common/IExtensionSettings.ts b/src/common/IExtensionSettings.ts index 271af415..010844be 100644 --- a/src/common/IExtensionSettings.ts +++ b/src/common/IExtensionSettings.ts @@ -8,6 +8,7 @@ export interface ISettings { filterAsYouType: boolean; useDeleteTriggers: boolean; gridTextSize: string; + readOnlyMode: boolean; } export interface ILogging { diff --git a/src/extension.ts b/src/extension.ts index 1518763c..eaebbe2a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -38,53 +38,58 @@ export async function activate(context: vscode.ExtensionContext) { let allFileContent = ''; vscode.workspace.onDidChangeConfiguration((event) => { - const affected = event.affectsConfiguration( - `${Constants.globalExtensionKey}.possiblePortsList` - ); - if (!affected) { - return; - } + if ( + event.affectsConfiguration( + `${Constants.globalExtensionKey}.possiblePortsList` + ) + ) { + const settingsPorts: number[] = + vscode.workspace + .getConfiguration(Constants.globalExtensionKey) + .get('possiblePortsList') ?? []; + if (settingsPorts.length === 0) { + context.globalState.update( + `${Constants.globalExtensionKey}.portList`, + undefined + ); + return; + } + let newGlobalStatePortList: IPort[] = []; + const globalStatePorts = context.globalState.get<{ + [id: string]: IPort; + }>(`${Constants.globalExtensionKey}.portList`); + if (globalStatePorts) { + newGlobalStatePortList = Object.values(globalStatePorts).filter( + (gPort) => { + const portIndex: number = settingsPorts.indexOf( + gPort.port + ); + if (portIndex < 0) { + return false; + } else { + settingsPorts.splice(portIndex, 1); + return true; + } + } + ); + } + + newGlobalStatePortList = [ + ...newGlobalStatePortList, + ...settingsPorts.map((sPort: number): IPort => { + return { + port: sPort, + isInUse: false, + timestamp: undefined, + }; + }), + ]; - const settingsPorts: number[] = - vscode.workspace - .getConfiguration(Constants.globalExtensionKey) - .get('possiblePortsList') ?? []; - if (settingsPorts.length === 0) { context.globalState.update( `${Constants.globalExtensionKey}.portList`, - undefined - ); - return; - } - let newGlobalStatePortList: IPort[] = []; - const globalStatePorts = context.globalState.get<{ - [id: string]: IPort; - }>(`${Constants.globalExtensionKey}.portList`); - if (globalStatePorts) { - newGlobalStatePortList = Object.values(globalStatePorts).filter( - (gPort) => { - const portIndex: number = settingsPorts.indexOf(gPort.port); - if (portIndex < 0) { - return false; - } else { - settingsPorts.splice(portIndex, 1); - return true; - } - } + newGlobalStatePortList ); } - - newGlobalStatePortList = [ - ...newGlobalStatePortList, - ...settingsPorts.map((sPort: number): IPort => { - return { port: sPort, isInUse: false, timestamp: undefined }; - }), - ]; - - context.globalState.update( - `${Constants.globalExtensionKey}.portList`, - newGlobalStatePortList - ); }); const updatePortList = () => { @@ -197,28 +202,21 @@ export async function activate(context: vscode.ExtensionContext) { }); vscode.workspace.onDidChangeConfiguration((event) => { - console.warn('OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO'); if ( event.affectsConfiguration( `${Constants.globalExtensionKey}.importConnections` - ) || - event.affectsConfiguration( - `${Constants.globalExtensionKey}.readOnlyMode` ) ) { - console.warn('YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'); importConnections = vscode.workspace .getConfiguration(Constants.globalExtensionKey) .get('importConnections'); if (importConnections) { - console.warn('UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU'); vscode.workspace .findFiles('**/openedge-project.json') .then((list) => { list.forEach((uri) => createJsonDatabases(uri)); }); } else { - console.warn('IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII'); clearDatabaseConfigState(); } } diff --git a/src/view/app/Connection/connectionForm.tsx b/src/view/app/Connection/connectionForm.tsx index 3137bf0d..21392306 100644 --- a/src/view/app/Connection/connectionForm.tsx +++ b/src/view/app/Connection/connectionForm.tsx @@ -6,7 +6,7 @@ import FileUploadRoundedIcon from '@mui/icons-material/FileUploadRounded'; import { PfParser } from '../utils/PfParser'; import { Logger } from '../../../common/Logger'; import { ISettings } from '../../../common/IExtensionSettings'; -import { getVSCodeAPI } from '@utils/vscode'; +import { getVSCodeAPI, getVSCodeConfiguration } from '@utils/vscode'; interface IConfigProps { initialData: IConfig; @@ -17,7 +17,12 @@ interface IConfigState { config: IConfig; } -function ConnectionForm({ initialData, configuration, ...props}: IConfigProps) { +function ConnectionForm({ + initialData, + configuration, + ...props +}: IConfigProps) { + const vsConfiguration = getVSCodeConfiguration(); const vscode = getVSCodeAPI(); const oldState = vscode.getState(); const initState = oldState ? oldState : { config: initialData }; @@ -57,7 +62,7 @@ function ConnectionForm({ initialData, configuration, ...props}: IConfigProps) { params: params, connectionId: vsState.config.connectionId, type: vsState.config.type, - isReadOnly: params.includes('-RO'), + isReadOnly: params.includes('-RO') || vsConfiguration.readOnlyMode, }; const command: ICommand = { id: id, @@ -109,7 +114,7 @@ function ConnectionForm({ initialData, configuration, ...props}: IConfigProps) { params: params, connectionId: vsState.config.connectionId, type: vsState.config.type, - isReadOnly: params.includes('-RO'), + isReadOnly: params.includes('-RO') || vsConfiguration.readOnlyMode, }; const command: ICommand = { id: id, diff --git a/src/view/app/Query/Update/update.tsx b/src/view/app/Query/Update/update.tsx index 4b935f04..270c7573 100644 --- a/src/view/app/Query/Update/update.tsx +++ b/src/view/app/Query/Update/update.tsx @@ -377,9 +377,7 @@ const UpdatePopup: React.FC = ({ setOpen(false); updateRecord(); }} - disabled={ - isReadOnly === true ? true : false - } + disabled = {isReadOnly} > UPDATE diff --git a/src/view/app/Query/query.tsx b/src/view/app/Query/query.tsx index 56bd2595..5eac23c0 100644 --- a/src/view/app/Query/query.tsx +++ b/src/view/app/Query/query.tsx @@ -229,7 +229,9 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) { processBooleanFields(message.data.columns, message.data.rawData); if (message.data.rawData === undefined) { - logger.log('message.data.rawData in query.tsx handleData() is undefined'); + logger.log( + 'message.data.rawData in query.tsx handleData() is undefined' + ); return; } setRawRows([...rawRows, ...message.data.rawData]); diff --git a/src/view/app/Query/test.tsx b/src/view/app/Query/test.tsx new file mode 100644 index 00000000..a589992f --- /dev/null +++ b/src/view/app/Query/test.tsx @@ -0,0 +1,8 @@ +function sample() +{ + return ( +
+

Sample

+
+ ); +} \ No newline at end of file diff --git a/src/view/app/utils/PfParser.ts b/src/view/app/utils/PfParser.ts index d8599b6f..25cc71cf 100644 --- a/src/view/app/utils/PfParser.ts +++ b/src/view/app/utils/PfParser.ts @@ -1,7 +1,9 @@ import { IConfig } from '../model'; -import * as vscode from 'vscode'; +import { getVSCodeConfiguration } from './vscode'; export class PfParser { + private readonly configuration = getVSCodeConfiguration(); + public parse(pfFile: string): IConfig { const config: IConfig = { id: 'connection', @@ -38,10 +40,9 @@ export class PfParser { '-Sn', ]; console.warn('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'); - const vsConfiguration = vscode.workspace.getConfiguration('pro-bro'); - if (vsConfiguration) { + if (this.configuration) { console.log('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ' + pfFile); - if (vsConfiguration.readOnlyMode) { + if (this.configuration.readOnlyMode) { console.log('AAAAAAAAAAAAAAAAAAAAAAAAAreadOnlyMode ' + pfFile); config.isReadOnly = true; } diff --git a/src/webview/ConnectionEditor.ts b/src/webview/ConnectionEditor.ts index 2807b0dd..6c512875 100644 --- a/src/webview/ConnectionEditor.ts +++ b/src/webview/ConnectionEditor.ts @@ -10,7 +10,7 @@ export class ConnectionEditor { private readonly panel: vscode.WebviewPanel | undefined; private readonly extensionPath: string; private disposables: vscode.Disposable[] = []; - private isTestedSuccesfully = false; + private isTestedSuccessfully = false; private readonly id?: string; private readonly configuration = vscode.workspace.getConfiguration( Constants.globalExtensionKey @@ -76,7 +76,7 @@ export class ConnectionEditor { }>(`${Constants.globalExtensionKey}.dbconfig`); switch (command.action) { case CommandAction.Save: - if (!this.isTestedSuccesfully) { + if (!this.isTestedSuccessfully) { vscode.window.showInformationMessage( 'Connection should be tested before saving.' ); @@ -90,7 +90,7 @@ export class ConnectionEditor { connections ); vscode.window.showInformationMessage( - 'Connection saved succesfully.' + 'Connection saved successfully.' ); this.panel?.dispose(); vscode.commands.executeCommand( @@ -115,7 +115,7 @@ export class ConnectionEditor { vscode.window.showInformationMessage( 'Connection OK' ); - this.isTestedSuccesfully = true; + this.isTestedSuccessfully = true; } }); } diff --git a/src/webview/QueryEditor.ts b/src/webview/QueryEditor.ts index e972c777..0ce39f6d 100644 --- a/src/webview/QueryEditor.ts +++ b/src/webview/QueryEditor.ts @@ -49,27 +49,23 @@ export class QueryEditor { let config: IConfig | undefined; switch (this.tableNode.source) { - case TableNodeSourceEnum.Tables: - config = this.tableListProvider.config; - break; - case TableNodeSourceEnum.Favorites: - config = this.favoritesProvider.config; - break; - case TableNodeSourceEnum.Custom: - config = this.customViewProvider.config; - break; - default: - return; + case TableNodeSourceEnum.Tables: + config = this.tableListProvider.config; + break; + case TableNodeSourceEnum.Favorites: + config = this.favoritesProvider.config; + break; + case TableNodeSourceEnum.Custom: + config = this.customViewProvider.config; + break; + default: + return; } if (tableNode instanceof CustomViewNode) { this.customViewData = tableNode.customViewParams; } - if (config) { - this.readOnly = config?.isReadOnly; - } - this.panel = vscode.window.createWebviewPanel( 'queryOETable', // Identifies the type of the webview. Used internally `${config?.label}.${this.tableNode.tableName}`, // Title of the panel displayed to the user @@ -115,48 +111,111 @@ export class QueryEditor { (command: ICommand) => { this.logger.log('command:', command); switch (command.action) { - case CommandAction.Query: - if (config) { - ProcessorFactory.getProcessorInstance() - .getTableData( - config, - this.tableNode.tableName, - this.customViewData - ? this.getParams(command.params!) - : command.params - ) - .then((oe) => { - if (this.customViewData) { - const obj = { - id: command.id, - command: 'customViewParams', - params: this.customViewData, - }; - this.logger.log( - 'customView params: ', - this.customViewData - ); - this.panel?.webview.postMessage(obj); - } - - if (this.panel) { - const obj = { - id: command.id, - command: 'data', - columns: + case CommandAction.Query: + if (config) { + ProcessorFactory.getProcessorInstance() + .getTableData( + config, + this.tableNode.tableName, + this.customViewData + ? this.getParams(command.params!) + : command.params + ) + .then((oe) => { + if (this.customViewData) { + const obj = { + id: command.id, + command: 'customViewParams', + params: this.customViewData, + }; + this.logger.log( + 'customView params: ', + this.customViewData + ); + this.panel?.webview.postMessage(obj); + } + + if (this.panel) { + const obj = { + id: command.id, + command: 'data', + columns: tableNode.cache ?.selectedColumns, - data: oe, - }; - this.logger.log('data:', obj); - this.customViewData = undefined; - this.panel?.webview.postMessage(obj); - } - }); - } - break; - case CommandAction.CRUD: - if (config) { + data: oe, + }; + this.logger.log('data:', obj); + this.customViewData = undefined; + this.panel?.webview.postMessage(obj); + } + }); + } + break; + case CommandAction.CRUD: + if (config) { + ProcessorFactory.getProcessorInstance() + .getTableData( + config, + this.tableNode.tableName, + command.params + ) + .then((oe) => { + if (this.panel) { + const obj = { + id: command.id, + command: 'crud', + data: oe, + }; + this.logger.log('data:', obj); + this.panel?.webview.postMessage(obj); + } + }); + } + break; + case CommandAction.Submit: + if (config) { + ProcessorFactory.getProcessorInstance() + .submitTableData( + config, + this.tableNode.tableName, + command.params + ) + .then((oe) => { + if (this.panel) { + const obj = { + id: command.id, + command: 'submit', + data: oe, + }; + this.logger.log('data:', obj); + if ( + obj.data.description !== null && + obj.data.description !== undefined + ) { + if (obj.data.description === '') { + vscode.window.showErrorMessage( + 'Database Error: Trigger canceled action' + ); + } else { + vscode.window.showErrorMessage( + 'Database Error: ' + + obj.data.description + ); + } + } else { + vscode.window.showInformationMessage( + 'Action was successful' + ); + } + this.panel?.webview.postMessage(obj); + } + }); + } + break; + case CommandAction.Export: + if (!config) { + break; + } ProcessorFactory.getProcessorInstance() .getTableData( config, @@ -164,128 +223,65 @@ export class QueryEditor { command.params ) .then((oe) => { - if (this.panel) { - const obj = { - id: command.id, - command: 'crud', - data: oe, - }; - this.logger.log('data:', obj); - this.panel?.webview.postMessage(obj); + if (!this.panel) { + return; } - }); - } - break; - case CommandAction.Submit: - if (config) { - ProcessorFactory.getProcessorInstance() - .submitTableData( - config, - this.tableNode.tableName, - command.params - ) - .then((oe) => { - if (this.panel) { + if (!config) { + throw new Error( + 'Configuration became undefined unexpectedly.' + ); + } + let exportData = oe; + if (command.params?.exportType === 'dumpFile') { + const dumpFileFormatter = + new DumpFileFormatter(); + dumpFileFormatter.formatDumpFile( + oe, + this.tableNode.tableName, + config.label + ); + exportData = + dumpFileFormatter.getDumpFile(); + } + if (command.params !== undefined) { const obj = { id: command.id, - command: 'submit', - data: oe, + command: 'export', + tableName: this.tableNode.tableName, + data: exportData, + format: command.params.exportType, }; + this.logger.log('data:', obj); - if ( - obj.data.description !== null && - obj.data.description !== undefined - ) { - if (obj.data.description === '') { - vscode.window.showErrorMessage( - 'Database Error: Trigger canceled action' - ); - } else { - vscode.window.showErrorMessage( - 'Database Error: ' + - obj.data.description - ); - } - } else { - vscode.window.showInformationMessage( - 'Action was successful' - ); - } this.panel?.webview.postMessage(obj); } }); - } - break; - case CommandAction.Export: - if (!config) { break; - } - ProcessorFactory.getProcessorInstance() - .getTableData( - config, - this.tableNode.tableName, - command.params - ) - .then((oe) => { - if (!this.panel) { - return; - } - if (!config) { - throw new Error( - 'Configuration became undefined unexpectedly.' - ); - } - let exportData = oe; - if (command.params?.exportType === 'dumpFile') { - const dumpFileFormatter = - new DumpFileFormatter(); - dumpFileFormatter.formatDumpFile( - oe, - this.tableNode.tableName, - config.label - ); - exportData = - dumpFileFormatter.getDumpFile(); - } - if (command.params !== undefined) { - const obj = { - id: command.id, - command: 'export', - tableName: this.tableNode.tableName, - data: exportData, - format: command.params.exportType, - }; - - this.logger.log('data:', obj); - this.panel?.webview.postMessage(obj); - } - }); - break; - case CommandAction.SaveCustomQuery: - vscode.commands - .executeCommand( - `${Constants.globalExtensionKey}.saveCustomView`, - new CustomViewNode( - Constants.context, - this.tableNode, - command.customView?.name || '', - command.customView + case CommandAction.SaveCustomQuery: + vscode.commands + .executeCommand( + `${Constants.globalExtensionKey}.saveCustomView`, + new CustomViewNode( + Constants.context, + this.tableNode, + command.customView?.name || '', + command.customView + ) ) - ) - .then( - () => { - console.log( - 'Command executed successfully' - ); - }, - (error) => { - console.error( - 'Error executing command:', - error - ); - } - ); - break; + .then( + () => { + console.log( + 'Command executed successfully' + ); + }, + (error) => { + console.error( + 'Error executing command:', + error + ); + } + ); + break; } }, undefined, @@ -308,7 +304,7 @@ export class QueryEditor { } public setParams = (node: CustomViewNode): void => { - this.customViewData = node.customViewParams; + this.customViewData = node.customViewParams; }; public resetParams = (): void => { @@ -325,7 +321,6 @@ export class QueryEditor { }; }; - public getParams = (params: ITableData): ITableData => { if (!this.customViewData) { return params; From d92b90c18830140191f2e10c7140213821175c91 Mon Sep 17 00:00:00 2001 From: Aldas Kleinas Date: Thu, 17 Apr 2025 13:02:49 +0300 Subject: [PATCH 3/5] 544 improved formatting --- src/treeview/DbConnectionNode.ts | 32 +-- src/view/app/Fields/fields.tsx | 9 +- src/webview/QueryEditor.ts | 324 ++++++++++++++++--------------- 3 files changed, 186 insertions(+), 179 deletions(-) diff --git a/src/treeview/DbConnectionNode.ts b/src/treeview/DbConnectionNode.ts index 6c17237c..c91dd959 100644 --- a/src/treeview/DbConnectionNode.ts +++ b/src/treeview/DbConnectionNode.ts @@ -18,7 +18,7 @@ export class DbConnectionNode implements INode { id: string, config: IConfig, refreshCallback: IRefreshCallback, - private context: vscode.ExtensionContext + private context: vscode.ExtensionContext ) { this.id = id; this.config = config; @@ -44,14 +44,14 @@ export class DbConnectionNode implements INode { private iconChooser() { switch (this.config.conStatus) { - case ConnectionStatus.Connected: - return 'progress_icon.svg'; - case ConnectionStatus.NotConnected: - return 'progress_icon_stop.svg'; - case ConnectionStatus.Connecting: - return 'loading.gif'; - default: - return 'progress_icon_stop.svg'; + case ConnectionStatus.Connected: + return 'progress_icon.svg'; + case ConnectionStatus.NotConnected: + return 'progress_icon_stop.svg'; + case ConnectionStatus.Connecting: + return 'loading.gif'; + default: + return 'progress_icon_stop.svg'; } } @@ -60,7 +60,7 @@ export class DbConnectionNode implements INode { } public async deleteConnection(context: vscode.ExtensionContext) { - //TODO fix and move to someplace else + //TODO fix and move to someplace else let connections = context.globalState.get<{ [id: string]: IConfig }>( 'pro-bro.dbconfig' @@ -107,13 +107,13 @@ export class DbConnectionNode implements INode { if (this.id) { let connections = this.context.globalState.get<{ - [id: string]: IConfig; - }>(`${Constants.globalExtensionKey}.dbconfig`); + [id: string]: IConfig; + }>(`${Constants.globalExtensionKey}.dbconfig`); if (connections && !connections[this.id]) { connections = this.context.workspaceState.get<{ - [id: string]: IConfig; - }>(`${Constants.globalExtensionKey}.dbconfig`); + [id: string]: IConfig; + }>(`${Constants.globalExtensionKey}.dbconfig`); } if (connections) { return connections[this.id]; @@ -167,7 +167,9 @@ export class DbConnectionNode implements INode { console.log(`stdout: ${data}`); }); - child.on('error', (error) => console.log('child process error: \n', error)); + child.on('error', (error) => + console.log('child process error: \n', error) + ); // Listen for the process exit event child.on('exit', (code) => { diff --git a/src/view/app/Fields/fields.tsx b/src/view/app/Fields/fields.tsx index 518e08cf..f87d05e9 100644 --- a/src/view/app/Fields/fields.tsx +++ b/src/view/app/Fields/fields.tsx @@ -124,8 +124,8 @@ function Fields() { setCellSelected={props.setCellSelected} filters={filters} setFilters={setFilters} - configuration={configuration} - /> + configuration={configuration} + /> ); }; }); @@ -157,7 +157,10 @@ function Fields() { enabled: true, }); - if (message.data.selectedColumns.length === 0 && message.data.selectedColumns === undefined) { + if ( + message.data.selectedColumns.length === 0 && + message.data.selectedColumns === undefined + ) { setSelectedRows( (): ReadonlySet => new Set( diff --git a/src/webview/QueryEditor.ts b/src/webview/QueryEditor.ts index 0ce39f6d..ad76329c 100644 --- a/src/webview/QueryEditor.ts +++ b/src/webview/QueryEditor.ts @@ -112,175 +112,19 @@ export class QueryEditor { this.logger.log('command:', command); switch (command.action) { case CommandAction.Query: - if (config) { - ProcessorFactory.getProcessorInstance() - .getTableData( - config, - this.tableNode.tableName, - this.customViewData - ? this.getParams(command.params!) - : command.params - ) - .then((oe) => { - if (this.customViewData) { - const obj = { - id: command.id, - command: 'customViewParams', - params: this.customViewData, - }; - this.logger.log( - 'customView params: ', - this.customViewData - ); - this.panel?.webview.postMessage(obj); - } - - if (this.panel) { - const obj = { - id: command.id, - command: 'data', - columns: - tableNode.cache - ?.selectedColumns, - data: oe, - }; - this.logger.log('data:', obj); - this.customViewData = undefined; - this.panel?.webview.postMessage(obj); - } - }); - } + this.handleQueryCommand(command, config); break; case CommandAction.CRUD: - if (config) { - ProcessorFactory.getProcessorInstance() - .getTableData( - config, - this.tableNode.tableName, - command.params - ) - .then((oe) => { - if (this.panel) { - const obj = { - id: command.id, - command: 'crud', - data: oe, - }; - this.logger.log('data:', obj); - this.panel?.webview.postMessage(obj); - } - }); - } + this.handleCRUDCommand(command, config); break; case CommandAction.Submit: - if (config) { - ProcessorFactory.getProcessorInstance() - .submitTableData( - config, - this.tableNode.tableName, - command.params - ) - .then((oe) => { - if (this.panel) { - const obj = { - id: command.id, - command: 'submit', - data: oe, - }; - this.logger.log('data:', obj); - if ( - obj.data.description !== null && - obj.data.description !== undefined - ) { - if (obj.data.description === '') { - vscode.window.showErrorMessage( - 'Database Error: Trigger canceled action' - ); - } else { - vscode.window.showErrorMessage( - 'Database Error: ' + - obj.data.description - ); - } - } else { - vscode.window.showInformationMessage( - 'Action was successful' - ); - } - this.panel?.webview.postMessage(obj); - } - }); - } + this.handleSubmitCommand(command, config); break; case CommandAction.Export: - if (!config) { - break; - } - ProcessorFactory.getProcessorInstance() - .getTableData( - config, - this.tableNode.tableName, - command.params - ) - .then((oe) => { - if (!this.panel) { - return; - } - if (!config) { - throw new Error( - 'Configuration became undefined unexpectedly.' - ); - } - let exportData = oe; - if (command.params?.exportType === 'dumpFile') { - const dumpFileFormatter = - new DumpFileFormatter(); - dumpFileFormatter.formatDumpFile( - oe, - this.tableNode.tableName, - config.label - ); - exportData = - dumpFileFormatter.getDumpFile(); - } - if (command.params !== undefined) { - const obj = { - id: command.id, - command: 'export', - tableName: this.tableNode.tableName, - data: exportData, - format: command.params.exportType, - }; - - this.logger.log('data:', obj); - this.panel?.webview.postMessage(obj); - } - }); + this.handleExportCommand(command, config); break; case CommandAction.SaveCustomQuery: - vscode.commands - .executeCommand( - `${Constants.globalExtensionKey}.saveCustomView`, - new CustomViewNode( - Constants.context, - this.tableNode, - command.customView?.name || '', - command.customView - ) - ) - .then( - () => { - console.log( - 'Command executed successfully' - ); - }, - (error) => { - console.error( - 'Error executing command:', - error - ); - } - ); + this.handleSaveCustomQueryCommand(command, config); break; } }, @@ -361,6 +205,164 @@ export class QueryEditor { this.panel?.webview.postMessage(obj); } + private handleQueryCommand(command: ICommand, config?: IConfig) { + if (!config) { + return; + } + + ProcessorFactory.getProcessorInstance() + .getTableData( + config, + this.tableNode.tableName, + this.customViewData + ? this.getParams(command.params!) + : command.params + ) + .then((oe) => { + if (this.customViewData) { + const obj = { + id: command.id, + command: 'customViewParams', + params: this.customViewData, + }; + this.logger.log('customView params: ', this.customViewData); + this.panel?.webview.postMessage(obj); + } + + if (this.panel) { + const obj = { + id: command.id, + command: 'data', + columns: this.tableNode.cache?.selectedColumns, + data: oe, + }; + this.logger.log('data:', obj); + this.customViewData = undefined; + this.panel?.webview.postMessage(obj); + } + }); + } + + private handleCRUDCommand(command: ICommand, config?: IConfig) { + if (!config) { + return; + } + + ProcessorFactory.getProcessorInstance() + .getTableData(config, this.tableNode.tableName, command.params) + .then((oe) => { + if (this.panel) { + const obj = { + id: command.id, + command: 'crud', + data: oe, + }; + this.logger.log('data:', obj); + this.panel?.webview.postMessage(obj); + } + }); + } + + private handleSubmitCommand(command: ICommand, config?: IConfig) { + if (!config) { + return; + } + + ProcessorFactory.getProcessorInstance() + .submitTableData(config, this.tableNode.tableName, command.params) + .then((oe) => { + if (this.panel) { + const obj = { + id: command.id, + command: 'submit', + data: oe, + }; + this.logger.log('data:', obj); + if ( + obj.data.description !== null && + obj.data.description !== undefined + ) { + if (obj.data.description === '') { + vscode.window.showErrorMessage( + 'Database Error: Trigger canceled action' + ); + } else { + vscode.window.showErrorMessage( + 'Database Error: ' + obj.data.description + ); + } + } else { + vscode.window.showInformationMessage( + 'Action was successful' + ); + } + this.panel?.webview.postMessage(obj); + } + }); + } + + private handleExportCommand(command: ICommand, config?: IConfig) { + if (!config) { + return; + } + + ProcessorFactory.getProcessorInstance() + .getTableData(config, this.tableNode.tableName, command.params) + .then((oe) => { + if (!this.panel) { + return; + } + if (!config) { + throw new Error( + 'Configuration became undefined unexpectedly.' + ); + } + let exportData = oe; + if (command.params?.exportType === 'dumpFile') { + const dumpFileFormatter = new DumpFileFormatter(); + dumpFileFormatter.formatDumpFile( + oe, + this.tableNode.tableName, + config.label + ); + exportData = dumpFileFormatter.getDumpFile(); + } + if (command.params !== undefined) { + const obj = { + id: command.id, + command: 'export', + tableName: this.tableNode.tableName, + data: exportData, + format: command.params.exportType, + }; + + this.logger.log('data:', obj); + this.panel?.webview.postMessage(obj); + } + }); + } + + private handleSaveCustomQueryCommand(command: ICommand, config?: IConfig) { + vscode.commands + .executeCommand( + `${Constants.globalExtensionKey}.saveCustomView`, + new CustomViewNode( + Constants.context, + this.tableNode, + command.customView?.name || '', + command.customView + ) + ) + .then( + () => { + console.log('Command executed successfully'); + }, + (error) => { + console.error('Error executing command:', error); + } + ); + } + private getWebviewContent(tableData: IOETableData): string { // Local path to main script run in the webview const reactAppPathOnDisk = vscode.Uri.file( From ed6b7ba338abac9f874146f945ce5834b3c395b6 Mon Sep 17 00:00:00 2001 From: Aldas Kleinas Date: Thu, 17 Apr 2025 14:07:46 +0300 Subject: [PATCH 4/5] 544 resolved typescript errors --- src/types/global.d.ts | 17 +++++++++++++++++ src/view/app/Fields/index.tsx | 7 ------- src/view/app/Indexes/index.tsx | 9 --------- src/view/app/utils/vscode.ts | 8 ++++---- 4 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 src/types/global.d.ts diff --git a/src/types/global.d.ts b/src/types/global.d.ts new file mode 100644 index 00000000..c8948f5f --- /dev/null +++ b/src/types/global.d.ts @@ -0,0 +1,17 @@ +import { ISettings } from "../common/IExtensionSettings"; +import { IOETableData } from "../db/Oe"; +import { IConfig } from "../view/app/model"; +import { VSCode } from "../view/app/utils/vscode"; + +declare global { + interface Window { + acquireVsCodeApi: () => VSCode; + configuration: ISettings; + initialData: IConfig; + tableData: IOETableData; + tableName: string; + isReadOnly: boolean; + } +} + +export {}; diff --git a/src/view/app/Fields/index.tsx b/src/view/app/Fields/index.tsx index fd5e0fe6..bbba9110 100644 --- a/src/view/app/Fields/index.tsx +++ b/src/view/app/Fields/index.tsx @@ -1,13 +1,6 @@ import { createRoot } from 'react-dom/client'; import './fields.css'; import Fields from './fields'; -import { VSCode } from '@utils/vscode'; - -declare global { - interface Window { - acquireVsCodeApi(): VSCode; - } -} const root = createRoot(document.getElementById('root')); root.render(); diff --git a/src/view/app/Indexes/index.tsx b/src/view/app/Indexes/index.tsx index 4687ba42..350b6592 100644 --- a/src/view/app/Indexes/index.tsx +++ b/src/view/app/Indexes/index.tsx @@ -1,15 +1,6 @@ import { createRoot } from 'react-dom/client'; import './indexes.css'; import Indexes from './indexes'; -import { ISettings } from '@src/common/IExtensionSettings'; -import { VSCode } from '@utils/vscode'; - -declare global { - interface Window { - acquireVsCodeApi(): VSCode; - configuration: ISettings; - } -} const root = createRoot(document.getElementById('root')); root.render(); diff --git a/src/view/app/utils/vscode.ts b/src/view/app/utils/vscode.ts index 3e133f8c..29d1d559 100644 --- a/src/view/app/utils/vscode.ts +++ b/src/view/app/utils/vscode.ts @@ -1,5 +1,5 @@ -import { ICommand } from '@app/model'; -import { ISettings } from '@src/common/IExtensionSettings'; +import { ISettings } from '../../../common/IExtensionSettings'; +import { ICommand } from '../model'; /** * Active interface for vscode api variable @@ -10,8 +10,8 @@ export interface VSCode { setState(state: any): void; } -let vsCodeAPI: VSCode = undefined; -let configuration: ISettings = undefined; +let vsCodeAPI: VSCode; +let configuration: ISettings; /** * method that returns the vsCodeAPI From 23d56e8268b5e3decae9697621379b187bdf6ee6 Mon Sep 17 00:00:00 2001 From: Aldas Kleinas Date: Tue, 13 May 2025 11:09:45 +0300 Subject: [PATCH 5/5] 544 removed unnecesarry comments improved formatting --- docker/openedge-project.json | 2 +- src/common/OpenEdgeJsonReaded.ts | 1 - src/view/app/Connection/connectionForm.tsx | 1 + src/view/app/Query/test.tsx | 8 -- src/view/app/utils/PfParser.ts | 3 - src/webview/ConnectionEditor.ts | 131 +++++++++++---------- 6 files changed, 74 insertions(+), 72 deletions(-) delete mode 100644 src/view/app/Query/test.tsx diff --git a/docker/openedge-project.json b/docker/openedge-project.json index 8db88284..0232dfc8 100644 --- a/docker/openedge-project.json +++ b/docker/openedge-project.json @@ -29,4 +29,4 @@ "numThreads": 1, "procedures": [], "profiles": [] -} \ No newline at end of file +} diff --git a/src/common/OpenEdgeJsonReaded.ts b/src/common/OpenEdgeJsonReaded.ts index bb555122..18508957 100644 --- a/src/common/OpenEdgeJsonReaded.ts +++ b/src/common/OpenEdgeJsonReaded.ts @@ -25,7 +25,6 @@ export function parseOEFile(fileContent: string, filePath: string) { const directoryPath = path.dirname(filePath); - console.warn('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'); dbConnections.forEach((connection: { name: string; connect: string }) => { const { name, connect } = connection; diff --git a/src/view/app/Connection/connectionForm.tsx b/src/view/app/Connection/connectionForm.tsx index 21392306..4eb902f1 100644 --- a/src/view/app/Connection/connectionForm.tsx +++ b/src/view/app/Connection/connectionForm.tsx @@ -64,6 +64,7 @@ function ConnectionForm({ type: vsState.config.type, isReadOnly: params.includes('-RO') || vsConfiguration.readOnlyMode, }; + console.warn('onSaveClick config', config); const command: ICommand = { id: id, action: CommandAction.Save, diff --git a/src/view/app/Query/test.tsx b/src/view/app/Query/test.tsx deleted file mode 100644 index a589992f..00000000 --- a/src/view/app/Query/test.tsx +++ /dev/null @@ -1,8 +0,0 @@ -function sample() -{ - return ( -
-

Sample

-
- ); -} \ No newline at end of file diff --git a/src/view/app/utils/PfParser.ts b/src/view/app/utils/PfParser.ts index 25cc71cf..a2764bd9 100644 --- a/src/view/app/utils/PfParser.ts +++ b/src/view/app/utils/PfParser.ts @@ -39,11 +39,8 @@ export class PfParser { '-crTXDisplay', '-Sn', ]; - console.warn('ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'); if (this.configuration) { - console.log('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ' + pfFile); if (this.configuration.readOnlyMode) { - console.log('AAAAAAAAAAAAAAAAAAAAAAAAAreadOnlyMode ' + pfFile); config.isReadOnly = true; } } diff --git a/src/webview/ConnectionEditor.ts b/src/webview/ConnectionEditor.ts index 6c512875..d15dc213 100644 --- a/src/webview/ConnectionEditor.ts +++ b/src/webview/ConnectionEditor.ts @@ -71,71 +71,19 @@ export class ConnectionEditor { this.panel.webview.onDidReceiveMessage( (command: ICommand) => { this.logger.log('command:', command); - let connections = this.context.globalState.get<{ - [id: string]: IConfig; - }>(`${Constants.globalExtensionKey}.dbconfig`); + const connections = + this.context.globalState.get<{ [id: string]: IConfig }>( + `${Constants.globalExtensionKey}.dbconfig` + ) ?? {}; switch (command.action) { case CommandAction.Save: - if (!this.isTestedSuccessfully) { - vscode.window.showInformationMessage( - 'Connection should be tested before saving.' - ); - return; - } else if (!connections) { - connections = {}; - } else if (command.content) { - connections[command.content.id] = command.content; - this.context.globalState.update( - `${Constants.globalExtensionKey}.dbconfig`, - connections - ); - vscode.window.showInformationMessage( - 'Connection saved successfully.' - ); - this.panel?.dispose(); - vscode.commands.executeCommand( - `${Constants.globalExtensionKey}.refreshList` - ); - } + this.handleSaveAction(command, connections); return; case CommandAction.Test: - if (command.content) { - ProcessorFactory.getProcessorInstance() - .getDBVersion(command.content) - .then((oe) => { - if (oe.error) { - vscode.window.showErrorMessage( - `Error connecting DB: ${oe.description} (${oe.error})` - ); - } else { - this.logger.log( - 'Requested version of DB', - oe.dbversion - ); - vscode.window.showInformationMessage( - 'Connection OK' - ); - this.isTestedSuccessfully = true; - } - }); - } + this.handleTestAction(command); return; case CommandAction.Group: - if (connections) { - const uniqueGroups = new Set(); // Specify that the Set will contain strings - - for (const id of Object.keys(connections)) { - const group = - connections[id].group.toUpperCase(); - uniqueGroups.add(group); - } - - const groupNames: string[] = - Array.from(uniqueGroups); - - this.groupList(groupNames); - } - + this.handleGroupAction(command, connections); return; } }, @@ -152,6 +100,71 @@ export class ConnectionEditor { ); } + private handleSaveAction( + command: ICommand, + connections: { [id: string]: IConfig } + ) { + if (!this.isTestedSuccessfully) { + vscode.window.showInformationMessage( + 'Connection should be tested before saving.' + ); + return; + } else if (command.content) { + console.warn('command.content', command.content); + connections[command.content.id] = command.content; + this.context.globalState.update( + `${Constants.globalExtensionKey}.dbconfig`, + connections + ); + vscode.window.showInformationMessage( + 'Connection saved successfully.' + ); + this.panel?.dispose(); + vscode.commands.executeCommand( + `${Constants.globalExtensionKey}.refreshList` + ); + } + } + + private handleTestAction(command: ICommand) { + if (!command.content) { + return; + } + ProcessorFactory.getProcessorInstance() + .getDBVersion(command.content) + .then((oe) => { + if (oe.error) { + vscode.window.showErrorMessage( + `Error connecting DB: ${oe.description} (${oe.error})` + ); + } else { + this.logger.log('Requested version of DB', oe.dbversion); + vscode.window.showInformationMessage('Connection OK'); + this.isTestedSuccessfully = true; + } + }); + } + + private handleGroupAction( + command: ICommand, + connections: { [id: string]: IConfig } + ) { + if (!connections) { + return; + } + + const uniqueGroups = new Set(); // Specify that the Set will contain strings + + for (const id of Object.keys(connections)) { + const group = connections[id].group.toUpperCase(); + uniqueGroups.add(group); + } + + const groupNames: string[] = Array.from(uniqueGroups); + + this.groupList(groupNames); + } + private groupList(groupNames: string[]) { const obj = { command: 'group',