Skip to content

Commit b5dbd0e

Browse files
alexjustesenvadius45Laurent Parodi
authored
Add default chart range (alexjustesen#2369)
Co-authored-by: Laurent P <[email protected]> Co-authored-by: Laurent Parodi <[email protected]> Co-authored-by: Alex Justesen <[email protected]>
1 parent 4994ae6 commit b5dbd0e

File tree

8 files changed

+56
-51
lines changed

8 files changed

+56
-51
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Filament\Widgets\Concerns;
4+
5+
trait HasChartFilters
6+
{
7+
protected function getFilters(): ?array
8+
{
9+
return [
10+
'24h' => 'Last 24 hours',
11+
'week' => 'Last 7 days',
12+
'month' => 'Last 30 days',
13+
];
14+
}
15+
}

app/Filament/Widgets/RecentDownloadChartWidget.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
namespace App\Filament\Widgets;
44

55
use App\Enums\ResultStatus;
6+
use App\Filament\Widgets\Concerns\HasChartFilters;
67
use App\Helpers\Average;
78
use App\Helpers\Number;
89
use App\Models\Result;
910
use Filament\Widgets\ChartWidget;
1011

1112
class RecentDownloadChartWidget extends ChartWidget
1213
{
14+
use HasChartFilters;
15+
1316
protected static ?string $heading = 'Download (Mbps)';
1417

1518
protected int|string|array $columnSpan = 'full';
@@ -18,15 +21,11 @@ class RecentDownloadChartWidget extends ChartWidget
1821

1922
protected static ?string $pollingInterval = '60s';
2023

21-
public ?string $filter = '24h';
24+
public ?string $filter = null;
2225

23-
protected function getFilters(): ?array
26+
public function mount(): void
2427
{
25-
return [
26-
'24h' => 'Last 24h',
27-
'week' => 'Last week',
28-
'month' => 'Last month',
29-
];
28+
$this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h');
3029
}
3130

3231
protected function getData(): array

app/Filament/Widgets/RecentDownloadLatencyChartWidget.php

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

55
use App\Enums\ResultStatus;
6+
use App\Filament\Widgets\Concerns\HasChartFilters;
67
use App\Models\Result;
78
use Filament\Widgets\ChartWidget;
89

910
class RecentDownloadLatencyChartWidget extends ChartWidget
1011
{
12+
use HasChartFilters;
13+
1114
protected static ?string $heading = 'Download Latency';
1215

1316
protected int|string|array $columnSpan = 'full';
@@ -16,15 +19,11 @@ class RecentDownloadLatencyChartWidget extends ChartWidget
1619

1720
protected static ?string $pollingInterval = '60s';
1821

19-
public ?string $filter = '24h';
22+
public ?string $filter = null;
2023

21-
protected function getFilters(): ?array
24+
public function mount(): void
2225
{
23-
return [
24-
'24h' => 'Last 24h',
25-
'week' => 'Last week',
26-
'month' => 'Last month',
27-
];
26+
$this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h');
2827
}
2928

3029
protected function getData(): array

app/Filament/Widgets/RecentJitterChartWidget.php

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

55
use App\Enums\ResultStatus;
6+
use App\Filament\Widgets\Concerns\HasChartFilters;
67
use App\Models\Result;
78
use Filament\Widgets\ChartWidget;
89

910
class RecentJitterChartWidget extends ChartWidget
1011
{
12+
use HasChartFilters;
13+
1114
protected static ?string $heading = 'Jitter';
1215

1316
protected int|string|array $columnSpan = 'full';
@@ -16,15 +19,11 @@ class RecentJitterChartWidget extends ChartWidget
1619

1720
protected static ?string $pollingInterval = '60s';
1821

19-
public ?string $filter = '24h';
22+
public ?string $filter = null;
2023

21-
protected function getFilters(): ?array
24+
public function mount(): void
2225
{
23-
return [
24-
'24h' => 'Last 24h',
25-
'week' => 'Last week',
26-
'month' => 'Last month',
27-
];
26+
$this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h');
2827
}
2928

3029
protected function getData(): array

app/Filament/Widgets/RecentPingChartWidget.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
namespace App\Filament\Widgets;
44

55
use App\Enums\ResultStatus;
6+
use App\Filament\Widgets\Concerns\HasChartFilters;
67
use App\Helpers\Average;
78
use App\Models\Result;
89
use Filament\Widgets\ChartWidget;
910

1011
class RecentPingChartWidget extends ChartWidget
1112
{
13+
use HasChartFilters;
14+
1215
protected static ?string $heading = 'Ping (ms)';
1316

1417
protected int|string|array $columnSpan = 'full';
@@ -17,15 +20,11 @@ class RecentPingChartWidget extends ChartWidget
1720

1821
protected static ?string $pollingInterval = '60s';
1922

20-
public ?string $filter = '24h';
23+
public ?string $filter = null;
2124

22-
protected function getFilters(): ?array
25+
public function mount(): void
2326
{
24-
return [
25-
'24h' => 'Last 24h',
26-
'week' => 'Last week',
27-
'month' => 'Last month',
28-
];
27+
$this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h');
2928
}
3029

3130
protected function getData(): array

app/Filament/Widgets/RecentUploadChartWidget.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
namespace App\Filament\Widgets;
44

55
use App\Enums\ResultStatus;
6+
use App\Filament\Widgets\Concerns\HasChartFilters;
67
use App\Helpers\Average;
78
use App\Helpers\Number;
89
use App\Models\Result;
910
use Filament\Widgets\ChartWidget;
1011

1112
class RecentUploadChartWidget extends ChartWidget
1213
{
14+
use HasChartFilters;
15+
1316
protected static ?string $heading = 'Upload (Mbps)';
1417

1518
protected int|string|array $columnSpan = 'full';
@@ -18,15 +21,11 @@ class RecentUploadChartWidget extends ChartWidget
1821

1922
protected static ?string $pollingInterval = '60s';
2023

21-
public ?string $filter = '24h';
24+
public ?string $filter = null;
2225

23-
protected function getFilters(): ?array
26+
public function mount(): void
2427
{
25-
return [
26-
'24h' => 'Last 24h',
27-
'week' => 'Last week',
28-
'month' => 'Last month',
29-
];
28+
$this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h');
3029
}
3130

3231
protected function getData(): array

app/Filament/Widgets/RecentUploadLatencyChartWidget.php

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

55
use App\Enums\ResultStatus;
6+
use App\Filament\Widgets\Concerns\HasChartFilters;
67
use App\Models\Result;
78
use Filament\Widgets\ChartWidget;
89

910
class RecentUploadLatencyChartWidget extends ChartWidget
1011
{
12+
use HasChartFilters;
13+
1114
protected static ?string $heading = 'Upload Latency';
1215

1316
protected int|string|array $columnSpan = 'full';
@@ -16,15 +19,11 @@ class RecentUploadLatencyChartWidget extends ChartWidget
1619

1720
protected static ?string $pollingInterval = '60s';
1821

19-
public ?string $filter = '24h';
22+
public ?string $filter = null;
2023

21-
protected function getFilters(): ?array
24+
public function mount(): void
2225
{
23-
return [
24-
'24h' => 'Last 24h',
25-
'week' => 'Last week',
26-
'month' => 'Last month',
27-
];
26+
$this->filter = $this->filter ?? config('speedtest.default_chart_range', '24h');
2827
}
2928

3029
protected function getData(): array

config/speedtest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
/**
77
* General settings.
88
*/
9-
109
'build_date' => Carbon::parse('2025-10-24'),
1110

1211
'build_version' => 'v1.6.9',
@@ -17,6 +16,7 @@
1716

1817
'public_dashboard' => env('PUBLIC_DASHBOARD', false),
1918

19+
'default_chart_range' => env('DEFAULT_CHART_RANGE', '24h'),
2020

2121
/**
2222
* Speedtest settings.
@@ -31,25 +31,21 @@
3131

3232
'checkinternet_url' => env('SPEEDTEST_CHECKINTERNET_URL', 'https://icanhazip.com'),
3333

34-
3534
/**
3635
* IP filtering settings.
3736
*/
38-
3937
'allowed_ips' => env('ALLOWED_IPS'),
4038

4139
'skip_ips' => env('SPEEDTEST_SKIP_IPS', ''),
4240

43-
4441
/**
4542
* Threshold settings.
4643
*/
44+
'threshold_enabled' => env('THRESHOLD_ENABLED', false),
4745

48-
'threshold_enabled' => env('THRESHOLD_ENABLED', false),
49-
50-
'threshold_download' => env('THRESHOLD_DOWNLOAD', 0),
46+
'threshold_download' => env('THRESHOLD_DOWNLOAD', 0),
5147

52-
'threshold_upload' => env('THRESHOLD_UPLOAD', 0),
48+
'threshold_upload' => env('THRESHOLD_UPLOAD', 0),
5349

54-
'threshold_ping' => env('THRESHOLD_PING', 0) ,
50+
'threshold_ping' => env('THRESHOLD_PING', 0),
5551
];

0 commit comments

Comments
 (0)