mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-16 14:50:15 +08:00
dbeaver/pro#9515 pass default values
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
import { computed } from 'mobx';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useCallback, useDeferredValue, useMemo, useState } from 'react';
|
||||
|
||||
import { getObjectPropertyOptionValue } from '@cloudbeaver/core-sdk';
|
||||
import { isNotNullDefined } from '@dbeaver/js-helpers';
|
||||
@@ -47,6 +47,7 @@ export const PropertiesTable = observer<Props>(function PropertiesTable(props) {
|
||||
const style = useS(styles);
|
||||
|
||||
const [filterValue, setFilterValue] = useState('');
|
||||
const deferredFilterValue = useDeferredValue(filterValue);
|
||||
|
||||
const sortedProperties = useMemo(
|
||||
() =>
|
||||
@@ -54,9 +55,9 @@ export const PropertiesTable = observer<Props>(function PropertiesTable(props) {
|
||||
((propsRef.sortByName ?? true)
|
||||
? propsRef.properties.slice().sort((a, b) => (a.displayName ?? '').localeCompare(b.displayName ?? ''))
|
||||
: propsRef.properties
|
||||
).filter(p => p.new || p.key.toLocaleLowerCase().includes(filterValue.toLocaleLowerCase())),
|
||||
).filter(p => p.new || p.key.toLocaleLowerCase().includes(deferredFilterValue.toLocaleLowerCase())),
|
||||
),
|
||||
[propsRef.properties, propsRef.sortByName, filterValue],
|
||||
[propsRef.properties, propsRef.sortByName, deferredFilterValue],
|
||||
);
|
||||
|
||||
const changeName = useCallback((id: string, key: string) => {
|
||||
|
||||
@@ -522,9 +522,16 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
|
||||
}
|
||||
|
||||
async getConnectionDriverProperties(projectId: string, config: ConnectionConfig): Promise<ObjectPropertyInfo[]> {
|
||||
const options = toJS(config);
|
||||
/*
|
||||
We should not pass properties here. If we do, the values in ObjectPropertyInfo will be taken from the properties in the config.
|
||||
By deleting them, we always get the values that are actually saved on the server.
|
||||
*/
|
||||
delete options.properties;
|
||||
|
||||
const { properties } = await this.graphQLService.sdk.getConnectionDriverProperties({
|
||||
projectId,
|
||||
config,
|
||||
config: options,
|
||||
});
|
||||
|
||||
return properties;
|
||||
|
||||
+26
-4
@@ -12,7 +12,7 @@ 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';
|
||||
import { getObjectPropertyDefaultValue, getObjectPropertyOptionValue, getObjectPropertyValue } from '@cloudbeaver/core-sdk';
|
||||
import type { CONNECTION_PROPERTIES_SCHEMA } from '../CONNECTION_CONFIG_SCHEMA.js';
|
||||
|
||||
type ConnectionProperties = schema.infer<typeof CONNECTION_PROPERTIES_SCHEMA>;
|
||||
@@ -33,8 +33,9 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<ConnectionPrope
|
||||
this.optionsPart.onDriverIdChange.addHandler(this.onDriverIdChangeHandler.bind(this));
|
||||
}
|
||||
|
||||
private onDriverIdChangeHandler(driverId: string | undefined) {
|
||||
this.reset();
|
||||
private async onDriverIdChangeHandler(driverId: string | undefined) {
|
||||
const defaults = await this.getDefaultConfig();
|
||||
this.setState(defaults);
|
||||
}
|
||||
|
||||
override isOutdated(): boolean {
|
||||
@@ -57,7 +58,8 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<ConnectionPrope
|
||||
|
||||
protected override async loader(): Promise<void> {
|
||||
if (!this.optionsPart.connectionKey) {
|
||||
this.setInitialState(getDefaultState());
|
||||
const defaults = await this.getDefaultConfig();
|
||||
this.setInitialState(defaults);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,4 +110,24 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<ConnectionPrope
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private async getDefaultConfig() {
|
||||
const config: ConnectionProperties = {};
|
||||
const properties = await this.connectionInfoResource.getConnectionDriverProperties(this.formState.state.projectId, this.optionsPart.state);
|
||||
|
||||
for (const property of properties) {
|
||||
const value = getObjectPropertyValue(property);
|
||||
const defaultValue = getObjectPropertyDefaultValue(property);
|
||||
|
||||
/**
|
||||
The backend can override some driver properties by default. These overridden properties will be stored in the value field,
|
||||
so we set them here to allow the user to change them or reset them to their default driver values later.
|
||||
*/
|
||||
if (value && value !== defaultValue && property.id) {
|
||||
config[property.id] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user