Skip to content

Commit ab623bd

Browse files
remove switcher and make connection string permanently seen, refactoring
1 parent 8c50fcc commit ab623bd

3 files changed

Lines changed: 33 additions & 58 deletions

File tree

frontend/src/app/components/connect-db/connect-db.component.css

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@
2929
grid-template-columns: subgrid;
3030
grid-template-rows: subgrid;
3131
grid-column: 1 / span 4;
32-
grid-row: 5 / span 4;
32+
grid-row: 6 / span 4;
3333
}
3434

35-
:host ::ng-deep .connectForm__typeSwitch + .credentials-fieldset {
35+
:host ::ng-deep .connectForm__typeSwitch + ndc-dynamic + .credentials-fieldset {
3636
grid-row: 4 / span 4;
3737
}
3838

39-
:host ::ng-deep .connectForm__warningMessage + .connectForm__credentialsModeSwitch + .credentials-fieldset {
40-
grid-row: 6 / span 4;
41-
}
42-
4339

4440

4541
@media (width <= 600px) {
@@ -219,6 +215,7 @@
219215

220216
.connectForm__connectionString button {
221217
margin-top: 4px;
218+
margin-left: -80px;
222219
}
223220

224221
.agent-token {

frontend/src/app/components/connect-db/connect-db.component.html

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ <h1 class="mat-h1 connectForm__fullLine">
7272
</div>
7373

7474
@if (db.connectionType === 'direct' && !db.id) {
75-
<div class="connectForm__fullLine connectForm__toggle connectForm__credentialsModeSwitch">
76-
<mat-button-toggle-group name="connectionInputMode"
77-
data-testid="connection-input-mode-toggle"
78-
[disabled]="submitting"
79-
[(ngModel)]="connectionInputMode">
80-
<mat-button-toggle value="manual">Manual</mat-button-toggle>
81-
<mat-button-toggle value="connectionString">Connection string</mat-button-toggle>
82-
</mat-button-toggle-group>
83-
</div>
84-
}
85-
86-
@if (connectionInputMode === 'connectionString' && db.connectionType === 'direct' && !db.id) {
8775
<div class="connectForm__fullLine connectForm__connectionString">
8876
<mat-form-field appearance="outline" style="width: 100%">
8977
<mat-label>Connection string</mat-label>
@@ -105,7 +93,8 @@ <h1 class="mat-h1 connectForm__fullLine">
10593
<mat-error>Failed to parse connection string</mat-error>
10694
}
10795
</mat-form-field>
108-
<button type="button" mat-flat-button color="primary"
96+
<button type="button" mat-button color="primary"
97+
class="connectForm__connectionStringApplyButton"
10998
data-testid="connection-string-apply-button"
11099
[disabled]="submitting || !connectionString.trim() || connectionStringInput.invalid"
111100
(click)="applyConnectionString()">
@@ -114,12 +103,21 @@ <h1 class="mat-h1 connectForm__fullLine">
114103
</div>
115104
}
116105

117-
<ndc-dynamic
118-
[ndcDynamicComponent]="credentialsFormComponent"
119-
[ndcDynamicInputs]="credentialsFormInputs"
120-
[ndcDynamicOutputs]="credentialsFormOutputs"
121-
[ndcDynamicAttributes]="credentialsFormAttributes"
122-
></ndc-dynamic>
106+
@if (db.connectionType === 'direct') {
107+
<ndc-dynamic
108+
[ndcDynamicComponent]="credentialsFormComponent"
109+
[ndcDynamicInputs]="{
110+
connection: db,
111+
submitting: submitting,
112+
accessLevel: accessLevel,
113+
masterKey: masterKey,
114+
readonly: !!((accessLevel === 'readonly' || db.isTestConnection) && db.id)
115+
}"
116+
[ndcDynamicOutputs]="credentialsFormOutputs"
117+
[ndcDynamicAttributes]="credentialsFormAttributes"
118+
></ndc-dynamic>
119+
}
120+
123121

124122
<div *ngIf="db.connectionType === 'agent'" class="connectForm__fullLine instruction">
125123

frontend/src/app/components/connect-db/connect-db.component.ts

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
22
import { CommonModule } from '@angular/common';
3-
import { Component, DoCheck, NgZone, OnInit, Type } from '@angular/core';
3+
import { Component, NgZone, OnInit, Type } from '@angular/core';
44
import { FormsModule, NgForm } from '@angular/forms';
55
import { MatButtonModule } from '@angular/material/button';
66
import { 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

Comments
 (0)