From d438e29154ebeb24d285af8a7f680eaeec468a0a Mon Sep 17 00:00:00 2001 From: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:55:40 +0100 Subject: [PATCH] Add missing `Database` address field (#1049) * Add address field to display `host:port` to enduser on `ListDatabases` & `EditServer` * Add `CopyAction` to `EditServer` * Update databaseHost `display_name_help` --- .../Resources/ServerResource/Pages/EditServer.php | 15 ++++++++++++--- .../DatabaseResource/Pages/ListDatabases.php | 7 ++++++- app/Models/Database.php | 7 ++++++- lang/en/admin/databasehost.php | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php index 4436d738d..c8480f339 100644 --- a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php @@ -664,11 +664,17 @@ class EditServer extends EditRecord ->helperText(fn (Server $server) => $server->databases->isNotEmpty() ? '' : trans('admin/server.no_databases')) ->columns(2) ->schema([ + TextInput::make('host') + ->label(trans('admin/databasehost.table.host')) + ->disabled() + ->formatStateUsing(fn ($record) => $record->address()) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) + ->columnSpan(1), TextInput::make('database') - ->columnSpan(2) - ->label(trans('admin/server.name')) + ->label(trans('admin/databasehost.table.database')) ->disabled() ->formatStateUsing(fn ($record) => $record->database) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) ->hintAction( Action::make('Delete') ->label(trans('filament-actions::delete.single.modal.actions.delete.label')) @@ -689,6 +695,7 @@ class EditServer extends EditRecord ->label(trans('admin/databasehost.table.username')) ->disabled() ->formatStateUsing(fn ($record) => $record->username) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) ->columnSpan(1), TextInput::make('password') ->label(trans('admin/databasehost.table.password')) @@ -697,6 +704,7 @@ class EditServer extends EditRecord ->revealable() ->columnSpan(1) ->hintAction(RotateDatabasePasswordAction::make()) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null) ->formatStateUsing(fn (Database $database) => $database->password), TextInput::make('remote') ->disabled() @@ -714,7 +722,8 @@ class EditServer extends EditRecord ->revealable() ->label(trans('admin/databasehost.table.connection_string')) ->columnSpan(2) - ->formatStateUsing(fn (Database $record) => $record->jdbc), + ->formatStateUsing(fn (Database $record) => $record->jdbc) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), ]) ->relationship('databases') ->deletable(false) diff --git a/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php b/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php index f2c3a7004..30549c6d3 100644 --- a/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php +++ b/app/Filament/Server/Resources/DatabaseResource/Pages/ListDatabases.php @@ -35,8 +35,10 @@ class ListDatabases extends ListRecords return $form ->schema([ + TextInput::make('host') + ->formatStateUsing(fn (Database $database) => $database->address()) + ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), TextInput::make('database') - ->columnSpanFull() ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), TextInput::make('username') ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), @@ -67,6 +69,9 @@ class ListDatabases extends ListRecords { return $table ->columns([ + TextColumn::make('host') + ->state(fn (Database $database) => $database->address()) + ->badge(), TextColumn::make('database'), TextColumn::make('username'), TextColumn::make('remote'), diff --git a/app/Models/Database.php b/app/Models/Database.php index 635807b8d..c1b3da0fd 100644 --- a/app/Models/Database.php +++ b/app/Models/Database.php @@ -87,10 +87,15 @@ class Database extends Model implements Validatable return $this->belongsTo(Server::class); } + public function address(): string + { + return $this->host->name . ':' . $this->host->port; + } + protected function jdbc(): Attribute { return Attribute::make( - get: fn () => 'jdbc:mysql://' . $this->username . ':' . urlencode($this->password) . '@' . $this->host->host . ':' . $this->host->port . '/' . $this->database, + get: fn () => 'jdbc:mysql://' . $this->username . ':' . urlencode($this->password) . '@' . $this->address() . '/' . $this->database, ); } diff --git a/lang/en/admin/databasehost.php b/lang/en/admin/databasehost.php index 13be77c53..ccd12e47d 100644 --- a/lang/en/admin/databasehost.php +++ b/lang/en/admin/databasehost.php @@ -5,6 +5,7 @@ return [ 'model_label' => 'Database Host', 'model_label_plural' => 'Database Hosts', 'table' => [ + 'database' => 'Database', 'name' => 'Name', 'host' => 'Host', 'port' => 'Port', @@ -25,7 +26,7 @@ return [ 'max_database' => 'Max Databases', 'max_databases_help' => 'The maximum number of databases that can be created on this host. If the limit is reached, no new databases can be created on this host. Blank is unlimited.', 'display_name' => 'Display Name', - 'display_name_help' => 'A short identifier used to distinguish this host from others. Must be between 1 and 60 characters, for example, us.nyc.lvl3.', + 'display_name_help' => 'The IP address or Domain name that should be shown to the enduser.', 'username' => 'Username', 'username_help' => 'The username of an account that has enough permissions to create new users and databases on the system.', 'password' => 'Password',