diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/ConnectionForm.tsx b/webapp/packages/plugin-connections/src/ConnectionForm/ConnectionForm.tsx index 360e106d7f..70daf9eeb9 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/ConnectionForm.tsx +++ b/webapp/packages/plugin-connections/src/ConnectionForm/ConnectionForm.tsx @@ -19,7 +19,7 @@ import type { ConnectionFormState } from './ConnectionFormState.js'; import { getFirstException } from '@cloudbeaver/core-utils'; import { ConnectionFormService } from './ConnectionFormService.js'; import { ConnectionInfoResource, createConnectionParam } from '@cloudbeaver/core-connections'; -import { connectionTestContext } from './Contexts/connectionTestContext.js'; +import { connectionTestContext, type IConnectionTestContext } from './Contexts/connectionTestContext.js'; export interface ConnectionFormProps { formState: ConnectionFormState; @@ -70,6 +70,24 @@ export const ConnectionForm = observer(function ConnectionF onCancel, })); + function getTestMessageInfo(testContext: IConnectionTestContext) { + let message = ''; + + if (testContext.clientVersion) { + message += 'Client version: ' + testContext.clientVersion + '\n'; + } + + if (testContext.serverVersion) { + message += 'Server version: ' + testContext.serverVersion + '\n'; + } + + if (testContext.connectTime) { + message += 'Connection time: ' + testContext.connectTime + '\n'; + } + + return message; + } + useExecutor({ executor: formState.submitTask, postHandlers: [ @@ -77,18 +95,13 @@ export const ConnectionForm = observer(function ConnectionF const validation = contexts.getContext(formValidationContext); const state = contexts.getContext(formStatusContext); const testContext = contexts.getContext(connectionTestContext); + const message = getTestMessageInfo(testContext); - if (data.state.submitType === 'test' && !data.isError) { + if (data.state.submitType === 'test' && !data.isError && message.length) { notificationService.notify( { title: 'Connection is established', - message: - 'Client version: ' + - testContext.clientVersion + - '\nServer version: ' + - testContext.serverVersion + - '\nConnection time: ' + - testContext.connectTime, + message, }, ENotificationType.Success, ); diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionCredentialsStateContext.ts b/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionCredentialsStateContext.ts deleted file mode 100644 index 8884ee9241..0000000000 --- a/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionCredentialsStateContext.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others - * - * Licensed under the Apache License, Version 2.0. - * you may not use this file except in compliance with the License. - */ - -interface IConnectionCredentialsState { - authModelId: string | null; - networkHandlers: string[]; -} - -interface IConnectionCredentialsStateContext extends IConnectionCredentialsState { - requireAuthModel: (id: string) => void; - requireNetworkHandler: (id: string) => void; -} - -export function connectionCredentialsStateContext(): IConnectionCredentialsStateContext { - return { - authModelId: null, - networkHandlers: [], - requireAuthModel(id) { - this.authModelId = id; - }, - requireNetworkHandler(id) { - this.networkHandlers.push(id); - }, - }; -} diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionTestContext.ts b/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionTestContext.ts index 4d23b208b0..b717d2b515 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionTestContext.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/Contexts/connectionTestContext.ts @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. */ -interface IConnectionTestContext { +export interface IConnectionTestContext { clientVersion: string | null; serverVersion: string | null; connectTime: string | null; diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOpitonsPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOpitonsPart.ts index 7502ed0ae7..c357463f4a 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOpitonsPart.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOpitonsPart.ts @@ -20,15 +20,16 @@ import { } from '@cloudbeaver/core-connections'; import type { ProjectInfoResource } from '@cloudbeaver/core-projects'; import { AUTH_PROVIDER_LOCAL_ID, AuthProvidersResource, UserInfoResource } from '@cloudbeaver/core-authentication'; -import { toJS } from 'mobx'; +import { observable, runInAction, toJS } from 'mobx'; import { getUniqueName, isNotNullDefined } from '@cloudbeaver/core-utils'; import { getDefaultConfigurationType } from './getDefaultConfigurationType.js'; import { getConnectionName } from './getConnectionName.js'; import type { LocalizationService } from '@cloudbeaver/core-localization'; -import { connectionCredentialsStateContext } from '../Contexts/connectionCredentialsStateContext.js'; import type { IConnectionFormOptionsState } from './IConnectionFormOptionsState.js'; import type { IConnectionFormState } from '../IConnectionFormState.js'; import { connectionTestContext } from '../Contexts/connectionTestContext.js'; +import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dialogs'; +import { ConnectionAuthenticationDialogLoader } from '../../ConnectionAuthentication/ConnectionAuthenticationDialogLoader.js'; const MAIN_PROPERTY_DATABASE_KEY = 'database'; const MAIN_PROPERTY_HOST_KEY = 'host'; @@ -77,8 +78,11 @@ export class ConnectionFormOptionsPart extends FormPart>) { @@ -109,6 +113,44 @@ export class ConnectionFormOptionsPart extends FormPart, contexts: IExecutionContextProvider>) { + const authModelId = this.state.authModelId ?? this.formState.state.config.authModelId ?? null; + const networkHandlers = this.state.networkHandlersConfig ?? []; + + if (data.state.submitType !== 'test' || (!authModelId && !networkHandlers.length)) { + return; + } + + runInAction(() => { + if (authModelId) { + if (!this.state.credentials) { + this.state.credentials = { ...this.formState.state.config.credentials }; + } + + this.state.credentials = observable(this.state.credentials); + } + + if (networkHandlers.length > 0) { + if (!this.state.networkHandlersConfig) { + this.state.networkHandlersConfig = toJS(this.formState.state.config.networkHandlersConfig) || []; + } + + this.state.networkHandlersConfig = observable(this.state.networkHandlersConfig); + } + }); + + const result = await this.commonDialogService.open(ConnectionAuthenticationDialogLoader, { + config: this.state, + authModelId: authModelId, + networkHandlers: networkHandlers.map(handler => handler.id), + projectId: this.formState.state.projectId, + }); + + if (result === DialogueStateResult.Rejected) { + ExecutorInterrupter.interrupt(contexts); + } + } + protected override async loader(): Promise { if (this.formState.mode === 'create') { await this.setDefaults(); @@ -224,8 +266,6 @@ export class ConnectionFormOptionsPart extends FormPart, contexts: IExecutionContextProvider>, ): Promise { - const credentialsState = contexts.getContext(connectionCredentialsStateContext); - if (!this.state.driverId || !this.formState.state.projectId) { return; } @@ -283,7 +323,7 @@ export class ConnectionFormOptionsPart extends FormPart('Connection Form Options Part'); @@ -27,6 +28,7 @@ export function getConnectionFormOptionsPart(formState: IFormState, contexts: IExecutionContextProvider>, ): void | Promise { - const credentialsState = contexts.getContext(connectionCredentialsStateContext); const optionsPart = getConnectionFormOptionsPart(this.formState); const urlType = optionsPart.state.configurationType === DriverConfigurationType.Url; @@ -87,11 +85,7 @@ export class ConnectionFormSSHPart extends FormPart h.id === SSH_TUNNEL_ID); diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/SSL/ConnectionFormSSLPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/SSL/ConnectionFormSSLPart.ts index 1ef7ce0133..1e30c27d05 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/SSL/ConnectionFormSSLPart.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/SSL/ConnectionFormSSLPart.ts @@ -20,7 +20,6 @@ import { } from '@cloudbeaver/core-connections'; import { CachedMapAllKey } from '@cloudbeaver/core-resource'; import { toJS } from 'mobx'; -import { connectionCredentialsStateContext } from '../Contexts/connectionCredentialsStateContext.js'; import { PROPERTY_FEATURE_SECURED } from './PROPERTY_FEATURE_SECURED.js'; import { SSL_CODE_NAME } from './SSL_CODE_NAME.js'; import type { INetworkHandlerConfig } from '../Options/IConnectionNetworkHanler.js'; @@ -79,7 +78,6 @@ export class ConnectionFormSSLPart extends FormPart, contexts: IExecutionContextProvider>, ): Promise { - const credentialsState = contexts.getContext(connectionCredentialsStateContext); const optionsPart = getConnectionFormOptionsPart(this.formState); if (!this.isChanged || !this.formState.state.config.driverId) { @@ -138,11 +136,7 @@ export class ConnectionFormSSLPart extends FormPart (handlerConfig.id || SSL_CODE_NAME) === h.id); diff --git a/webapp/packages/plugin-connections/src/index.ts b/webapp/packages/plugin-connections/src/index.ts index d39f0b7ad4..b9e5f12a7d 100644 --- a/webapp/packages/plugin-connections/src/index.ts +++ b/webapp/packages/plugin-connections/src/index.ts @@ -13,7 +13,6 @@ export * from './ConnectionForm/Options/ConnectionOptionsTabService.js'; export * from './ConnectionForm/DriverProperties/ConnectionDriverPropertiesTabService.js'; export * from './ConnectionForm/SSH/ConnectionSSHTabService.js'; export * from './ConnectionForm/OriginInfo/ConnectionOriginInfoTabService.js'; -export * from './ConnectionForm/Contexts/connectionCredentialsStateContext.js'; export * from './ConnectionForm/ConnectionFormBaseActionsLoader.js'; export * from './ConnectionForm/ConnectionFormLoader.js'; export * from './ConnectionForm/IConnectionFormState.js';