Repository: alexjustesen/speedtest-tracker (language: php)

Issue:
Feature request: drop down list 
Is it possible for your own chosen/ specified server in the config file to be listed in the drop down list when wanting to run a test rather than just local ones. My list shows local servers but in reality they aren't as close as the one I use for my tests.

Thanks 




Discussion / hints:
Can do
For later Alex to implement https://filamentphp.com/docs/3.x/forms/fields/select/#grouping-options
Thanks so much!

Fix patch:
diff --git a/app/Filament/Pages/Dashboard.php b/app/Filament/Pages/Dashboard.php
index 666001369..bdbb940a8 100644
--- a/app/Filament/Pages/Dashboard.php
+++ b/app/Filament/Pages/Dashboard.php
@@ -11,6 +11,7 @@
 use App\Filament\Widgets\RecentUploadChartWidget;
 use App\Filament\Widgets\RecentUploadLatencyChartWidget;
 use App\Filament\Widgets\StatsOverviewWidget;
+use App\Helpers\Ookla;
 use Carbon\Carbon;
 use Cron\CronExpression;
 use Filament\Actions\Action;
@@ -57,6 +58,12 @@ protected function getHeaderActions(): array
                         ->label('Select Server')
                         ->helperText('Leave empty to run the speedtest without specifying a server.')
                         ->options(fn (): array => GetOoklaSpeedtestServers::run())
+                        ->options(function (): array {
+                            return array_filter([
+                                'Manual servers' => Ookla::getConfigServers(),
+                                'Closest servers' => GetOoklaSpeedtestServers::run(),
+                            ]);
+                        })
                         ->searchable(),
                 ])
                 ->action(function (array $data) {
diff --git a/app/Helpers/Ookla.php b/app/Helpers/Ookla.php
index df6c34161..0773025bc 100644
--- a/app/Helpers/Ookla.php
+++ b/app/Helpers/Ookla.php
@@ -28,4 +28,28 @@ public static function getErrorMessage(ProcessFailedException $exception): strin
 
         return $errorMessage;
     }
+
+    public static function getConfigServers(): ?array
+    {
+        $list = [];
+
+        if (blank(config('speedtest.servers'))) {
+            return null;
+        }
+
+        $servers = collect(array_map(
+            'trim',
+            explode(',', config('speedtest.servers'))
+        ));
+
+        if (! count($servers)) {
+            return null;
+        }
+
+        $list = $servers->mapWithKeys(function ($serverId) {
+            return [$serverId => $serverId.' (Config server)'];
+        })->sort()->toArray();
+
+        return $list;
+    }
 }


Test patch:
diff --git a/config/speedtest.php b/config/speedtest.php
index 737755716..7989369d6 100644
--- a/config/speedtest.php
+++ b/config/speedtest.php
@@ -31,7 +31,7 @@
      */
     'schedule' => env('SPEEDTEST_SCHEDULE', false),
 
-    'servers' => env('SPEEDTEST_SERVERS', ''),
+    'servers' => env('SPEEDTEST_SERVERS'),
 
     /**
      * IP filtering settings.