Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Server selection for manual tests #1763

Merged
merged 9 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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