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`
This commit is contained in:
MartinOscar 2025-03-06 15:55:40 +01:00 committed by GitHub
parent 1fdc428f3e
commit d438e29154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 6 deletions

View File

@ -664,11 +664,17 @@ class EditServer extends EditRecord
->helperText(fn (Server $server) => $server->databases->isNotEmpty() ? '' : trans('admin/server.no_databases')) ->helperText(fn (Server $server) => $server->databases->isNotEmpty() ? '' : trans('admin/server.no_databases'))
->columns(2) ->columns(2)
->schema([ ->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') TextInput::make('database')
->columnSpan(2) ->label(trans('admin/databasehost.table.database'))
->label(trans('admin/server.name'))
->disabled() ->disabled()
->formatStateUsing(fn ($record) => $record->database) ->formatStateUsing(fn ($record) => $record->database)
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null)
->hintAction( ->hintAction(
Action::make('Delete') Action::make('Delete')
->label(trans('filament-actions::delete.single.modal.actions.delete.label')) ->label(trans('filament-actions::delete.single.modal.actions.delete.label'))
@ -689,6 +695,7 @@ class EditServer extends EditRecord
->label(trans('admin/databasehost.table.username')) ->label(trans('admin/databasehost.table.username'))
->disabled() ->disabled()
->formatStateUsing(fn ($record) => $record->username) ->formatStateUsing(fn ($record) => $record->username)
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null)
->columnSpan(1), ->columnSpan(1),
TextInput::make('password') TextInput::make('password')
->label(trans('admin/databasehost.table.password')) ->label(trans('admin/databasehost.table.password'))
@ -697,6 +704,7 @@ class EditServer extends EditRecord
->revealable() ->revealable()
->columnSpan(1) ->columnSpan(1)
->hintAction(RotateDatabasePasswordAction::make()) ->hintAction(RotateDatabasePasswordAction::make())
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null)
->formatStateUsing(fn (Database $database) => $database->password), ->formatStateUsing(fn (Database $database) => $database->password),
TextInput::make('remote') TextInput::make('remote')
->disabled() ->disabled()
@ -714,7 +722,8 @@ class EditServer extends EditRecord
->revealable() ->revealable()
->label(trans('admin/databasehost.table.connection_string')) ->label(trans('admin/databasehost.table.connection_string'))
->columnSpan(2) ->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') ->relationship('databases')
->deletable(false) ->deletable(false)

View File

@ -35,8 +35,10 @@ class ListDatabases extends ListRecords
return $form return $form
->schema([ ->schema([
TextInput::make('host')
->formatStateUsing(fn (Database $database) => $database->address())
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
TextInput::make('database') TextInput::make('database')
->columnSpanFull()
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
TextInput::make('username') TextInput::make('username')
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null), ->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
@ -67,6 +69,9 @@ class ListDatabases extends ListRecords
{ {
return $table return $table
->columns([ ->columns([
TextColumn::make('host')
->state(fn (Database $database) => $database->address())
->badge(),
TextColumn::make('database'), TextColumn::make('database'),
TextColumn::make('username'), TextColumn::make('username'),
TextColumn::make('remote'), TextColumn::make('remote'),

View File

@ -87,10 +87,15 @@ class Database extends Model implements Validatable
return $this->belongsTo(Server::class); return $this->belongsTo(Server::class);
} }
public function address(): string
{
return $this->host->name . ':' . $this->host->port;
}
protected function jdbc(): Attribute protected function jdbc(): Attribute
{ {
return Attribute::make( 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,
); );
} }

View File

@ -5,6 +5,7 @@ return [
'model_label' => 'Database Host', 'model_label' => 'Database Host',
'model_label_plural' => 'Database Hosts', 'model_label_plural' => 'Database Hosts',
'table' => [ 'table' => [
'database' => 'Database',
'name' => 'Name', 'name' => 'Name',
'host' => 'Host', 'host' => 'Host',
'port' => 'Port', 'port' => 'Port',
@ -25,7 +26,7 @@ return [
'max_database' => 'Max Databases', '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.', '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' => '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' => 'Username',
'username_help' => 'The username of an account that has enough permissions to create new users and databases on the system.', 'username_help' => 'The username of an account that has enough permissions to create new users and databases on the system.',
'password' => 'Password', 'password' => 'Password',