Skip to content

Commit 4a9153f

Browse files
authored
Performance thresholds (alexjustesen#85)
1 parent 4540f3f commit 4a9153f

16 files changed

+452
-58
lines changed

app/Filament/Pages/Settings/General.php renamed to app/Filament/Pages/Settings/GeneralPage.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
use Filament\Pages\SettingsPage;
1313
use Squire\Models\Timezone;
1414

15-
class General extends SettingsPage
15+
class GeneralPage extends SettingsPage
1616
{
1717
protected static ?string $navigationIcon = 'heroicon-o-cog';
1818

1919
protected static ?string $navigationGroup = 'Settings';
2020

2121
protected static ?int $navigationSort = 1;
2222

23+
protected static ?string $title = 'General';
24+
25+
protected static ?string $navigationLabel = 'General';
26+
2327
protected static string $settings = GeneralSettings::class;
2428

2529
protected function getFormSchema(): array
@@ -35,7 +39,6 @@ protected function getFormSchema(): array
3539
])
3640
->schema([
3741
Section::make('Site Settings')
38-
->collapsible()
3942
->schema([
4043
TextInput::make('site_name')
4144
->maxLength(50)
@@ -51,13 +54,13 @@ protected function getFormSchema(): array
5154
->maxLength(25)
5255
->required(),
5356
])
57+
->compact()
5458
->columns([
5559
'default' => 1,
5660
'md' => 2,
5761
]),
5862

5963
Section::make('Speedtest Settings')
60-
->collapsible()
6164
->schema([
6265
TextInput::make('speedtest_schedule')
6366
->helperText('Leave empty to disable the schedule. You can also use the cron expression generator [HERE](https://crontab.cronhub.io/) to help you make schedules.')
@@ -68,6 +71,7 @@ protected function getFormSchema(): array
6871
->nullable()
6972
->columnSpan(1),
7073
])
74+
->compact()
7175
->columns([
7276
'default' => 1,
7377
'md' => 2,

app/Filament/Pages/Settings/InfluxDb.php renamed to app/Filament/Pages/Settings/InfluxDbPage.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
namespace App\Filament\Pages\Settings;
44

55
use App\Settings\InfluxDbSettings;
6-
use Filament\Forms\Components\Card;
76
use Filament\Forms\Components\Grid;
87
use Filament\Forms\Components\Section;
98
use Filament\Forms\Components\TextInput;
109
use Filament\Forms\Components\Toggle;
1110
use Filament\Pages\SettingsPage;
1211

13-
class InfluxDb extends SettingsPage
12+
class InfluxDbPage extends SettingsPage
1413
{
1514
protected static ?string $navigationIcon = 'heroicon-o-database';
1615

17-
protected static ?string $navigationLabel = 'InfluxDB';
18-
1916
protected static ?string $navigationGroup = 'Settings';
2017

21-
protected static ?int $navigationSort = 2;
18+
protected static ?int $navigationSort = 3;
19+
20+
protected static ?string $title = 'InfluxDB';
21+
22+
protected static ?string $navigationLabel = 'InfluxDB';
2223

2324
protected static string $settings = InfluxDbSettings::class;
2425

@@ -35,8 +36,11 @@ protected function getFormSchema(): array
3536
])
3637
->schema([
3738
Section::make('InfluxDB v2 Settings')
38-
->collapsible()
3939
->schema([
40+
Toggle::make('v2_enabled')
41+
->label('Enabled')
42+
->inline(false)
43+
->columnSpan(2),
4044
TextInput::make('v2_url')
4145
->label('URL')
4246
->placeholder('http://your-influxdb-instance')
@@ -58,6 +62,7 @@ protected function getFormSchema(): array
5862
->disableAutocomplete()
5963
->columnSpan(['md' => 2]),
6064
])
65+
->compact()
6166
->columns([
6267
'default' => 1,
6368
'md' => 2,
@@ -66,16 +71,6 @@ protected function getFormSchema(): array
6671
->columnSpan([
6772
'md' => 2,
6873
]),
69-
70-
Card::make()
71-
->schema([
72-
Toggle::make('v2_enabled')
73-
->label('v2 enabled')
74-
->helperText('NOTE: At this time only InfluxDB v2 is supported'),
75-
])
76-
->columnSpan([
77-
'md' => 1,
78-
]),
7974
]),
8075
];
8176
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace App\Filament\Pages\Settings;
4+
5+
use App\Forms\Components\TestDatabaseNotification;
6+
use App\Settings\NotificationSettings;
7+
use Closure;
8+
use Filament\Forms\Components\Card;
9+
use Filament\Forms\Components\Fieldset;
10+
use Filament\Forms\Components\Grid;
11+
use Filament\Forms\Components\Section;
12+
use Filament\Forms\Components\Toggle;
13+
use Filament\Forms\Components\View;
14+
use Filament\Notifications\Notification;
15+
use Filament\Pages\SettingsPage;
16+
17+
class NotificationPage extends SettingsPage
18+
{
19+
protected static ?string $navigationIcon = 'heroicon-o-bell';
20+
21+
protected static ?string $navigationGroup = 'Settings';
22+
23+
protected static ?int $navigationSort = 2;
24+
25+
protected static ?string $title = 'Notifications';
26+
27+
protected static ?string $navigationLabel = 'Notifications';
28+
29+
protected static string $settings = NotificationSettings::class;
30+
31+
protected function getFormSchema(): array
32+
{
33+
return [
34+
Grid::make([
35+
'default' => 1,
36+
'md' => 3,
37+
])
38+
->schema([
39+
Grid::make([
40+
'default' => 1,
41+
])
42+
->schema([
43+
Section::make('Database')
44+
->description('Notifications sent to this channel will show up under the 🔔 icon in the header.')
45+
->schema([
46+
Toggle::make('database_enabled')
47+
->label('Enable database notifications')
48+
->reactive()
49+
->columnSpan(2),
50+
Grid::make([
51+
'default' => 1,
52+
])
53+
->hidden(fn (Closure $get) => $get('database_enabled') !== true)
54+
->schema([
55+
Fieldset::make('Triggers')
56+
->schema([
57+
Toggle::make('database_on_speedtest_run')
58+
->label('Notify on every speetest run')
59+
->columnSpan(2),
60+
Toggle::make('database_on_threshold_failure')
61+
->label('Notify on threshold failures')
62+
->columnSpan(2),
63+
]),
64+
TestDatabaseNotification::make('test channel'),
65+
]),
66+
])
67+
->compact()
68+
->columns([
69+
'default' => 1,
70+
'md' => 2,
71+
]),
72+
])
73+
->columnSpan([
74+
'md' => 2,
75+
]),
76+
77+
Card::make()
78+
->schema([
79+
View::make('filament.forms.notifications-helptext'),
80+
])
81+
->columnSpan([
82+
'md' => 1,
83+
]),
84+
]),
85+
];
86+
}
87+
88+
public function sendTestDatabaseNotification()
89+
{
90+
$recipient = auth()->user();
91+
92+
$recipient->notify(
93+
Notification::make()
94+
->title('Test database notification received!')
95+
->body('You say pong')
96+
->success()
97+
->toDatabase(),
98+
);
99+
100+
Notification::make()
101+
->title('Test database notification sent.')
102+
->body('I say ping')
103+
->success()
104+
->send();
105+
}
106+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace App\Filament\Pages\Settings;
4+
5+
use App\Settings\ThresholdSettings;
6+
use Closure;
7+
use Filament\Forms\Components\Card;
8+
use Filament\Forms\Components\Fieldset;
9+
use Filament\Forms\Components\Grid;
10+
use Filament\Forms\Components\Section;
11+
use Filament\Forms\Components\TextInput;
12+
use Filament\Forms\Components\Toggle;
13+
use Filament\Forms\Components\View;
14+
use Filament\Pages\SettingsPage;
15+
16+
class ThresholdsPage extends SettingsPage
17+
{
18+
protected static ?string $navigationIcon = 'heroicon-o-exclamation';
19+
20+
protected static ?string $navigationGroup = 'Settings';
21+
22+
protected static ?int $navigationSort = 4;
23+
24+
protected static ?string $title = 'Thresholds';
25+
26+
protected static ?string $navigationLabel = 'Thresholds';
27+
28+
protected static string $settings = ThresholdSettings::class;
29+
30+
protected function getFormSchema(): array
31+
{
32+
return [
33+
Grid::make([
34+
'default' => 1,
35+
'md' => 3,
36+
])
37+
->schema([
38+
Grid::make([
39+
'default' => 1,
40+
])
41+
->schema([
42+
Section::make('Absolute')
43+
->description('Absolute thresholds do not take into account previous history and could be triggered on each test.')
44+
->schema([
45+
Toggle::make('absolute_enabled')
46+
->label('Enable absolute thresholds')
47+
->reactive()
48+
->columnSpan(2),
49+
Grid::make([
50+
'default' => 1,
51+
])
52+
->hidden(fn (Closure $get) => $get('absolute_enabled') !== true)
53+
->schema([
54+
Fieldset::make('Metrics')
55+
->schema([
56+
TextInput::make('absolute_download')
57+
->label('Download')
58+
->hint('Mbps')
59+
->helperText('Leave empty to skip this metric.')
60+
->numeric(),
61+
TextInput::make('absolute_upload')
62+
->label('Upload')
63+
->hint('Mbps')
64+
->helperText('Leave empty to skip this metric.')
65+
->numeric(),
66+
TextInput::make('absolute_ping')
67+
->label('Ping')
68+
->hint('Ms')
69+
->helperText('Leave empty to skip this metric.')
70+
->numeric(),
71+
])
72+
->columns([
73+
'default' => 1,
74+
'md' => 2,
75+
]),
76+
]),
77+
])
78+
->compact()
79+
->columns([
80+
'default' => 1,
81+
'md' => 2,
82+
]),
83+
])
84+
->columnSpan([
85+
'md' => 2,
86+
]),
87+
88+
Card::make()
89+
->schema([
90+
View::make('filament.forms.thresholds-helptext'),
91+
])
92+
->columnSpan([
93+
'md' => 1,
94+
]),
95+
]),
96+
];
97+
}
98+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Forms\Components;
4+
5+
use Filament\Forms\Components\Field;
6+
7+
class TestDatabaseNotification extends Field
8+
{
9+
protected string $view = 'forms.components.test-database-notification';
10+
}

0 commit comments

Comments
 (0)