diff --git a/app/Filament/Pages/Settings/DataIntegrationPage.php b/app/Filament/Pages/Settings/DataIntegrationPage.php index d49792ca4..391577432 100644 --- a/app/Filament/Pages/Settings/DataIntegrationPage.php +++ b/app/Filament/Pages/Settings/DataIntegrationPage.php @@ -6,6 +6,12 @@ use App\Jobs\Influxdb\v2\TestConnectionJob; use App\Settings\DataIntegrationSettings; use Filament\Forms; +use Filament\Forms\Components\Actions; +use Filament\Forms\Components\Actions\Action; +use Filament\Forms\Components\Checkbox; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Notifications\Notification; use Filament\Pages\SettingsPage; @@ -27,63 +33,63 @@ class DataIntegrationPage extends SettingsPage public static function canAccess(): bool { - return auth()->user()->is_admin; + return Auth::check() && Auth::user()->is_admin; } public static function shouldRegisterNavigation(): bool { - return auth()->user()->is_admin; + return Auth::check() && Auth::user()->is_admin; } public function form(Form $form): Form { return $form ->schema([ - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, 'md' => 3, ]) ->schema([ - Forms\Components\Section::make('InfluxDB v2') + Section::make('InfluxDB v2') ->description('When enabled, all new Speedtest results will also be sent to InfluxDB.') ->schema([ Forms\Components\Toggle::make('influxdb_v2_enabled') ->label('Enable') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make(['default' => 1, 'md' => 3]) + Grid::make(['default' => 1, 'md' => 3]) ->hidden(fn (Forms\Get $get) => $get('influxdb_v2_enabled') !== true) ->schema([ - Forms\Components\TextInput::make('influxdb_v2_url') + TextInput::make('influxdb_v2_url') ->label('URL') ->placeholder('http://your-influxdb-instance') ->maxLength(255) ->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true) ->columnSpan(['md' => 1]), - Forms\Components\TextInput::make('influxdb_v2_org') + TextInput::make('influxdb_v2_org') ->label('Org') ->maxLength(255) ->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true) ->columnSpan(['md' => 1]), - Forms\Components\TextInput::make('influxdb_v2_bucket') + TextInput::make('influxdb_v2_bucket') ->placeholder('speedtest-tracker') ->label('Bucket') ->maxLength(255) ->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true) ->columnSpan(['md' => 2]), - Forms\Components\TextInput::make('influxdb_v2_token') + TextInput::make('influxdb_v2_token') ->label('Token') ->maxLength(255) ->password() ->required(fn (Forms\Get $get) => $get('influxdb_v2_enabled') === true) ->disableAutocomplete() ->columnSpan(['md' => 2]), - Forms\Components\Checkbox::make('influxdb_v2_verify_ssl') + Checkbox::make('influxdb_v2_verify_ssl') ->label('Verify SSL') ->columnSpanFull(), // Button to send old data to InfluxDB - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('Export current results') + Actions::make([ + Action::make('Export current results') ->label('Export current results') ->action(function () { Notification::make() @@ -98,8 +104,8 @@ public function form(Form $form): Form ->visible(fn (): bool => app(DataIntegrationSettings::class)->influxdb_v2_enabled), ]), // Button to test InfluxDB connection - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('Test connection') + Actions::make([ + Action::make('Test connection') ->label('Test connection') ->action(function () { Notification::make() diff --git a/app/Filament/Pages/Settings/NotificationPage.php b/app/Filament/Pages/Settings/NotificationPage.php index bd7df5902..070a4c122 100755 --- a/app/Filament/Pages/Settings/NotificationPage.php +++ b/app/Filament/Pages/Settings/NotificationPage.php @@ -14,6 +14,13 @@ use App\Actions\Notifications\SendWebhookTestNotification; use App\Settings\NotificationSettings; use Filament\Forms; +use Filament\Forms\Components\Actions; +use Filament\Forms\Components\Actions\Action; +use Filament\Forms\Components\Fieldset; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Repeater; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\Toggle; use Filament\Forms\Form; use Filament\Pages\SettingsPage; use Illuminate\Support\Facades\Auth; @@ -34,50 +41,50 @@ class NotificationPage extends SettingsPage public static function canAccess(): bool { - return auth()->user()->is_admin; + return Auth::check() && Auth::user()->is_admin; } public static function shouldRegisterNavigation(): bool { - return auth()->user()->is_admin; + return Auth::check() && Auth::user()->is_admin; } public function form(Form $form): Form { return $form ->schema([ - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, 'md' => 3, ]) ->schema([ - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->schema([ - Forms\Components\Section::make('Database') + Section::make('Database') ->description('Notifications sent to this channel will show up under the 🔔 icon in the header.') ->schema([ - Forms\Components\Toggle::make('database_enabled') + Toggle::make('database_enabled') ->label('Enable database notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('database_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('database_on_speedtest_run') + Toggle::make('database_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('database_on_threshold_failure') + Toggle::make('database_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test database') + Actions::make([ + Action::make('test database') ->label('Test database channel') ->action(fn () => SendDatabaseTestNotification::run(user: Auth::user())), ]), @@ -89,27 +96,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Pushover') + Section::make('Pushover') ->schema([ - Forms\Components\Toggle::make('pushover_enabled') + Toggle::make('pushover_enabled') ->label('Enable Pushover webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('pushover_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('pushover_on_speedtest_run') + Toggle::make('pushover_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('pushover_on_threshold_failure') + Toggle::make('pushover_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('pushover_webhooks') + Repeater::make('pushover_webhooks') ->label('Pushover Webhooks') ->schema([ Forms\Components\TextInput::make('url') @@ -130,8 +137,8 @@ public function form(Form $form): Form ->required(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test pushover') + Actions::make([ + Action::make('test pushover') ->label('Test Pushover webhook') ->action(fn (Forms\Get $get) => SendPushoverTestNotification::run( webhooks: $get('pushover_webhooks') @@ -146,27 +153,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Discord') + Section::make('Discord') ->schema([ - Forms\Components\Toggle::make('discord_enabled') + Toggle::make('discord_enabled') ->label('Enable Discord webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('discord_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('discord_on_speedtest_run') + Toggle::make('discord_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('discord_on_threshold_failure') + Toggle::make('discord_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('discord_webhooks') + Repeater::make('discord_webhooks') ->label('Webhooks') ->schema([ Forms\Components\TextInput::make('url') @@ -176,8 +183,8 @@ public function form(Form $form): Form ->url(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test discord') + Actions::make([ + Action::make('test discord') ->label('Test Discord webhook') ->action(fn (Forms\Get $get) => SendDiscordTestNotification::run(webhooks: $get('discord_webhooks'))) ->hidden(fn (Forms\Get $get) => ! count($get('discord_webhooks'))), @@ -190,27 +197,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Gotify') + Section::make('Gotify') ->schema([ - Forms\Components\Toggle::make('gotify_enabled') + Toggle::make('gotify_enabled') ->label('Enable Gotify webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('gotify_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('gotify_on_speedtest_run') + Toggle::make('gotify_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('gotify_on_threshold_failure') + Toggle::make('gotify_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('gotify_webhooks') + Repeater::make('gotify_webhooks') ->label('Webhooks') ->schema([ Forms\Components\TextInput::make('url') @@ -220,8 +227,8 @@ public function form(Form $form): Form ->url(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test gotify') + Actions::make([ + Action::make('test gotify') ->label('Test Gotify webhook') ->action(fn (Forms\Get $get) => SendgotifyTestNotification::run(webhooks: $get('gotify_webhooks'))) ->hidden(fn (Forms\Get $get) => ! count($get('gotify_webhooks'))), @@ -234,27 +241,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Slack') + Section::make('Slack') ->schema([ - Forms\Components\Toggle::make('slack_enabled') + Toggle::make('slack_enabled') ->label('Enable Slack webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('slack_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('slack_on_speedtest_run') + Toggle::make('slack_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('slack_on_threshold_failure') + Toggle::make('slack_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('slack_webhooks') + Repeater::make('slack_webhooks') ->label('Webhooks') ->schema([ Forms\Components\TextInput::make('url') @@ -264,8 +271,8 @@ public function form(Form $form): Form ->url(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test Slack') + Actions::make([ + Action::make('test Slack') ->label('Test slack webhook') ->action(fn (Forms\Get $get) => SendSlackTestNotification::run(webhooks: $get('slack_webhooks'))) ->hidden(fn (Forms\Get $get) => ! count($get('slack_webhooks'))), @@ -278,27 +285,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Ntfy') + Section::make('Ntfy') ->schema([ - Forms\Components\Toggle::make('ntfy_enabled') + Toggle::make('ntfy_enabled') ->label('Enable Ntfy webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('ntfy_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('ntfy_on_speedtest_run') + Toggle::make('ntfy_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('ntfy_on_threshold_failure') + Toggle::make('ntfy_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('ntfy_webhooks') + Repeater::make('ntfy_webhooks') ->label('Webhooks') ->schema([ Forms\Components\TextInput::make('url') @@ -322,8 +329,8 @@ public function form(Form $form): Form ->maxLength(200), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test ntfy') + Actions::make([ + Action::make('test ntfy') ->label('Test Ntfy webhook') ->action(fn (Forms\Get $get) => SendNtfyTestNotification::run(webhooks: $get('ntfy_webhooks'))) ->hidden(fn (Forms\Get $get) => ! count($get('ntfy_webhooks'))), @@ -336,27 +343,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Mail') + Section::make('Mail') ->schema([ - Forms\Components\Toggle::make('mail_enabled') + Toggle::make('mail_enabled') ->label('Enable mail notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('mail_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('mail_on_speedtest_run') + Toggle::make('mail_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('mail_on_threshold_failure') + Toggle::make('mail_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('mail_recipients') + Repeater::make('mail_recipients') ->label('Recipients') ->schema([ Forms\Components\TextInput::make('email_address') @@ -365,8 +372,8 @@ public function form(Form $form): Form ->required(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test mail') + Actions::make([ + Action::make('test mail') ->label('Test mail channel') ->action(fn (Forms\Get $get) => SendMailTestNotification::run(recipients: $get('mail_recipients'))) ->hidden(fn (Forms\Get $get) => ! count($get('mail_recipients'))), @@ -379,28 +386,28 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Healthcheck.io') + Section::make('Healthcheck.io') ->schema([ - Forms\Components\Toggle::make('healthcheck_enabled') + Toggle::make('healthcheck_enabled') ->label('Enable healthcheck.io webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('healthcheck_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('healthcheck_on_speedtest_run') + Toggle::make('healthcheck_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('healthcheck_on_threshold_failure') + Toggle::make('healthcheck_on_threshold_failure') ->label('Notify on threshold failures') ->helperText('Threshold notifications will be sent to the /fail path of the URL.') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('healthcheck_webhooks') + Repeater::make('healthcheck_webhooks') ->label('webhooks') ->schema([ Forms\Components\TextInput::make('url') @@ -410,8 +417,8 @@ public function form(Form $form): Form ->url(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test healthcheck') + Actions::make([ + Action::make('test healthcheck') ->label('Test healthcheck.io webhook') ->action(fn (Forms\Get $get) => SendHealthCheckTestNotification::run(webhooks: $get('healthcheck_webhooks'))) ->hidden(fn (Forms\Get $get) => ! count($get('healthcheck_webhooks'))), @@ -424,33 +431,33 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Telegram') + Section::make('Telegram') ->schema([ - Forms\Components\Toggle::make('telegram_enabled') + Toggle::make('telegram_enabled') ->label('Enable telegram notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('telegram_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Options') + Fieldset::make('Options') ->schema([ - Forms\Components\Toggle::make('telegram_disable_notification') + Toggle::make('telegram_disable_notification') ->label('Send the message silently to the user') ->columnSpanFull(), ]), - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('telegram_on_speedtest_run') + Toggle::make('telegram_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpanFull(), - Forms\Components\Toggle::make('telegram_on_threshold_failure') + Toggle::make('telegram_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpanFull(), ]), - Forms\Components\Repeater::make('telegram_recipients') + Repeater::make('telegram_recipients') ->label('Recipients') ->schema([ Forms\Components\TextInput::make('telegram_chat_id') @@ -460,8 +467,8 @@ public function form(Form $form): Form ->required(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test telegram') + Actions::make([ + Action::make('test telegram') ->label('Test Telegram channel') ->action(fn (Forms\Get $get) => SendTelegramTestNotification::run(recipients: $get('telegram_recipients'))) ->hidden(fn (Forms\Get $get) => ! count($get('telegram_recipients')) || blank(config('telegram.bot'))), @@ -474,27 +481,27 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Webhook') + Section::make('Webhook') ->schema([ - Forms\Components\Toggle::make('webhook_enabled') + Toggle::make('webhook_enabled') ->label('Enable webhook notifications') ->reactive() ->columnSpanFull(), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('webhook_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Triggers') + Fieldset::make('Triggers') ->schema([ - Forms\Components\Toggle::make('webhook_on_speedtest_run') + Toggle::make('webhook_on_speedtest_run') ->label('Notify on every speedtest run') ->columnSpan(2), - Forms\Components\Toggle::make('webhook_on_threshold_failure') + Toggle::make('webhook_on_threshold_failure') ->label('Notify on threshold failures') ->columnSpan(2), ]), - Forms\Components\Repeater::make('webhook_urls') + Repeater::make('webhook_urls') ->label('Recipients') ->schema([ Forms\Components\TextInput::make('url') @@ -504,8 +511,8 @@ public function form(Form $form): Form ->url(), ]) ->columnSpanFull(), - Forms\Components\Actions::make([ - Forms\Components\Actions\Action::make('test webhook') + Actions::make([ + Action::make('test webhook') ->label('Test webhook channel') ->action(fn (Forms\Get $get) => SendWebhookTestNotification::run(webhooks: $get('webhook_urls'))) ->hidden(fn (Forms\Get $get) => ! count($get('webhook_urls'))), @@ -522,7 +529,7 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make() + Section::make() ->schema([ Forms\Components\View::make('filament.forms.notifications-helptext'), ]) diff --git a/app/Filament/Pages/Settings/ThresholdsPage.php b/app/Filament/Pages/Settings/ThresholdsPage.php index 7f60ba5f5..3dc749bd7 100644 --- a/app/Filament/Pages/Settings/ThresholdsPage.php +++ b/app/Filament/Pages/Settings/ThresholdsPage.php @@ -4,8 +4,15 @@ use App\Settings\ThresholdSettings; use Filament\Forms; +use Filament\Forms\Components\Fieldset; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\TextInput; +use Filament\Forms\Components\Toggle; +use Filament\Forms\Components\View; use Filament\Forms\Form; use Filament\Pages\SettingsPage; +use Illuminate\Support\Facades\Auth; class ThresholdsPage extends SettingsPage { @@ -23,42 +30,42 @@ class ThresholdsPage extends SettingsPage public static function canAccess(): bool { - return auth()->user()->is_admin; + return Auth::check() && Auth::user()->is_admin; } public static function shouldRegisterNavigation(): bool { - return auth()->user()->is_admin; + return Auth::check() && Auth::user()->is_admin; } public function form(Form $form): Form { return $form ->schema([ - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, 'md' => 3, ]) ->schema([ - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->schema([ - Forms\Components\Section::make('Absolute') + Section::make('Absolute') ->description('Absolute thresholds do not take into account previous history and could be triggered on each test.') ->schema([ - Forms\Components\Toggle::make('absolute_enabled') + Toggle::make('absolute_enabled') ->label('Enable absolute thresholds') ->reactive() ->columnSpan(2), - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ]) ->hidden(fn (Forms\Get $get) => $get('absolute_enabled') !== true) ->schema([ - Forms\Components\Fieldset::make('Metrics') + Fieldset::make('Metrics') ->schema([ - Forms\Components\TextInput::make('absolute_download') + TextInput::make('absolute_download') ->label('Download') ->hint('Mbps') ->helperText('Set to zero to disable this metric.') @@ -66,7 +73,7 @@ public function form(Form $form): Form ->minValue(0) ->numeric() ->required(), - Forms\Components\TextInput::make('absolute_upload') + TextInput::make('absolute_upload') ->label('Upload') ->hint('Mbps') ->helperText('Set to zero to disable this metric.') @@ -74,7 +81,7 @@ public function form(Form $form): Form ->minValue(0) ->numeric() ->required(), - Forms\Components\TextInput::make('absolute_ping') + TextInput::make('absolute_ping') ->label('Ping') ->hint('ms') ->helperText('Set to zero to disable this metric.') @@ -99,9 +106,9 @@ public function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make() + Section::make() ->schema([ - Forms\Components\View::make('filament.forms.thresholds-helptext'), + View::make('filament.forms.thresholds-helptext'), ]) ->columnSpan([ 'md' => 1, diff --git a/app/Filament/Resources/ResultResource.php b/app/Filament/Resources/ResultResource.php index e4230f5a1..f47681567 100644 --- a/app/Filament/Resources/ResultResource.php +++ b/app/Filament/Resources/ResultResource.php @@ -10,12 +10,25 @@ use App\Models\Result; use Carbon\Carbon; use Filament\Forms; +use Filament\Forms\Components\Checkbox; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Placeholder; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Support\Enums\Alignment; -use Filament\Tables; use Filament\Tables\Actions\Action; +use Filament\Tables\Actions\ActionGroup; +use Filament\Tables\Actions\DeleteAction; +use Filament\Tables\Actions\DeleteBulkAction; +use Filament\Tables\Actions\ExportAction; +use Filament\Tables\Actions\ViewAction; +use Filament\Tables\Columns\IconColumn; +use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; +use Filament\Tables\Filters\TernaryFilter; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; @@ -30,73 +43,73 @@ class ResultResource extends Resource public static function form(Form $form): Form { return $form->schema([ - Forms\Components\Grid::make(['default' => 2, 'md' => 3])->schema([ - Forms\Components\Grid::make()->schema([ - Forms\Components\Section::make('Result Overview')->schema([ - Forms\Components\TextInput::make('id') + Grid::make(['default' => 2, 'md' => 3])->schema([ + Grid::make()->schema([ + Section::make('Result Overview')->schema([ + TextInput::make('id') ->label('ID'), - Forms\Components\TextInput::make('created_at') + TextInput::make('created_at') ->label('Created') ->afterStateHydrated(function (TextInput $component, $state) { $component->state(Carbon::parse($state) ->timezone(config('app.display_timezone')) ->format(config('app.datetime_format'))); }), - Forms\Components\TextInput::make('download') + TextInput::make('download') ->label('Download') ->afterStateHydrated(fn ($component, Result $record) => $component->state(! blank($record->download) ? Number::toBitRate(bits: $record->download_bits, precision: 2) : '')), - Forms\Components\TextInput::make('upload') + TextInput::make('upload') ->label('Upload') ->afterStateHydrated(fn ($component, Result $record) => $component->state(! blank($record->upload) ? Number::toBitRate(bits: $record->upload_bits, precision: 2) : '')), - Forms\Components\TextInput::make('ping') + TextInput::make('ping') ->label('Ping') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.packetLoss') + TextInput::make('data.packetLoss') ->label('Packet Loss') ->formatStateUsing(fn ($state) => number_format((float) $state, 2, '.', '').' %'), ])->columns(2), - Forms\Components\Section::make('Download Latency') + Section::make('Download Latency') ->schema([ - Forms\Components\TextInput::make('data.download.latency.jitter')->label('Jitter') + TextInput::make('data.download.latency.jitter')->label('Jitter') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.download.latency.high')->label('High') + TextInput::make('data.download.latency.high')->label('High') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.download.latency.low')->label('Low') + TextInput::make('data.download.latency.low')->label('Low') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.download.latency.iqm')->label('IQM') + TextInput::make('data.download.latency.iqm')->label('IQM') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), ]) ->columns(2) ->collapsed(), - Forms\Components\Section::make('Upload Latency') + Section::make('Upload Latency') ->schema([ - Forms\Components\TextInput::make('data.upload.latency.jitter')->label('Jitter') + TextInput::make('data.upload.latency.jitter')->label('Jitter') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.upload.latency.high')->label('High') + TextInput::make('data.upload.latency.high')->label('High') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.upload.latency.low')->label('Low') + TextInput::make('data.upload.latency.low')->label('Low') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.upload.latency.iqm')->label('IQM') + TextInput::make('data.upload.latency.iqm')->label('IQM') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), ]) ->columns(2) ->collapsed(), - Forms\Components\Section::make('Ping Details') + Section::make('Ping Details') ->schema([ - Forms\Components\TextInput::make('data.ping.jitter')->label('Jitter') + TextInput::make('data.ping.jitter')->label('Jitter') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.ping.low')->label('Low') + TextInput::make('data.ping.low')->label('Low') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), - Forms\Components\TextInput::make('data.ping.high')->label('High') + TextInput::make('data.ping.high')->label('High') ->formatStateUsing(fn ($state) => number_format((float) $state, 0, '.', '').' ms'), ]) ->columns(2) ->collapsed(), - Forms\Components\Textarea::make('data.message') + Textarea::make('data.message') ->label('Message') ->hint(new HtmlString('🔗Error Messages')) ->columnSpanFull(), @@ -105,26 +118,26 @@ public static function form(Form $form): Form 'md' => 2, ]), - Forms\Components\Section::make('Server & Metadata')->schema([ - Forms\Components\Placeholder::make('service') + Section::make('Server & Metadata')->schema([ + Placeholder::make('service') ->content(fn (Result $result): string => $result->service->getLabel()), - Forms\Components\Placeholder::make('server_name') + Placeholder::make('server_name') ->content(fn (Result $result): ?string => $result->server_name), - Forms\Components\Placeholder::make('server_id') + Placeholder::make('server_id') ->label('Server ID') ->content(fn (Result $result): ?string => $result->server_id), - Forms\Components\Placeholder::make('isp') + Placeholder::make('isp') ->label('ISP') ->content(fn (Result $result): ?string => $result->isp), - Forms\Components\Placeholder::make('server_location') + Placeholder::make('server_location') ->label('Server Location') ->content(fn (Result $result): ?string => $result->server_location), - Forms\Components\Placeholder::make('server_host') + Placeholder::make('server_host') ->content(fn (Result $result): ?string => $result->server_host), - Forms\Components\Placeholder::make('comment') + Placeholder::make('comment') ->content(fn (Result $result): ?string => $result->comments), - Forms\Components\Checkbox::make('scheduled'), - Forms\Components\Checkbox::make('healthy'), + Checkbox::make('scheduled'), + Checkbox::make('healthy'), ])->columns(1)->columnSpan([ 'default' => 2, 'md' => 1, @@ -137,58 +150,58 @@ public static function table(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('id') + TextColumn::make('id') ->label('ID') ->sortable(), - Tables\Columns\TextColumn::make('data.interface.externalIp') + TextColumn::make('data.interface.externalIp') ->label('IP address') ->toggleable() ->toggledHiddenByDefault() ->sortable(query: function (Builder $query, string $direction): Builder { return $query->orderBy('data->interface->externalIp', $direction); }), - Tables\Columns\TextColumn::make('service') + TextColumn::make('service') ->toggleable() ->toggledHiddenByDefault() ->sortable(), - Tables\Columns\TextColumn::make('data.server.id') + TextColumn::make('data.server.id') ->label('Server ID') ->toggleable() ->sortable(query: function (Builder $query, string $direction): Builder { return $query->orderBy('data->server->id', $direction); }), - Tables\Columns\TextColumn::make('data.isp') + TextColumn::make('data.isp') ->label('ISP') ->toggleable() ->toggledHiddenByDefault() ->sortable(query: function (Builder $query, string $direction): Builder { return $query->orderBy('data->isp', $direction); }), - Tables\Columns\TextColumn::make('data.server.location') + TextColumn::make('data.server.location') ->label('Server Location') ->toggleable() ->toggledHiddenByDefault() ->sortable(query: function (Builder $query, string $direction): Builder { return $query->orderBy('data->server->location', $direction); }), - Tables\Columns\TextColumn::make('data.server.name') + TextColumn::make('data.server.name') ->toggleable() ->sortable(query: function (Builder $query, string $direction): Builder { return $query->orderBy('data->server->name', $direction); }), - Tables\Columns\TextColumn::make('download') + TextColumn::make('download') ->getStateUsing(fn (Result $record): ?string => ! blank($record->download) ? Number::toBitRate(bits: $record->download_bits, precision: 2) : null) ->sortable(), - Tables\Columns\TextColumn::make('upload') + TextColumn::make('upload') ->getStateUsing(fn (Result $record): ?string => ! blank($record->upload) ? Number::toBitRate(bits: $record->upload_bits, precision: 2) : null) ->sortable(), - Tables\Columns\TextColumn::make('ping') + TextColumn::make('ping') ->toggleable() ->sortable() ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.download.latency.jitter') + TextColumn::make('data.download.latency.jitter') ->label('Download jitter') ->toggleable() ->toggledHiddenByDefault() @@ -198,7 +211,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.download.latency.high') + TextColumn::make('data.download.latency.high') ->label('Download latency high') ->toggleable() ->toggledHiddenByDefault() @@ -208,7 +221,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.download.latency.low') + TextColumn::make('data.download.latency.low') ->label('Download latency low') ->toggleable() ->toggledHiddenByDefault() @@ -218,7 +231,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.download.latency.iqm') + TextColumn::make('data.download.latency.iqm') ->label('Download latency iqm') ->toggleable() ->toggledHiddenByDefault() @@ -228,7 +241,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.upload.latency.jitter') + TextColumn::make('data.upload.latency.jitter') ->label('Upload jitter') ->toggleable() ->toggledHiddenByDefault() @@ -238,7 +251,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.upload.latency.high') + TextColumn::make('data.upload.latency.high') ->label('Upload latency high') ->toggleable() ->toggledHiddenByDefault() @@ -248,7 +261,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.upload.latency.low') + TextColumn::make('data.upload.latency.low') ->label('Upload latency low') ->toggleable() ->toggledHiddenByDefault() @@ -258,7 +271,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.upload.latency.iqm') + TextColumn::make('data.upload.latency.iqm') ->label('Upload latency iqm') ->toggleable() ->toggledHiddenByDefault() @@ -268,7 +281,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.ping.jitter') + TextColumn::make('data.ping.jitter') ->label('Ping jitter') ->toggleable() ->toggledHiddenByDefault() @@ -278,7 +291,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.ping.low') + TextColumn::make('data.ping.low') ->label('Ping low') ->toggleable() ->toggledHiddenByDefault() @@ -288,7 +301,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('data.ping.high') + TextColumn::make('data.ping.high') ->label('Ping high') ->toggleable() ->toggledHiddenByDefault() @@ -298,7 +311,7 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), - Tables\Columns\TextColumn::make('packet_loss') + TextColumn::make('packet_loss') ->toggleable() ->toggledHiddenByDefault() ->sortable(query: function (Builder $query, string $direction): Builder { @@ -307,35 +320,35 @@ public static function table(Table $table): Table ->formatStateUsing(function ($state) { return number_format((float) $state, 2, '.', '').' %'; }), - Tables\Columns\TextColumn::make('status') + TextColumn::make('status') ->badge() ->toggleable() ->sortable(), - Tables\Columns\IconColumn::make('scheduled') + IconColumn::make('scheduled') ->boolean() ->toggleable() ->toggledHiddenByDefault() ->alignment(Alignment::Center), - Tables\Columns\IconColumn::make('healthy') + IconColumn::make('healthy') ->boolean() ->toggleable() ->toggledHiddenByDefault() ->sortable() ->alignment(Alignment::Center), - Tables\Columns\TextColumn::make('data.message') + TextColumn::make('data.message') ->label('Error Message') ->limit(15) ->tooltip(fn ($state) => $state) ->toggleable() ->toggledHiddenByDefault() ->sortable(), - Tables\Columns\TextColumn::make('created_at') + TextColumn::make('created_at') ->dateTime(config('app.datetime_format')) ->timezone(config('app.display_timezone')) ->toggleable() ->sortable() ->alignment(Alignment::End), - Tables\Columns\TextColumn::make('updated_at') + TextColumn::make('updated_at') ->dateTime(config('app.datetime_format')) ->timezone(config('app.display_timezone')) ->toggleable() @@ -344,7 +357,7 @@ public static function table(Table $table): Table ->alignment(Alignment::End), ]) ->filters([ - Tables\Filters\SelectFilter::make('ip_address') + SelectFilter::make('ip_address') ->label('IP address') ->multiple() ->options(function (): array { @@ -361,7 +374,7 @@ public static function table(Table $table): Table ->toArray(); }) ->attribute('data->interface->externalIp'), - Tables\Filters\SelectFilter::make('server_name') + SelectFilter::make('server_name') ->label('Server name') ->multiple() ->options(function (): array { @@ -378,7 +391,7 @@ public static function table(Table $table): Table ->toArray(); }) ->attribute('data->server->name'), - Tables\Filters\TernaryFilter::make('scheduled') + TernaryFilter::make('scheduled') ->nullable() ->trueLabel('Only scheduled speedtests') ->falseLabel('Only manual speedtests') @@ -387,10 +400,10 @@ public static function table(Table $table): Table false: fn (Builder $query) => $query->where('scheduled', false), blank: fn (Builder $query) => $query, ), - Tables\Filters\SelectFilter::make('status') + SelectFilter::make('status') ->multiple() ->options(ResultStatus::class), - Tables\Filters\TernaryFilter::make('healthy') + TernaryFilter::make('healthy') ->nullable() ->trueLabel('Only healthy speedtests') ->falseLabel('Only unhealthy speedtests') @@ -401,17 +414,17 @@ public static function table(Table $table): Table ), ]) ->actions([ - Tables\Actions\ActionGroup::make([ + ActionGroup::make([ Action::make('view result') ->label('View on Speedtest.net') ->icon('heroicon-o-link') ->url(fn (Result $record): ?string => $record->result_url) ->hidden(fn (Result $record): bool => $record->status !== ResultStatus::Completed) ->openUrlInNewTab(), - Tables\Actions\ViewAction::make(), - Tables\Actions\Action::make('updateComments') + ViewAction::make(), + Action::make('updateComments') ->icon('heroicon-o-chat-bubble-bottom-center-text') - ->hidden(fn (): bool => ! auth()->user()->is_admin && ! auth()->user()->is_user) + ->hidden(fn (): bool => ! (Auth::user()?->is_admin ?? false) && ! (Auth::user()?->is_user ?? false)) ->mountUsing(fn (Forms\ComponentContainer $form, Result $record) => $form->fill([ 'comments' => $record->comments, ])) @@ -420,23 +433,22 @@ public static function table(Table $table): Table $record->save(); }) ->form([ - Forms\Components\Textarea::make('comments') + Textarea::make('comments') ->rows(6) ->maxLength(500), - ]) - ->modalButton('Save'), - Tables\Actions\DeleteAction::make(), + ]), + DeleteAction::make(), ]), ]) ->bulkActions([ - Tables\Actions\DeleteBulkAction::make(), + DeleteBulkAction::make(), ]) ->headerActions([ - Tables\Actions\ExportAction::make() + ExportAction::make() ->exporter(ResultExporter::class) ->fileName(fn (): string => 'results-'.now()->timestamp), - Tables\Actions\ActionGroup::make([ - Tables\Actions\Action::make('truncate') + ActionGroup::make([ + Action::make('truncate') ->action(fn () => TruncateResults::dispatch(Auth::user())) ->requiresConfirmation() ->modalHeading('Truncate Results') diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index fa0c775f8..90bb95540 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -5,10 +5,18 @@ use App\Enums\UserRole; use App\Filament\Resources\UserResource\Pages; use App\Models\User; -use Filament\Forms; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Placeholder; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Resources\Resource; -use Filament\Tables; +use Filament\Tables\Actions\ActionGroup; +use Filament\Tables\Actions\DeleteAction; +use Filament\Tables\Actions\EditAction; +use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; @@ -27,29 +35,29 @@ public static function form(Form $form): Form { return $form ->schema([ - Forms\Components\Grid::make([ + Grid::make([ 'default' => 1, ])->columnSpan([ 'lg' => 2, ])->schema([ - Forms\Components\Section::make('Details') + Section::make('Details') ->columns([ 'default' => 1, 'lg' => 2, ]) ->schema([ - Forms\Components\TextInput::make('name') + TextInput::make('name') ->required() ->maxLength(255) ->columnSpanFull(), - Forms\Components\TextInput::make('email') + TextInput::make('email') ->email() ->required() ->maxLength(255) ->columnSpanFull(), - Forms\Components\TextInput::make('password') + TextInput::make('password') ->confirmed() ->password() ->revealable() @@ -57,7 +65,7 @@ public static function form(Form $form): Form ->dehydrateStateUsing(fn ($state) => Hash::make($state)) ->dehydrated(fn ($state) => filled($state)), - Forms\Components\TextInput::make('password_confirmation') + TextInput::make('password_confirmation') ->password() ->revealable(), @@ -65,12 +73,12 @@ public static function form(Form $form): Form ]), ]), - Forms\Components\Grid::make(1) + Grid::make(1) ->columnSpan(1) ->schema([ - Forms\Components\Section::make('Platform') + Section::make('Platform') ->schema([ - Forms\Components\Select::make('role') + Select::make('role') ->label('Role') ->default(UserRole::User) ->options(UserRole::class) @@ -80,12 +88,12 @@ public static function form(Form $form): Form // ... ]), - Forms\Components\Section::make() + Section::make() ->schema([ - Forms\Components\Placeholder::make('created_at') + Placeholder::make('created_at') ->content(fn (?User $record): string => $record ? $record->created_at->diffForHumans() : '-'), - Forms\Components\Placeholder::make('updated_at') + Placeholder::make('updated_at') ->content(fn (?User $record): string => $record ? $record->updated_at->diffForHumans() : '-'), // ... @@ -102,27 +110,27 @@ public static function table(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('id') + TextColumn::make('id') ->label('ID') ->sortable(), - Tables\Columns\TextColumn::make('name') + TextColumn::make('name') ->searchable(), - Tables\Columns\TextColumn::make('email') + TextColumn::make('email') ->searchable(), - Tables\Columns\TextColumn::make('role') + TextColumn::make('role') ->badge(), - Tables\Columns\TextColumn::make('created_at') + TextColumn::make('created_at') ->alignEnd() ->dateTime(config('app.datetime_format')) ->timezone(config('app.display_timezone')) ->sortable() ->toggleable(isToggledHiddenByDefault: false), - Tables\Columns\TextColumn::make('updated_at') + TextColumn::make('updated_at') ->alignEnd() ->dateTime(config('app.datetime_format')) ->timezone(config('app.display_timezone')) @@ -132,12 +140,13 @@ public static function table(Table $table): Table // ... ]) ->filters([ - Tables\Filters\SelectFilter::make('role') + SelectFilter::make('role') ->options(UserRole::class), ]) ->actions([ - Tables\Actions\ActionGroup::make([ - Tables\Actions\EditAction::make(), + ActionGroup::make([ + EditAction::make(), + DeleteAction::make(), ]), ]) ->bulkActions([ @@ -156,8 +165,6 @@ public static function getPages(): array { return [ 'index' => Pages\ListUsers::route('/'), - 'create' => Pages\CreateUser::route('/create'), - 'edit' => Pages\EditUser::route('/{record}/edit'), ]; } } diff --git a/app/Filament/Resources/UserResource/Pages/CreateUser.php b/app/Filament/Resources/UserResource/Pages/CreateUser.php deleted file mode 100644 index 78a389490..000000000 --- a/app/Filament/Resources/UserResource/Pages/CreateUser.php +++ /dev/null @@ -1,11 +0,0 @@ -