Skip to content

Commit

Permalink
[Feature] Server selection for manual tests (#1763)
Browse files Browse the repository at this point in the history
* Add pop up

* White line

* swap name and sponsor, add id

* Use GetOoklaSpeedtestServers

* Make it Server selection optional

* Update Dashboard.php

* removed spaces

---------

Co-authored-by: Alex Justesen <[email protected]>
  • Loading branch information
svenvg93 and alexjustesen authored Nov 22, 2024
1 parent 59677db commit 4723309
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Actions/GetOoklaSpeedtestServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle(): array

return $response->mapWithKeys(function (array $item, int $key) {
return [
$item['id'] => $item['id'].': '.$item['name'].' ('.$item['sponsor'].')',
$item['id'] => $item['sponsor'].' ('.$item['name'].', '.$item['id'].')',
];
})->toArray();
}
Expand Down
34 changes: 22 additions & 12 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Pages;

use App\Actions\GetOoklaSpeedtestServers;
use App\Actions\Ookla\StartSpeedtest;
use App\Filament\Widgets\RecentDownloadChartWidget;
use App\Filament\Widgets\RecentDownloadLatencyChartWidget;
Expand All @@ -13,7 +14,7 @@
use Carbon\Carbon;
use Cron\CronExpression;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Pages\Dashboard as BasePage;
use Filament\Support\Enums\IconPosition;
Expand Down Expand Up @@ -49,20 +50,29 @@ protected function getHeaderActions(): array
->color('gray')
->hidden(fn (): bool => ! config('speedtest.public_dashboard'))
->url(shouldOpenInNewTab: true, url: '/'),
ActionGroup::make([
Action::make('ookla speedtest')
->action(function () {
StartSpeedtest::run();
Action::make('ookla_speedtest')
->form([
Forms\Components\Select::make('server_id')
->label('Select Server')
->helperText('Leave blank to run the speedtest without specifying a server.')
->options(fn (callable $get) => app(GetOoklaSpeedtestServers::class)->handle($get('server_search')))
->searchable(),
])
->action(function (array $data) {
$serverId = $data['server_id'] ?? null;

Notification::make()
->title('Ookla speedtest started')
->success()
->send();
}),
])
StartSpeedtest::run(serverId: $serverId);

Notification::make()
->title('Speedtest started')
->success()
->send();
})
->modalHeading('Run Speedtest')
->modalButton('Run Speedtest')
->modalWidth('lg')
->button()
->color('primary')
->dropdownPlacement('bottom-end')
->label('Run Speedtest')
->icon('heroicon-o-rocket-launch')
->iconPosition(IconPosition::Before)
Expand Down

0 comments on commit 4723309

Please sign in to comment.