mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 14:04:45 +02:00
Improve alert banner fetching (#1173)
* use events for alert banner pulling * add ids to alert banners to prevent duplicates
This commit is contained in:
parent
8d7eff13fb
commit
7471347b55
@ -38,10 +38,10 @@ class Console extends Page
|
||||
try {
|
||||
$server->validateCurrentState();
|
||||
} catch (ServerStateConflictException $exception) {
|
||||
AlertBanner::make()
|
||||
->warning()
|
||||
AlertBanner::make('server_conflict')
|
||||
->title('Warning')
|
||||
->body($exception->getMessage())
|
||||
->warning()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ class EditFiles extends Page
|
||||
$this->form->fill();
|
||||
|
||||
if (str($path)->endsWith('.pelicanignore')) {
|
||||
AlertBanner::make()
|
||||
AlertBanner::make('.pelicanignore_info')
|
||||
->title('You\'re editing a <code>.pelicanignore</code> file!')
|
||||
->body('Any files or directories listed in here will be excluded from backups. Wildcards are supported by using an asterisk (<code>*</code>).<br>You can negate a prior rule by prepending an exclamation point (<code>!</code>).')
|
||||
->info()
|
||||
|
@ -57,13 +57,18 @@ class ListFiles extends ListRecords
|
||||
public function mount(?string $path = null): void
|
||||
{
|
||||
parent::mount();
|
||||
|
||||
$this->path = $path ?? '/';
|
||||
|
||||
try {
|
||||
$this->getDaemonFileRepository()->getDirectory('/');
|
||||
} catch (ConnectionException) {
|
||||
$this->isDisabled = true;
|
||||
$this->getFailureNotification();
|
||||
|
||||
AlertBanner::make('node_connection_error')
|
||||
->title('Could not connect to the node!')
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,14 +568,6 @@ class ListFiles extends ListRecords
|
||||
return $this->fileRepository;
|
||||
}
|
||||
|
||||
public function getFailureNotification(): AlertBanner
|
||||
{
|
||||
return AlertBanner::make()
|
||||
->title('Could not connect to the node!')
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
|
||||
public static function route(string $path): PageRegistration
|
||||
{
|
||||
return new PageRegistration(
|
||||
|
@ -130,7 +130,7 @@ class ServerConsole extends Widget
|
||||
#[On('websocket-error')]
|
||||
public function websocketError(): void
|
||||
{
|
||||
AlertBanner::make()
|
||||
AlertBanner::make('websocket_error')
|
||||
->title('Could not connect to websocket!')
|
||||
->body('Check your browser console for more details.')
|
||||
->danger()
|
||||
|
@ -44,9 +44,8 @@ final class AlertBanner implements Wireable
|
||||
|
||||
public static function fromLivewire(mixed $value): AlertBanner
|
||||
{
|
||||
$static = AlertBanner::make();
|
||||
$static = AlertBanner::make($value['id']);
|
||||
|
||||
$static->id($value['id']);
|
||||
$static->title($value['title']);
|
||||
$static->body($value['body']);
|
||||
$static->status($value['status']);
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
class AlertBannerContainer extends Component
|
||||
@ -16,6 +17,7 @@ class AlertBannerContainer extends Component
|
||||
$this->pullFromSession();
|
||||
}
|
||||
|
||||
#[On('alertBannerSent')]
|
||||
public function pullFromSession(): void
|
||||
{
|
||||
foreach (session()->pull('alert-banners', []) as $alertBanner) {
|
||||
|
@ -37,8 +37,13 @@ use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Livewire\Component;
|
||||
use Livewire\Livewire;
|
||||
use Spatie\Health\Facades\Health;
|
||||
|
||||
use function Livewire\on;
|
||||
use function Livewire\store;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
@ -139,6 +144,22 @@ class AppServiceProvider extends ServiceProvider
|
||||
fn () => Blade::render('filament.layouts.footer'),
|
||||
);
|
||||
|
||||
on('dehydrate', function (Component $component) {
|
||||
if (!Livewire::isLivewireRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (store($component)->has('redirect')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (count(session()->get('alert-banners') ?? []) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$component->dispatch('alertBannerSent');
|
||||
});
|
||||
|
||||
// Don't run any health checks during tests
|
||||
if (!$app->runningUnitTests()) {
|
||||
Health::checks([
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div wire:poll.1s="pullFromSession" id="alert-banner-container" class="flex flex-col gap-4">
|
||||
<div id="alert-banner-container" class="flex flex-col gap-4">
|
||||
@foreach (array_values($alertBanners) as $alertBanner)
|
||||
@include('livewire.alerts.alert-banner', ['alertBanner' => $alertBanner])
|
||||
@endforeach
|
||||
|
Loading…
x
Reference in New Issue
Block a user