diff --git a/webapp/packages/core-connections/src/CONNECTION_INFO_PARAM_SCHEMA.ts b/webapp/packages/core-connections/src/CONNECTION_INFO_PARAM_SCHEMA.ts index 96ec0e63de..193e981571 100644 --- a/webapp/packages/core-connections/src/CONNECTION_INFO_PARAM_SCHEMA.ts +++ b/webapp/packages/core-connections/src/CONNECTION_INFO_PARAM_SCHEMA.ts @@ -7,6 +7,7 @@ */ import { schema } from '@cloudbeaver/core-utils'; +// // TODO add here driverId, submitType export const CONNECTION_INFO_PARAM_SCHEMA = schema .object({ projectId: schema.string(), diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionDriverPropertiesTabService.ts b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionDriverPropertiesTabService.ts index dd932d3f43..2b4dbc87b7 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionDriverPropertiesTabService.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionDriverPropertiesTabService.ts @@ -24,6 +24,7 @@ export class ConnectionDriverPropertiesTabService extends Bootstrap { constructor( private readonly connectionFormService: ConnectionFormService, private readonly dbDriverResource: DBDriverResource, + // private readonly connectionFormServiceRefactored: ConnectionFormServiceRefactored, ) { super(); @@ -47,6 +48,28 @@ export class ConnectionDriverPropertiesTabService extends Bootstrap { }, }); + // TODO uncomment once refactored + // this.connectionFormServiceRefactored.parts.add({ + // key: 'driver_properties', + // name: 'plugin_connections_connection_form_part_properties', + // title: 'plugin_connections_connection_form_part_properties', + // order: 2, + // panel: () => DriverPropertiesLoader, + // isDisabled: (tabId, props) => { + // if (!props?.formState) { + // return true; + // } + + // const optionsPart = getConnectionFormOptionsPart(props.formState); + + // if (optionsPart.state.connectionConfig.driverId) { + // return !optionsPart.state.connectionConfig.driverId; + // } + + // return true; + // }, + // }); + this.connectionFormService.prepareConfigTask.addHandler(this.prepareConfig.bind(this)); this.connectionFormService.formStateTask.addHandler(this.formState.bind(this)); @@ -56,6 +79,7 @@ export class ConnectionDriverPropertiesTabService extends Bootstrap { this.connectionFormService.configureTask.addHandler(this.configure.bind(this)); } + // TODO include this private configure(data: IConnectionFormState, contexts: IExecutionContextProvider) { const configuration = contexts.getContext(connectionFormConfigureContext); diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionFormDriverPropertiesPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionFormDriverPropertiesPart.ts new file mode 100644 index 0000000000..b67e4ad53b --- /dev/null +++ b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/ConnectionFormDriverPropertiesPart.ts @@ -0,0 +1,71 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2025 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 { FormPart, type IFormState } from '@cloudbeaver/core-ui'; +import { type IConnectionFormRefactoredState } from '../ConnectionFormServiceRefactored.js'; +import type { IConnectionFromDriverPropertiesState } from './IConnectionFromDriverPropertiesState.js'; +import type { IExecutionContextProvider } from '@cloudbeaver/core-executor'; +import type { ConnectionInfoResource, DBDriverResource } from '@cloudbeaver/core-connections'; +import { getConnectionFormOptionsPart } from '../Options/getConnectionFormOptionsPart.js'; + +const getDefaultState = () => + ({ + properties: {}, + }) as IConnectionFromDriverPropertiesState; + +export class ConnectionFormDriverPropertiesPart extends FormPart { + constructor( + formState: IFormState, + private readonly connectionInfoResource: ConnectionInfoResource, + private readonly dbDriverResource: DBDriverResource, + ) { + super(formState, getDefaultState()); + } + + protected override async loader(): Promise { + const info = await this.connectionInfoResource.load({ + connectionId: this.formState.state.connectionInfoParams.connectionId, + projectId: this.formState.state.connectionInfoParams.projectId, + }); + + this.setInitialState({ + properties: info?.properties, + }); + } + + protected override saveChanges( + data: IFormState, + contexts: IExecutionContextProvider>, + ): Promise { + return Promise.resolve(); + } + + protected override format( + data: IFormState, + contexts: IExecutionContextProvider>, + ): void | Promise { + const optionsPart = getConnectionFormOptionsPart(this.formState); + const config = optionsPart.state.connectionConfig; + + // TODO move driverId to formState + if (config.driverId) { + const driver = this.dbDriverResource.get(config.driverId); + const defaultDriverProperties = new Set(driver?.driverProperties?.map(property => property.id) ?? []); + + for (let key of Object.keys(this.state.properties)) { + const value = this.state.properties[key]; + if (!defaultDriverProperties?.has(key)) { + key = key.trim(); + } + + this.state.properties[key] = typeof value === 'string' ? value.trim() : value; + } + + config.properties = { ...this.state.properties }; + } + } +} diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/IConnectionFromDriverPropertiesState.ts b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/IConnectionFromDriverPropertiesState.ts new file mode 100644 index 0000000000..6ff682e658 --- /dev/null +++ b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/IConnectionFromDriverPropertiesState.ts @@ -0,0 +1,14 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2025 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 { schema } from '@cloudbeaver/core-utils'; + +export const CONNECTION_FORM_DRIVER_PROPERTIES_SCHEMA = schema.object({ + properties: schema.record(schema.string(), schema.string().optional()), +}); + +export type IConnectionFromDriverPropertiesState = schema.infer; diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/getConnectionFormDriverPropertiesPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/getConnectionFormDriverPropertiesPart.ts new file mode 100644 index 0000000000..cf70daae3d --- /dev/null +++ b/webapp/packages/plugin-connections/src/ConnectionForm/DriverProperties/getConnectionFormDriverPropertiesPart.ts @@ -0,0 +1,26 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2025 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, DATA_CONTEXT_DI_PROVIDER } from '@cloudbeaver/core-data-context'; +import type { IFormState } from '@cloudbeaver/core-ui'; +import type { IConnectionFormRefactoredState } from '../ConnectionFormServiceRefactored.js'; +import { ConnectionFormDriverPropertiesPart } from './ConnectionFormDriverPropertiesPart.js'; +import { ConnectionInfoResource, DBDriverResource } from '@cloudbeaver/core-connections'; + +const DATA_CONTEXT_CONNECTION_FORM_DRIVER_PROPERTIES_PART = createDataContext( + 'Connection Form Driver Properties Part', +); + +export function getConnectionFormSSHPart(formState: IFormState): ConnectionFormDriverPropertiesPart { + return formState.getPart(DATA_CONTEXT_CONNECTION_FORM_DRIVER_PROPERTIES_PART, context => { + const di = context.get(DATA_CONTEXT_DI_PROVIDER)!; + const connectionInfoResource = di.getService(ConnectionInfoResource); + const dbDriverResource = di.getService(DBDriverResource); + + return new ConnectionFormDriverPropertiesPart(formState, connectionInfoResource, dbDriverResource); + }); +} diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/Options/getConnectionFormOptionsPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/Options/getConnectionFormOptionsPart.ts index da26152d0e..b5f2e16985 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/Options/getConnectionFormOptionsPart.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/Options/getConnectionFormOptionsPart.ts @@ -14,7 +14,7 @@ import { ProjectInfoResource } from '@cloudbeaver/core-projects'; import { AuthProvidersResource, UserInfoResource } from '@cloudbeaver/core-authentication'; import { LocalizationService } from '@cloudbeaver/core-localization'; -const DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART = createDataContext('Connection Options Form Part'); +const DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART = createDataContext('Connection Form Options Part'); export function getConnectionFormOptionsPart(formState: IFormState): ConnectionFormOptionsPart { return formState.getPart(DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART, context => { diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/SSH/getConnectionFormSSHPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/SSH/getConnectionFormSSHPart.ts index a7a55adb4c..8496514d2c 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/SSH/getConnectionFormSSHPart.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/SSH/getConnectionFormSSHPart.ts @@ -11,7 +11,7 @@ import { ConnectionFormSSHPart } from './ConnectionFormSSHPart.js'; import type { IConnectionFormRefactoredState } from '../ConnectionFormServiceRefactored.js'; import { ConnectionInfoResource } from '@cloudbeaver/core-connections'; -const DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART = createDataContext('Connection Options Form Part'); +const DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART = createDataContext('Connection Form SSH Part'); export function getConnectionFormSSHPart(formState: IFormState): ConnectionFormSSHPart { return formState.getPart(DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART, context => {