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/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 45964db7..434219ba 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 (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 2ce31e81..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 = () => { @@ -218,6 +223,7 @@ export async function activate(context: vscode.ExtensionContext) { }); function createJsonDatabases(uri: vscode.Uri) { + console.warn('VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV'); allFileContent = readFile(uri.fsPath); const configs = parseOEFile(allFileContent, uri.fsPath); 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/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/Connection/connectionForm.tsx b/src/view/app/Connection/connectionForm.tsx index 3137bf0d..4eb902f1 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,8 +62,9 @@ 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, }; + console.warn('onSaveClick config', config); const command: ICommand = { id: id, action: CommandAction.Save, @@ -109,7 +115,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/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/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/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/utils/PfParser.ts b/src/view/app/utils/PfParser.ts index dcedfc86..a2764bd9 100644 --- a/src/view/app/utils/PfParser.ts +++ b/src/view/app/utils/PfParser.ts @@ -1,6 +1,9 @@ import { IConfig } from '../model'; +import { getVSCodeConfiguration } from './vscode'; export class PfParser { + private readonly configuration = getVSCodeConfiguration(); + public parse(pfFile: string): IConfig { const config: IConfig = { id: 'connection', @@ -36,6 +39,11 @@ export class PfParser { '-crTXDisplay', '-Sn', ]; + if (this.configuration) { + if (this.configuration.readOnlyMode) { + config.isReadOnly = true; + } + } pfFile .split('\n') 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 diff --git a/src/webview/ConnectionEditor.ts b/src/webview/ConnectionEditor.ts index 2807b0dd..d15dc213 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 @@ -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.isTestedSuccesfully) { - 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 succesfully.' - ); - 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.isTestedSuccesfully = 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', diff --git a/src/webview/QueryEditor.ts b/src/webview/QueryEditor.ts index 9bac80ee..ad76329c 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 ); @@ -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,177 +111,21 @@ 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: - tableNode.cache - ?.selectedColumns, - 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) { + case CommandAction.Query: + this.handleQueryCommand(command, config); + break; + case CommandAction.CRUD: + this.handleCRUDCommand(command, config); + break; + case CommandAction.Submit: + this.handleSubmitCommand(command, config); + break; + case CommandAction.Export: + this.handleExportCommand(command, config); + break; + case CommandAction.SaveCustomQuery: + this.handleSaveCustomQueryCommand(command, 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 - ) - ) - .then( - () => { - console.log( - 'Command executed successfully' - ); - }, - (error) => { - console.error( - 'Error executing command:', - error - ); - } - ); - break; } }, undefined, @@ -308,7 +148,7 @@ export class QueryEditor { } public setParams = (node: CustomViewNode): void => { - this.customViewData = node.customViewParams; + this.customViewData = node.customViewParams; }; public resetParams = (): void => { @@ -325,7 +165,6 @@ export class QueryEditor { }; }; - public getParams = (params: ITableData): ITableData => { if (!this.customViewData) { return params; @@ -366,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(