mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-08 09:58:37 +02:00
replace custom suffixCopy
with filaments copyable
This commit is contained in:
parent
b1a670f8f5
commit
62df59008e
@ -97,14 +97,14 @@ class CreateDatabaseHost extends CreateRecord
|
||||
->default(fn (Get $get) => "CREATE USER '{$get('username')}'@'{$get('panel_ip')}' IDENTIFIED BY '{$get('password')}';")
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->columnSpanFull(),
|
||||
TextInput::make('assign_permissions')
|
||||
->label(trans('admin/databasehost.setup.command_assign_permissions'))
|
||||
->default(fn (Get $get) => "GRANT ALL PRIVILEGES ON *.* TO '{$get('username')}'@'{$get('panel_ip')}' WITH GRANT OPTION;")
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->columnSpanFull(),
|
||||
TextEntry::make('cli_exit')
|
||||
->hiddenLabel()
|
||||
|
@ -176,7 +176,7 @@ class EditServer extends EditRecord
|
||||
|
||||
TextInput::make('uuid')
|
||||
->label(trans('admin/server.uuid'))
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->columnSpan([
|
||||
'default' => 2,
|
||||
'sm' => 1,
|
||||
@ -187,7 +187,7 @@ class EditServer extends EditRecord
|
||||
->dehydrated(false),
|
||||
TextInput::make('uuid_short')
|
||||
->label(trans('admin/server.short_uuid'))
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->columnSpan([
|
||||
'default' => 2,
|
||||
'sm' => 1,
|
||||
|
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Components\Actions;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Js;
|
||||
|
||||
class CopyAction extends Action
|
||||
{
|
||||
protected Closure|string|null $copyable = null;
|
||||
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'copy';
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->icon('tabler-clipboard-copy');
|
||||
|
||||
$this->successNotificationTitle(trans('filament::components/copyable.messages.copied'));
|
||||
|
||||
$this->extraAttributes(fn () => [
|
||||
'x-on:click' => new HtmlString('window.navigator.clipboard.writeText('.$this->getCopyable().'); $tooltip('.Js::from($this->getSuccessNotificationTitle()).');'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function copyable(Closure|string|null $copyable): self
|
||||
{
|
||||
$this->copyable = $copyable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCopyable(): ?string
|
||||
{
|
||||
return Js::from($this->evaluate($this->copyable));
|
||||
}
|
||||
}
|
@ -168,7 +168,7 @@ class Settings extends ServerFormPage
|
||||
->label(trans('server/setting.node_info.sftp.connection'))
|
||||
->columnSpan(1)
|
||||
->disabled()
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->hintAction(
|
||||
Action::make('connect_sftp')
|
||||
->label(trans('server/setting.node_info.sftp.action'))
|
||||
@ -188,7 +188,7 @@ class Settings extends ServerFormPage
|
||||
TextInput::make('username')
|
||||
->label(trans('server/setting.node_info.sftp.username'))
|
||||
->columnSpan(1)
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->disabled()
|
||||
->formatStateUsing(fn (Server $server) => auth()->user()->username . '.' . $server->uuid_short),
|
||||
TextEntry::make('password')
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Filament\Server\Resources\Databases;
|
||||
|
||||
use App\Filament\Components\Actions\CopyAction;
|
||||
use App\Filament\Components\Actions\RotateDatabasePasswordAction;
|
||||
use App\Filament\Server\Resources\Databases\Pages\ListDatabases;
|
||||
use App\Filament\Components\Tables\Columns\DateTimeColumn;
|
||||
@ -77,13 +76,13 @@ class DatabaseResource extends Resource
|
||||
TextInput::make('host')
|
||||
->label(trans('server/database.host'))
|
||||
->formatStateUsing(fn (Database $database) => $database->address())
|
||||
->suffixCopy(),
|
||||
->copyable(),
|
||||
TextInput::make('database')
|
||||
->label(trans('server/database.database'))
|
||||
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
|
||||
->copyable(),
|
||||
TextInput::make('username')
|
||||
->label(trans('server/database.username'))
|
||||
->suffixAction(fn (string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null),
|
||||
->copyable(),
|
||||
TextInput::make('password')
|
||||
->label(trans('server/database.password'))
|
||||
->password()->revealable()
|
||||
@ -92,7 +91,7 @@ class DatabaseResource extends Resource
|
||||
RotateDatabasePasswordAction::make()
|
||||
->authorize(fn () => auth()->user()->can(Permission::ACTION_DATABASE_UPDATE, $server))
|
||||
)
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->formatStateUsing(fn (Database $database) => $database->password),
|
||||
TextInput::make('remote')
|
||||
->label(trans('server/database.remote')),
|
||||
@ -103,7 +102,7 @@ class DatabaseResource extends Resource
|
||||
->label(trans('server/database.jdbc'))
|
||||
->password()->revealable()
|
||||
->hidden(!auth()->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $server))
|
||||
->suffixCopy()
|
||||
->copyable()
|
||||
->columnSpanFull()
|
||||
->formatStateUsing(fn (Database $database) => $database->jdbc),
|
||||
]);
|
||||
|
@ -28,7 +28,6 @@ use Dedoc\Scramble\Scramble;
|
||||
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\Facades\FilamentView;
|
||||
@ -151,11 +150,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
$component->dispatch('alertBannerSent');
|
||||
});
|
||||
|
||||
Field::macro('suffixCopy', function () {
|
||||
/** @var TextInput $this */
|
||||
return $this->suffixAction(fn (?string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null); // @phpstan-ignore varTag.nativeType
|
||||
});
|
||||
|
||||
Field::macro('hintCopy', function () {
|
||||
/** @var Field $this */
|
||||
return $this->hintAction(fn (?string $state) => request()->isSecure() ? CopyAction::make()->copyable($state) : null); // @phpstan-ignore varTag.nativeType
|
||||
|
@ -14,7 +14,6 @@ parameters:
|
||||
ignoreErrors:
|
||||
- identifier: argument.templateType
|
||||
- identifier: missingType.generics
|
||||
- '#Call to an undefined method Filament\\Forms\\Components\\TextInput::suffixCopy\(\)#'
|
||||
- '#Call to an undefined method Filament\\Forms\\Components\\TextInput::hintCopy\(\)#'
|
||||
- '#Call to an undefined method Filament\\Forms\\Components\\Textarea::hintCopy\(\)#'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user