CB-4067 adds driver properties part

This commit is contained in:
sergeyteleshev
2025-02-25 13:53:01 +01:00
parent 04d8d71731
commit eecf63a802
7 changed files with 138 additions and 2 deletions
@@ -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(),
@@ -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<IConnectionFormState>) {
const configuration = contexts.getContext(connectionFormConfigureContext);
@@ -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<IConnectionFromDriverPropertiesState, IConnectionFormRefactoredState> {
constructor(
formState: IFormState<IConnectionFormRefactoredState>,
private readonly connectionInfoResource: ConnectionInfoResource,
private readonly dbDriverResource: DBDriverResource,
) {
super(formState, getDefaultState());
}
protected override async loader(): Promise<void> {
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<IConnectionFormRefactoredState>,
contexts: IExecutionContextProvider<IFormState<IConnectionFormRefactoredState>>,
): Promise<void> {
return Promise.resolve();
}
protected override format(
data: IFormState<IConnectionFormRefactoredState>,
contexts: IExecutionContextProvider<IFormState<IConnectionFormRefactoredState>>,
): void | Promise<void> {
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 };
}
}
}
@@ -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<typeof CONNECTION_FORM_DRIVER_PROPERTIES_SCHEMA>;
@@ -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<ConnectionFormDriverPropertiesPart>(
'Connection Form Driver Properties Part',
);
export function getConnectionFormSSHPart(formState: IFormState<IConnectionFormRefactoredState>): 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);
});
}
@@ -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<ConnectionFormOptionsPart>('Connection Options Form Part');
const DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART = createDataContext<ConnectionFormOptionsPart>('Connection Form Options Part');
export function getConnectionFormOptionsPart(formState: IFormState<IConnectionFormRefactoredState>): ConnectionFormOptionsPart {
return formState.getPart(DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART, context => {
@@ -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<ConnectionFormSSHPart>('Connection Options Form Part');
const DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART = createDataContext<ConnectionFormSSHPart>('Connection Form SSH Part');
export function getConnectionFormSSHPart(formState: IFormState<IConnectionFormRefactoredState>): ConnectionFormSSHPart {
return formState.getPart(DATA_CONTEXT_CONNECTION_FORM_OPTIONS_PART, context => {