dbeaver/pro#8515 sync properties state (#4214)

* dbeaver/pro#8515 sync properties state

* dbeaver/pro#8515 fixed null to empty strings props conversion

* dbeaver/pro#8515 do not send property if its in default value

* Revert "dbeaver/pro#8515 fixed null to empty strings props conversion"

This reverts commit 5c4f181edf.

* dbeaver/pro#8515 fix firefox icon

* dbeaver/pro#8515 change prop order

* dbeaver/pro#8515 add comment

---------

Co-authored-by: Dmitrii Barnukov <dmitrii.barnukov@dbeaver.com>
Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com>
Co-authored-by: sergeyteleshev <iamsergeyteleshev@gmail.com>
This commit is contained in:
alex
2026-03-17 17:35:45 +01:00
committed by GitHub
co-authored by Dmitrii Barnukov Daria Marutkina mr-anton-t sergeyteleshev
parent 296e03ec74
commit 33d1d97fb7
4 changed files with 34 additions and 14 deletions
@@ -99,8 +99,8 @@ export const PropertyItem = observer<Props>(function PropertyItem({
<ActionIconButton
title={translate('core_blocks_properties_table_item_reset')}
name="/icons/data_revert_all_sm.svg"
viewBox="0 0 16 16"
type="button"
img
onClick={handleRevert}
/>
)}
@@ -108,7 +108,6 @@ export const PropertyItem = observer<Props>(function PropertyItem({
<ActionIconButton
title={translate('core_blocks_properties_table_item_remove')}
name="reject"
viewBox="0 0 11 11"
type="button"
onClick={handleRemove}
/>
@@ -36,13 +36,7 @@ fragment DatabaseDriver on DriverInfo {
}
driverProperties @include(if: $includeDriverProperties) {
id
displayName
description
category
dataType
defaultValue
validValues
...DriverPropertyInfo
}
driverParameters @include(if: $includeDriverParameters)
}
@@ -7,11 +7,12 @@
*/
import { FormPart, type IFormState } from '@cloudbeaver/core-ui';
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
import { CONNECTION_PROPERTIES_SCHEMA, ConnectionInfoPropertiesResource } from '@cloudbeaver/core-connections';
import { CONNECTION_PROPERTIES_SCHEMA, ConnectionInfoPropertiesResource, DBDriverResource } from '@cloudbeaver/core-connections';
import type { IConnectionFormState } from '../IConnectionFormState.js';
import { runInAction, toJS } from 'mobx';
import type { ConnectionFormOptionsPart } from '../Options/ConnectionFormOptionsPart.js';
import type { schema } from '@cloudbeaver/core-utils';
import { getObjectPropertyOptionValue } from '@cloudbeaver/core-sdk';
type ConnectionProperties = schema.infer<typeof CONNECTION_PROPERTIES_SCHEMA>;
@@ -23,6 +24,7 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<ConnectionPrope
constructor(
formState: IFormState<IConnectionFormState>,
private readonly connectionInfoPropertiesResource: ConnectionInfoPropertiesResource,
private readonly dbDriverResource: DBDriverResource,
private readonly optionsPart: ConnectionFormOptionsPart,
) {
super(formState, getDefaultState());
@@ -69,10 +71,10 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<ConnectionPrope
contexts: IExecutionContextProvider<IFormState<IConnectionFormState>>,
): Promise<void> {}
protected override format(
protected override async format(
data: IFormState<IConnectionFormState>,
contexts: IExecutionContextProvider<IFormState<IConnectionFormState>>,
): void | Promise<void> {
): Promise<void> {
runInAction(() => {
for (const key of Object.keys(this.state!)) {
if (typeof this.state[key] === 'string') {
@@ -80,5 +82,29 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<ConnectionPrope
}
}
});
this.optionsPart.state.properties = await this.getPropertiesConfig();
}
private async getPropertiesConfig() {
const config = toJS(this.state);
if (!this.optionsPart.state.driverId) {
return config;
}
const properties = await this.dbDriverResource.load(this.optionsPart.state.driverId, ['includeDriverProperties']);
/* Default property values must not be returned. If they are included in the request, the backend will send them back with modified values (e.g., null converted to an empty string).
To avoid this behavior, only properties that were explicitly changed should be sent. Any properties that still contain default values must be removed from the object before sending the request
*/
for (const [key, value] of Object.entries(config)) {
const property = properties?.driverProperties.find(property => property.id === key);
if (property && value === getObjectPropertyOptionValue(property.defaultValue)) {
delete config[key];
}
}
return config;
}
}
@@ -8,7 +8,7 @@
import { createDataContext, DATA_CONTEXT_DI_PROVIDER } from '@cloudbeaver/core-data-context';
import type { IFormState } from '@cloudbeaver/core-ui';
import { ConnectionFormDriverPropertiesPart } from './ConnectionFormDriverPropertiesPart.js';
import { ConnectionInfoPropertiesResource } from '@cloudbeaver/core-connections';
import { ConnectionInfoPropertiesResource, DBDriverResource } from '@cloudbeaver/core-connections';
import type { IConnectionFormState } from '../IConnectionFormState.js';
import { getConnectionFormOptionsPart } from '../Options/getConnectionFormOptionsPart.js';
@@ -21,7 +21,8 @@ export function getConnectionFormDriverPropertiesPart(formState: IFormState<ICon
const di = context.get(DATA_CONTEXT_DI_PROVIDER)!;
const connectionInfoPropertiesResource = di.getService(ConnectionInfoPropertiesResource);
const optionsPart = getConnectionFormOptionsPart(formState);
const dbDriverResource = di.getService(DBDriverResource);
return new ConnectionFormDriverPropertiesPart(formState, connectionInfoPropertiesResource, optionsPart);
return new ConnectionFormDriverPropertiesPart(formState, connectionInfoPropertiesResource, dbDriverResource, optionsPart);
});
}