Skip to content

Commit 48b16e1

Browse files
Refactor Whois widget and remove irrelevant migrations
The Whois widget was restructured with added logic for plugin configurations and removed unused classes. Consequently, migrations which were no longer needed were deleted. This refactoring ensures efficient code structure and performance. Additionally, PHP requirement was updated to "^8.2", and "Whois" terminology was corrected in translation files.
1 parent 5c33d3d commit 48b16e1

9 files changed

+133
-27
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": "^8.1",
23+
"php": "^8.2",
2424
"filament/filament": "^3.0",
2525
"spatie/laravel-package-tools": "^1.15.0"
2626
},

phpstan.neon.dist

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ parameters:
66
paths:
77
- src
88
- config
9-
- database
109
tmpDir: build/phpstan
1110
checkOctaneCompatibility: true
1211
checkModelProperties: true
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
// translations for JeffersonSimaoGoncalves/FilamentCheckWhoisWidget
43
return [
5-
//
4+
'title' => 'WHOIS',
5+
'description' => 'List of whois to check details',
66
];

resources/views/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<x-filament-widgets::widget class="fi-filament-info-widget">
2+
<x-filament::section>
3+
@if($shouldShowTitle)
4+
<div class="mb-4">
5+
<h2 class="flex items-center text-lg font-semibold text-gray-900 dark:text-white">
6+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
7+
stroke="currentColor" class="w-4 h-4" style="margin-right: 8px;">
8+
<path stroke-linecap="round" stroke-linejoin="round"
9+
d="M9 12.75 11.25 15 15 9.75m-3-7.036A11.959 11.959 0 0 1 3.598 6 11.99 11.99 0 0 0 3 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285Z" />
10+
</svg>
11+
12+
{{ is_null($title) ? __('filament-check-whois-widget::default.title') : $title }}
13+
</h2>
14+
<p class="mt-1 text-xs text-gray-600 dark:text-gray-400">
15+
{{ is_null($description) ? __('filament-check-whois-widget::default.description') : $description }}
16+
</p>
17+
</div>
18+
@endif
19+
20+
<div class="grid grid-cols-1 gap-2 md:grid-cols-{{$quantityPerRow}}">
21+
@foreach ($domainWhois as $whois)
22+
<div class="flex items-center justify-between bg-gray-100 dark:bg-gray-700 p-2 rounded-md shadow-sm">
23+
<span class="flex text-sm font-medium text-gray-800 dark:text-white">
24+
{{ $whois['domain'] }}
25+
</span>
26+
<span class="flex items-center text-xs text-gray-800 dark:text-white">
27+
@if ($whois['expiration_date'])
28+
<li>
29+
<strong>Expiration: </strong> {{ $whois['expiration_date']->diffForHumans() }}
30+
(<strong class="italic">{{ (int)abs($whois['expiration_date']->diffInDays()) }} days</strong>)
31+
</li>
32+
@endif
33+
</span>
34+
</div>
35+
@endforeach
36+
</div>
37+
</x-filament::section>
38+
</x-filament-widgets::widget>

src/Facades/FilamentCheckWhoisWidget.php

-16
This file was deleted.

src/FilamentCheckWhoisWidget.php

-5
This file was deleted.

src/FilamentCheckWhoisWidgetServiceProvider.php

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public function configurePackage(Package $package): void
2727
->hasInstallCommand(function (InstallCommand $command) {
2828
$command
2929
->publishConfigFile()
30-
->publishMigrations()
31-
->askToRunMigrations()
3230
->askToStarRepoOnGitHub('jeffersonsimaogoncalves/filament-check-whois-widget');
3331
});
3432

src/Widgets/WhoisWidget.php

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace JeffersonSimaoGoncalves\FilamentCheckWhoisWidget\Widgets;
4+
5+
use AllowDynamicProperties;
6+
use Filament\Facades\Filament;
7+
use Filament\Widgets\Widget;
8+
use Illuminate\Contracts\View\View;
9+
use Illuminate\Support\Facades\Cache;
10+
11+
#[AllowDynamicProperties]
12+
class WhoisWidget extends Widget
13+
{
14+
protected static bool $isLazy = false;
15+
16+
protected static string $view = 'filament-check-whois-widget::filament.widgets.check-whois-widget';
17+
18+
protected array $domainWhois = [];
19+
20+
public function __construct()
21+
{
22+
$domains = [];
23+
24+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
25+
26+
if ($plugin->getDomains()) {
27+
$domains = $plugin->getDomains();
28+
}
29+
30+
foreach ($domains as $domain) {
31+
$this->whois[] = Cache::remember("filament-check-whois-widget-$domain", 2592000, fn() => $this->getWhois($domain));
32+
}
33+
}
34+
35+
private function getWhois(string $domain): array
36+
{
37+
38+
}
39+
40+
public static function getSort(): int
41+
{
42+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
43+
44+
return $plugin->getSort() ?? -1;
45+
}
46+
47+
public function getColumnSpan(): int|string|array
48+
{
49+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
50+
51+
return $plugin->getColumnSpan() ?? '1/2';
52+
}
53+
54+
public function render(): View
55+
{
56+
return view(static::$view, [
57+
'domainWhois' => $this->domainWhois,
58+
'shouldShowTitle' => $this->shouldShowTitle(),
59+
'title' => $this->title(),
60+
'description' => $this->description(),
61+
'quantityPerRow' => $this->quantityPerRow() ?? '1',
62+
]);
63+
}
64+
65+
public function shouldShowTitle(): bool
66+
{
67+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
68+
69+
return $plugin->getShouldShowTitle();
70+
}
71+
72+
public function title()
73+
{
74+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
75+
76+
return $plugin->getTitle();
77+
}
78+
79+
public function description()
80+
{
81+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
82+
83+
return $plugin->getDescription();
84+
}
85+
86+
public function quantityPerRow()
87+
{
88+
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-check-whois-widget');
89+
90+
return $plugin->getQuantityPerRow();
91+
}
92+
}

0 commit comments

Comments
 (0)