diff --git a/app/Filament/Widgets/RecentDownloadChartWidget.php b/app/Filament/Widgets/RecentDownloadChartWidget.php index 53feffba4..1f9dee427 100644 --- a/app/Filament/Widgets/RecentDownloadChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadChartWidget.php @@ -18,15 +18,28 @@ class RecentDownloadChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; protected function getFilters(): ?array { - return [ + $default = config('speedtest.default_view_range'); + $filters = [ + $default => 'Default (' . ucfirst($default) . ')', '24h' => 'Last 24h', 'week' => 'Last week', 'month' => 'Last month', ]; + + // Remove duplicate if default is one of the others + $filters = array_unique($filters); + + // Ensure default is first + $filters = array_merge( + [$default => $filters[$default]], + array_diff_key($filters, [$default => null]) + ); + + return $filters; } protected function getData(): array diff --git a/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php b/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php index 6b75ffc97..2cc3c8298 100644 --- a/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php @@ -16,15 +16,28 @@ class RecentDownloadLatencyChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; protected function getFilters(): ?array { - return [ + $default = config('speedtest.default_view_range'); + $filters = [ + $default => 'Default (' . ucfirst($default) . ')', '24h' => 'Last 24h', 'week' => 'Last week', 'month' => 'Last month', ]; + + // Remove duplicate if default is one of the others + $filters = array_unique($filters); + + // Ensure default is first + $filters = array_merge( + [$default => $filters[$default]], + array_diff_key($filters, [$default => null]) + ); + + return $filters; } protected function getData(): array diff --git a/app/Filament/Widgets/RecentJitterChartWidget.php b/app/Filament/Widgets/RecentJitterChartWidget.php index 0c88525d6..4f3ee2226 100644 --- a/app/Filament/Widgets/RecentJitterChartWidget.php +++ b/app/Filament/Widgets/RecentJitterChartWidget.php @@ -16,15 +16,28 @@ class RecentJitterChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; protected function getFilters(): ?array { - return [ + $default = config('speedtest.default_view_range'); + $filters = [ + $default => 'Default (' . ucfirst($default) . ')', '24h' => 'Last 24h', 'week' => 'Last week', 'month' => 'Last month', ]; + + // Remove duplicate if default is one of the others + $filters = array_unique($filters); + + // Ensure default is first + $filters = array_merge( + [$default => $filters[$default]], + array_diff_key($filters, [$default => null]) + ); + + return $filters; } protected function getData(): array diff --git a/app/Filament/Widgets/RecentPingChartWidget.php b/app/Filament/Widgets/RecentPingChartWidget.php index 5077cc6be..b63334fa6 100644 --- a/app/Filament/Widgets/RecentPingChartWidget.php +++ b/app/Filament/Widgets/RecentPingChartWidget.php @@ -17,15 +17,28 @@ class RecentPingChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; protected function getFilters(): ?array { - return [ + $default = config('speedtest.default_view_range'); + $filters = [ + $default => 'Default (' . ucfirst($default) . ')', '24h' => 'Last 24h', 'week' => 'Last week', 'month' => 'Last month', ]; + + // Remove duplicate if default is one of the others + $filters = array_unique($filters); + + // Ensure default is first + $filters = array_merge( + [$default => $filters[$default]], + array_diff_key($filters, [$default => null]) + ); + + return $filters; } protected function getData(): array diff --git a/app/Filament/Widgets/RecentUploadChartWidget.php b/app/Filament/Widgets/RecentUploadChartWidget.php index d58d5c38e..e857f9662 100644 --- a/app/Filament/Widgets/RecentUploadChartWidget.php +++ b/app/Filament/Widgets/RecentUploadChartWidget.php @@ -18,15 +18,28 @@ class RecentUploadChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; protected function getFilters(): ?array { - return [ + $default = config('speedtest.default_view_range'); + $filters = [ + $default => 'Default (' . ucfirst($default) . ')', '24h' => 'Last 24h', 'week' => 'Last week', 'month' => 'Last month', ]; + + // Remove duplicate if default is one of the others + $filters = array_unique($filters); + + // Ensure default is first + $filters = array_merge( + [$default => $filters[$default]], + array_diff_key($filters, [$default => null]) + ); + + return $filters; } protected function getData(): array diff --git a/app/Filament/Widgets/RecentUploadLatencyChartWidget.php b/app/Filament/Widgets/RecentUploadLatencyChartWidget.php index 08f2808b4..73c1c0a1a 100644 --- a/app/Filament/Widgets/RecentUploadLatencyChartWidget.php +++ b/app/Filament/Widgets/RecentUploadLatencyChartWidget.php @@ -16,15 +16,28 @@ class RecentUploadLatencyChartWidget extends ChartWidget protected static ?string $pollingInterval = '60s'; - public ?string $filter = '24h'; + public ?string $filter = null; protected function getFilters(): ?array { - return [ + $default = config('speedtest.default_view_range'); + $filters = [ + $default => 'Default (' . ucfirst($default) . ')', '24h' => 'Last 24h', 'week' => 'Last week', 'month' => 'Last month', ]; + + // Remove duplicate if default is one of the others + $filters = array_unique($filters); + + // Ensure default is first + $filters = array_merge( + [$default => $filters[$default]], + array_diff_key($filters, [$default => null]) + ); + + return $filters; } protected function getData(): array diff --git a/config/speedtest.php b/config/speedtest.php index 944a9dac9..65a05f170 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -17,6 +17,8 @@ 'public_dashboard' => env('PUBLIC_DASHBOARD', false), + 'default_view_range' => env('DEFAULT_VIEW_RANGE', '24h'), + /** * Speedtest settings.