11import { CdkCopyToClipboard } from '@angular/cdk/clipboard' ;
22import { CommonModule } from '@angular/common' ;
3- import { Component , DoCheck , NgZone , OnInit , Type } from '@angular/core' ;
3+ import { Component , NgZone , OnInit , Type } from '@angular/core' ;
44import { FormsModule , NgForm } from '@angular/forms' ;
55import { MatButtonModule } from '@angular/material/button' ;
66import { MatButtonToggleModule } from '@angular/material/button-toggle' ;
@@ -75,7 +75,7 @@ import { RedisCredentialsFormComponent } from './db-credentials-forms/redis-cred
7575 DynamicAttributesDirective ,
7676 ] ,
7777} )
78- export class ConnectDBComponent implements OnInit , DoCheck {
78+ export class ConnectDBComponent implements OnInit {
7979 protected posthog = posthog ;
8080
8181 public isSaas = ( environment as any ) . saas ;
@@ -90,7 +90,6 @@ export class ConnectDBComponent implements OnInit, DoCheck {
9090 message : null ,
9191 } ;
9292
93- public connectionInputMode : 'manual' | 'connectionString' = 'manual' ;
9493 public connectionString : string = '' ;
9594
9695 public credentialsFormMap : Record < string , Type < BaseCredentialsFormComponent > > = {
@@ -132,6 +131,14 @@ export class ConnectDBComponent implements OnInit, DoCheck {
132131 "This is a DEMO SESSION! It will disappear after you log out. Don't use databases you're actively using or that contain information you wish to retain." ,
133132 } ;
134133
134+ public credentialsFormComponent : Type < BaseCredentialsFormComponent > | null = null ;
135+ public credentialsFormInputs : Record < string , any > = { } ;
136+ public credentialsFormOutputs : Record < string , any > = {
137+ switchToAgent : ( ) => this . switchToAgent ( ) ,
138+ masterKeyChange : ( key : string ) => this . handleMasterKeyChange ( key ) ,
139+ } ;
140+ public credentialsFormAttributes : Record < string , string > = { class : 'credentials-fieldset' } ;
141+
135142 constructor (
136143 private _connections : ConnectionsService ,
137144 private _notifications : NotificationsService ,
@@ -158,6 +165,8 @@ export class ConnectDBComponent implements OnInit, DoCheck {
158165 this . db . port = this . ports [ databaseType ] ;
159166 }
160167
168+ this . credentialsFormComponent = this . credentialsFormMap [ this . db . type ] || null ;
169+
161170 this . _connections
162171 . getCurrentConnectionTitle ( )
163172 . pipe ( take ( 1 ) )
@@ -190,6 +199,7 @@ export class ConnectDBComponent implements OnInit, DoCheck {
190199
191200 dbTypeChange ( ) {
192201 this . db . port = this . ports [ this . db . type ] ;
202+ this . credentialsFormComponent = this . credentialsFormMap [ this . db . type ] || null ;
193203 }
194204
195205 testConnection ( ) {
@@ -458,10 +468,6 @@ export class ConnectDBComponent implements OnInit, DoCheck {
458468 this . masterKey = newMasterKey ;
459469 }
460470
461- ngDoCheck ( ) {
462- this . _updateCredentialsFormInputs ( ) ;
463- }
464-
465471 applyConnectionString ( ) {
466472 if ( ! this . connectionString . trim ( ) ) {
467473 return ;
@@ -487,7 +493,6 @@ export class ConnectDBComponent implements OnInit, DoCheck {
487493 this . db . ssl = true ;
488494 }
489495
490- this . connectionInputMode = 'manual' ;
491496 this . connectionString = '' ;
492497 this . _notifications . showSuccessSnackbar ( 'Connection string parsed successfully' ) ;
493498 } catch ( _e ) {
@@ -514,29 +519,4 @@ export class ConnectDBComponent implements OnInit, DoCheck {
514519 }
515520 return provider ;
516521 }
517-
518- public credentialsFormComponent : Type < BaseCredentialsFormComponent > | null = null ;
519- public credentialsFormInputs : Record < string , any > = { } ;
520- public credentialsFormOutputs : Record < string , any > = {
521- switchToAgent : ( ) => this . switchToAgent ( ) ,
522- masterKeyChange : ( key : string ) => this . handleMasterKeyChange ( key ) ,
523- } ;
524- public credentialsFormAttributes : Record < string , string > = { class : 'credentials-fieldset' } ;
525-
526- private _updateCredentialsFormInputs ( ) {
527- const isConnectionStringMode = this . connectionInputMode === 'connectionString' && this . db . connectionType === 'direct' && ! this . db . id ;
528- const targetType = ( ! isConnectionStringMode && this . db . connectionType === 'direct' && this . credentialsFormMap [ this . db . type ] ) || null ;
529-
530- this . credentialsFormComponent = targetType ;
531-
532- if ( targetType ) {
533- this . credentialsFormInputs = {
534- connection : this . db ,
535- submitting : this . submitting ,
536- accessLevel : this . accessLevel ,
537- masterKey : this . masterKey ,
538- readonly : ! ! ( ( this . accessLevel === 'readonly' || this . db . isTestConnection ) && this . db . id ) ,
539- } ;
540- }
541- }
542522}
0 commit comments