-
Notifications
You must be signed in to change notification settings - Fork 551
dbeaver/pro#10177 pass defaults to main properties #4538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -49,11 +49,11 @@ | |||
| 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: [], | ||||
|
|
@@ -151,7 +151,7 @@ | |||
| return state; | ||||
| } | ||||
|
|
||||
| get connectionKey() { | ||||
| if (!this.initialState.connectionId || !this.formState.state.projectId) { | ||||
| return null; | ||||
| } | ||||
|
|
@@ -185,14 +185,12 @@ | |||
|
|
||||
| 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,9 +338,39 @@ | |||
| this.state.authModelId = modelId; | ||||
| } | ||||
|
|
||||
| private async getDefaults() { | ||||
| const config = defaultStateGetter(this.initialState.connectionId ?? this.formState.state.connectionId); | ||||
|
|
||||
| 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) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we get config so this check is always true cloudbeaver/webapp/packages/plugin-connections/src/ConnectionForm/CONNECTION_CONFIG_SCHEMA.ts Line 26 in 8bbf4c2
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, types are from zod schema, there mainPropertyValues is optional |
||||
| 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>>, | ||||
| ): Promise<void> { | ||||
| if (!this.state.driverId || !this.formState.state.projectId) { | ||||
| return; | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,10 @@ | |
| connectionId: config.connectionId, | ||
| }).setMode(config.connectionId ? FormMode.Edit : FormMode.Create); | ||
|
|
||
| await this.optionsPart?.load(); | ||
| // Don't call load in create mode. There we rely on the defaults set here, and useAutoLoad will load the part on mount. | ||
| if (this.formState.mode === FormMode.Edit) { | ||
| await this.optionsPart?.load(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is off here Previously we waited for part being Right now it smells like race condition. What if in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the original issue here? Maybe we can resolve it differently? |
||
|
|
||
| if (config.driverId) { | ||
| await this.optionsPart?.setDriverId(config.driverId); | ||
|
|
@@ -136,7 +139,7 @@ | |
| return this.formState ? getConnectionFormOptionsPart(this.formState) : null; | ||
| } | ||
|
|
||
| private readonly closeRemoved: IExecutorHandler<ResourceKey<IConnectionInfoParams>> = (data, contexts) => { | ||
|
Check warning on line 142 in webapp/packages/plugin-connections/src/PublicConnectionForm/PublicConnectionFormService.ts
|
||
| if (!this.formState || !this.optionsPart?.connectionKey) { | ||
| return; | ||
| } | ||
|
|
@@ -146,7 +149,7 @@ | |
| } | ||
| }; | ||
|
|
||
| private readonly closeDeleted: IExecutorHandler<ResourceKeySimple<IConnectionInfoParams>> = (data, contexts) => { | ||
| if (!this.formState || !this.optionsPart?.connectionKey) { | ||
| return; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
includes is pattern we refused to support a while ago. it would be nice to create new resource
DBDriverMainPropertiesResourceand reuse it hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not scope of the ticket, code is already exist in this part