Skip to content

Commit 195142c

Browse files
authored
Moved latest test widgets to the dashboard (alexjustesen#57)
1 parent dd06013 commit 195142c

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

app/Filament/Pages/Dashboard.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Filament\Pages;
44

5+
use App\Filament\Widgets\StatsOverview;
56
use App\Jobs\ExecSpeedtest;
67
use Filament\Notifications\Notification;
78
use Filament\Pages\Actions\Action;
@@ -20,6 +21,13 @@ protected function getActions(): array
2021
];
2122
}
2223

24+
public function getHeaderWidgets(): array
25+
{
26+
return [
27+
StatsOverview::class,
28+
];
29+
}
30+
2331
public function queueSpeedtest()
2432
{
2533
ExecSpeedtest::dispatch();

app/Filament/Resources/ResultResource.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Filament\Resources;
44

55
use App\Filament\Resources\ResultResource\Pages;
6-
use App\Filament\Resources\ResultResource\Widgets\StatsOverview;
76
use App\Models\Result;
87
use Filament\Resources\Resource;
98
use Filament\Resources\Table;
@@ -15,11 +14,9 @@ class ResultResource extends Resource
1514
{
1615
protected static ?string $model = Result::class;
1716

18-
protected static ?string $navigationGroup = 'Data';
19-
2017
protected static ?string $navigationIcon = 'heroicon-o-table';
2118

22-
protected static ?string $navigationLabel = 'Speedtest Results';
19+
protected static ?string $navigationLabel = 'Results';
2320

2421
public static function table(Table $table): Table
2522
{
@@ -63,11 +60,4 @@ public static function getPages(): array
6360
'index' => Pages\ListResults::route('/'),
6461
];
6562
}
66-
67-
public static function getWidgets(): array
68-
{
69-
return [
70-
StatsOverview::class,
71-
];
72-
}
7363
}

app/Filament/Resources/ResultResource/Widgets/StatsOverview.php

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Filament\Widgets;
4+
5+
use App\Models\Result;
6+
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
7+
use Filament\Widgets\StatsOverviewWidget\Card;
8+
9+
class StatsOverview extends BaseWidget
10+
{
11+
protected static ?string $pollingInterval = null;
12+
13+
protected function getCards(): array
14+
{
15+
$result = Result::latest()->first();
16+
17+
return [
18+
Card::make('Latest download', fn (): string => ! blank($result) ? formatBits(formatBytesToBits($result->download)).'ps' : 'n/a')
19+
->icon('heroicon-o-download'),
20+
Card::make('Latest upload', fn (): string => ! blank($result) ? formatBits(formatBytesToBits($result->upload)).'ps' : 'n/a')
21+
->icon('heroicon-o-upload'),
22+
Card::make('Latest ping', fn (): string => ! blank($result) ? round($result->ping, 2).'ms' : 'n/a')
23+
->icon('heroicon-o-clock'),
24+
];
25+
}
26+
}

app/Providers/FilamentServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function boot()
2727
{
2828
Filament::serving(function () {
2929
Filament::registerNavigationGroups([
30-
'Data',
3130
'Links',
3231
]);
3332

0 commit comments

Comments
 (0)