diff --git a/frontend/src/app/components/connect-db/connect-db.component.html b/frontend/src/app/components/connect-db/connect-db.component.html index fc00cb029..0e2bb6fe8 100644 --- a/frontend/src/app/components/connect-db/connect-db.component.html +++ b/frontend/src/app/components/connect-db/connect-db.component.html @@ -9,7 +9,7 @@

- Connection name + Connection title Name your connection -

Give your hosted database a friendly name so you can find it easily.

+

Give your hosted database a friendly title so you can find it easily.

- Connection name + Connection title
diff --git a/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.css b/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.css new file mode 100644 index 000000000..c639bb127 --- /dev/null +++ b/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.css @@ -0,0 +1,5 @@ +.rename-dialog__field { + margin-top: 12px; + margin-bottom: -12px; + width: 100%; +} diff --git a/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.html b/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.html new file mode 100644 index 000000000..1d692e987 --- /dev/null +++ b/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.html @@ -0,0 +1,16 @@ +

Rename {{ data.databaseName }}

+ + + Connection name + + + + + + + diff --git a/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.ts b/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.ts new file mode 100644 index 000000000..6c3c4bc60 --- /dev/null +++ b/frontend/src/app/components/hosted-databases/hosted-database-rename-dialog/hosted-database-rename-dialog.component.ts @@ -0,0 +1,56 @@ +import { Component, inject, signal } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { firstValueFrom } from 'rxjs'; +import posthog from 'posthog-js'; +import { FoundHostedDatabase } from 'src/app/models/hosted-database'; +import { ConnectionsService } from 'src/app/services/connections.service'; +import { NotificationsService } from 'src/app/services/notifications.service'; + +@Component({ + selector: 'app-hosted-databases-rename-dialog', + templateUrl: './hosted-database-rename-dialog.component.html', + styleUrls: ['./hosted-database-rename-dialog.component.css'], + imports: [MatDialogModule, MatButtonModule, MatFormFieldModule, MatInputModule, FormsModule], +}) +export class HostedDatabasesRenameDialogComponent { + private _connectionsService = inject(ConnectionsService); + private _notifications = inject(NotificationsService); + private _dialogRef = inject(MatDialogRef); + + protected data: FoundHostedDatabase = inject(MAT_DIALOG_DATA); + protected title = this.data.title || this.data.databaseName || ''; + protected submitting = signal(false); + + async save(): Promise { + const title = this.title.trim(); + if (!title || this.submitting()) return; + + this.submitting.set(true); + + try { + const connections = await firstValueFrom(this._connectionsService.fetchConnections()); + const match = connections?.find( + (item) => + item.connection.host === this.data.hostname && + item.connection.database === this.data.databaseName, + ); + + if (!match) { + this._notifications.showErrorSnackbar('Matching connection not found.'); + this.submitting.set(false); + return; + } + + await firstValueFrom(this._connectionsService.updateConnectionTitle(match.connection.id, title)); + posthog.capture('Hosted Databases: database renamed', { databaseName: this.data.databaseName }); + this._connectionsService.fetchConnections().subscribe(); + this._dialogRef.close(title); + } finally { + this.submitting.set(false); + } + } +} diff --git a/frontend/src/app/components/hosted-databases/hosted-databases.component.html b/frontend/src/app/components/hosted-databases/hosted-databases.component.html index 323cf074a..ce16942c0 100644 --- a/frontend/src/app/components/hosted-databases/hosted-databases.component.html +++ b/frontend/src/app/components/hosted-databases/hosted-databases.component.html @@ -47,6 +47,11 @@

Hosted Databases

+