dbeaver/pro#10177 pass defaults to main properties (#4538)

* dbeaver/pro#10177 pass defaults to main properties

* dbeaver/pro#10177 postpone state init

---------

Co-authored-by: Evgenia <139753579+EvgeniaBzzz@users.noreply.github.com>
Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com>
This commit is contained in:
alex
2026-08-20 12:08:16 +02:00
committed by GitHub
co-authored by Evgenia mr-anton-t
parent d48cd7a0a7
commit 3e9e71ca6d
3 changed files with 46 additions and 13 deletions
@@ -49,11 +49,11 @@ const MAIN_PROPERTY_HOST_KEY = 'host';
const MAIN_PROPERTY_PORT_KEY = 'port';
const MAIN_PROPERTY_SERVER_KEY = 'server';
const defaultStateGetter = (connectionId?: string, credentials?: Record<string, any>) =>
const defaultStateGetter = (connectionId?: string) =>
({
connectionId,
configurationType: DriverConfigurationType.Manual,
credentials: credentials ?? {},
credentials: {},
mainPropertyValues: {},
expertSettingsValues: {},
networkHandlersConfig: [],
@@ -185,14 +185,12 @@ export class ConnectionFormOptionsPart extends FormPart<IConnectionFormOptionsSt
protected override async loader(): Promise<void> {
if (this.formState.mode === 'create') {
const credentials = this.state.authModelId
? getObjectPropertyDefaults(await this.getConnectionAuthModelProperties(this.state.authModelId))
: undefined;
this.setInitialState(defaultStateGetter(this.initialState.connectionId ?? this.formState.state.connectionId, credentials));
const defaults = await this.getDefaults();
await this.setDriverId(this.state.driverId);
this.setInitialState(defaults);
return;
}
@@ -340,6 +338,37 @@ export class ConnectionFormOptionsPart extends FormPart<IConnectionFormOptionsSt
this.state.authModelId = modelId;
}
private async getDefaults() {
const defaults = defaultStateGetter(this.initialState.connectionId ?? this.formState.state.connectionId);
const config = toJS({ ...defaults, ...this.state });
if (this.state.driverId) {
config.driverId = this.state.driverId;
}
if (this.state.authModelId) {
const authProperties = await this.getConnectionAuthModelProperties(this.state.authModelId);
config.credentials = getObjectPropertyDefaults(authProperties);
}
if (config.driverId) {
const driver = await this.dbDriverResource.load(config.driverId, ['includeMainProperties']);
if (config.mainPropertyValues) {
for (const property of driver.mainProperties) {
// We don't use getObjectPropertyDefaults because, in this case, the backend returns default values in the value field.
const value = getObjectPropertyDefaultValue(property) || getObjectPropertyValue(property);
if (property.id) {
config.mainPropertyValues[property.id] = value;
}
}
}
}
return config;
}
protected override async format(
data: IFormState<IConnectionFormState>,
contexts: IExecutionContextProvider<IFormState<IConnectionFormState>>,
@@ -113,7 +113,7 @@ export const Options: TabContainerPanelComponent<IConnectionFormProps> = observe
const driverMap = useResource(Options, DBDriverResource, {
key: optionsPart.state.driverId || null,
includes: ['includeProviderProperties', 'includeMainProperties', 'includeDriverProperties'] as const,
includes: ['includeProviderProperties', 'includeMainProperties'] as const,
});
const driver = driverMap.data;
@@ -83,7 +83,8 @@ export class PublicConnectionFormService {
async change(projectId: string, config: ConnectionConfig, availableDrivers?: string[]): Promise<void> {
this.formState?.dispose();
this.formState = new ConnectionFormState(this.serviceProvider, this.connectionFormService, {
const formState = new ConnectionFormState(this.serviceProvider, this.connectionFormService, {
projectId,
availableDrivers: availableDrivers ?? [],
type: 'public',
@@ -91,15 +92,18 @@ export class PublicConnectionFormService {
connectionId: config.connectionId,
}).setMode(config.connectionId ? FormMode.Edit : FormMode.Create);
await this.optionsPart?.load();
const optionsPart = getConnectionFormOptionsPart(formState);
if (config.driverId) {
await this.optionsPart?.setDriverId(config.driverId);
await optionsPart.setDriverId(config.driverId);
}
Object.assign(this.optionsPart!.state, config);
await optionsPart.load();
this.formState.disposeTask.addHandler(this.close.bind(this, true));
Object.assign(optionsPart.state, config);
formState.disposeTask.addHandler(this.close.bind(this, true));
this.formState = formState;
}
async open(projectId: string, config: ConnectionConfig, availableDrivers?: string[]): Promise<boolean> {