diff --git a/app/Filament/Server/Components/SmallStatBlock.php b/app/Filament/Server/Components/SmallStatBlock.php index 3e245f9e9..0d15534cb 100644 --- a/app/Filament/Server/Components/SmallStatBlock.php +++ b/app/Filament/Server/Components/SmallStatBlock.php @@ -2,43 +2,27 @@ namespace App\Filament\Server\Components; +use Closure; +use Filament\Support\Concerns\EvaluatesClosures; use Filament\Widgets\StatsOverviewWidget\Stat; -use Illuminate\Contracts\Support\Htmlable; use Illuminate\Contracts\View\View; class SmallStatBlock extends Stat { - protected string|Htmlable $label; + use EvaluatesClosures; - protected $value; + protected bool|Closure $copyOnClick = false; - public function label(string|Htmlable $label): static + public function copyOnClick(bool|Closure $copyOnClick = true): static { - $this->label = $label; + $this->copyOnClick = $copyOnClick; return $this; } - public function value($value): static + public function shouldCopyOnClick(): bool { - $this->value = $value; - - return $this; - } - - public function getLabel(): string|Htmlable - { - return $this->label; - } - - public function getValue() - { - return value($this->value); - } - - public function toHtml(): string - { - return $this->render()->render(); + return $this->evaluate($this->copyOnClick); } public function render(): View diff --git a/app/Filament/Server/Components/StatBlock.php b/app/Filament/Server/Components/StatBlock.php deleted file mode 100644 index 64e2a08e2..000000000 --- a/app/Filament/Server/Components/StatBlock.php +++ /dev/null @@ -1,48 +0,0 @@ -label = $label; - - return $this; - } - - public function value($value): static - { - $this->value = $value; - - return $this; - } - - public function getLabel(): string|Htmlable - { - return $this->label; - } - - public function getValue() - { - return value($this->value); - } - - public function toHtml(): string - { - return $this->render()->render(); - } - - public function render(): View - { - return view('filament.components.server-data-block', $this->data()); - } -} diff --git a/app/Filament/Server/Widgets/ServerOverview.php b/app/Filament/Server/Widgets/ServerOverview.php index f81362b67..0f7455cb1 100644 --- a/app/Filament/Server/Widgets/ServerOverview.php +++ b/app/Filament/Server/Widgets/ServerOverview.php @@ -6,8 +6,10 @@ use App\Enums\ContainerStatus; use App\Filament\Server\Components\SmallStatBlock; use App\Models\Server; use Carbon\CarbonInterface; +use Filament\Notifications\Notification; use Filament\Widgets\StatsOverviewWidget; use Illuminate\Support\Number; +use Livewire\Attributes\On; class ServerOverview extends StatsOverviewWidget { @@ -19,14 +21,10 @@ class ServerOverview extends StatsOverviewWidget { return [ SmallStatBlock::make('Name', $this->server->name) - ->extraAttributes([ - 'class' => 'overflow-x-auto', - ]), + ->copyOnClick(fn () => request()->isSecure()), SmallStatBlock::make('Status', $this->status()), SmallStatBlock::make('Address', $this->server->allocation->address) - ->extraAttributes([ - 'class' => 'overflow-x-auto', - ]), + ->copyOnClick(fn () => request()->isSecure()), SmallStatBlock::make('CPU', $this->cpuUsage()), SmallStatBlock::make('Memory', $this->memoryUsage()), SmallStatBlock::make('Disk', $this->diskUsage()), @@ -93,4 +91,16 @@ class ServerOverview extends StatsOverviewWidget return $used . ($this->server->disk > 0 ? ' / ' . $total : ' / ∞'); } + + #[On('copyClick')] + public function copyClick(string $value): void + { + $this->js("window.navigator.clipboard.writeText('{$value}');"); + + Notification::make() + ->title('Copied to clipboard') + ->body($value) + ->success() + ->send(); + } } diff --git a/resources/views/filament/components/server-data-block.blade.php b/resources/views/filament/components/server-data-block.blade.php deleted file mode 100644 index f640d582d..000000000 --- a/resources/views/filament/components/server-data-block.blade.php +++ /dev/null @@ -1,10 +0,0 @@ -
-
- - {{ $getLabel() }} - -
- {{ $getValue() }} -
-
-
diff --git a/resources/views/filament/components/server-small-data-block.blade.php b/resources/views/filament/components/server-small-data-block.blade.php index ff9770fa5..3be63ee71 100644 --- a/resources/views/filament/components/server-small-data-block.blade.php +++ b/resources/views/filament/components/server-small-data-block.blade.php @@ -1,9 +1,14 @@ -
+
+@if ($shouldCopyOnClick()) + +@else +@endif {{ $getLabel() }} - {{ $getValue() }} + + {{ $getValue() }} +