mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 17:34: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 {
|
try {
|
||||||
$server->validateCurrentState();
|
$server->validateCurrentState();
|
||||||
} catch (ServerStateConflictException $exception) {
|
} catch (ServerStateConflictException $exception) {
|
||||||
AlertBanner::make()
|
AlertBanner::make('server_conflict')
|
||||||
->warning()
|
|
||||||
->title('Warning')
|
->title('Warning')
|
||||||
->body($exception->getMessage())
|
->body($exception->getMessage())
|
||||||
|
->warning()
|
||||||
->send();
|
->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ class EditFiles extends Page
|
|||||||
$this->form->fill();
|
$this->form->fill();
|
||||||
|
|
||||||
if (str($path)->endsWith('.pelicanignore')) {
|
if (str($path)->endsWith('.pelicanignore')) {
|
||||||
AlertBanner::make()
|
AlertBanner::make('.pelicanignore_info')
|
||||||
->title('You\'re editing a <code>.pelicanignore</code> file!')
|
->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>).')
|
->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()
|
->info()
|
||||||
|
@ -57,13 +57,18 @@ class ListFiles extends ListRecords
|
|||||||
public function mount(?string $path = null): void
|
public function mount(?string $path = null): void
|
||||||
{
|
{
|
||||||
parent::mount();
|
parent::mount();
|
||||||
|
|
||||||
$this->path = $path ?? '/';
|
$this->path = $path ?? '/';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->getDaemonFileRepository()->getDirectory('/');
|
$this->getDaemonFileRepository()->getDirectory('/');
|
||||||
} catch (ConnectionException) {
|
} catch (ConnectionException) {
|
||||||
$this->isDisabled = true;
|
$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;
|
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
|
public static function route(string $path): PageRegistration
|
||||||
{
|
{
|
||||||
return new PageRegistration(
|
return new PageRegistration(
|
||||||
|
@ -130,7 +130,7 @@ class ServerConsole extends Widget
|
|||||||
#[On('websocket-error')]
|
#[On('websocket-error')]
|
||||||
public function websocketError(): void
|
public function websocketError(): void
|
||||||
{
|
{
|
||||||
AlertBanner::make()
|
AlertBanner::make('websocket_error')
|
||||||
->title('Could not connect to websocket!')
|
->title('Could not connect to websocket!')
|
||||||
->body('Check your browser console for more details.')
|
->body('Check your browser console for more details.')
|
||||||
->danger()
|
->danger()
|
||||||
|
@ -44,9 +44,8 @@ final class AlertBanner implements Wireable
|
|||||||
|
|
||||||
public static function fromLivewire(mixed $value): AlertBanner
|
public static function fromLivewire(mixed $value): AlertBanner
|
||||||
{
|
{
|
||||||
$static = AlertBanner::make();
|
$static = AlertBanner::make($value['id']);
|
||||||
|
|
||||||
$static->id($value['id']);
|
|
||||||
$static->title($value['title']);
|
$static->title($value['title']);
|
||||||
$static->body($value['body']);
|
$static->body($value['body']);
|
||||||
$static->status($value['status']);
|
$static->status($value['status']);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class AlertBannerContainer extends Component
|
class AlertBannerContainer extends Component
|
||||||
@ -16,6 +17,7 @@ class AlertBannerContainer extends Component
|
|||||||
$this->pullFromSession();
|
$this->pullFromSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[On('alertBannerSent')]
|
||||||
public function pullFromSession(): void
|
public function pullFromSession(): void
|
||||||
{
|
{
|
||||||
foreach (session()->pull('alert-banners', []) as $alertBanner) {
|
foreach (session()->pull('alert-banners', []) as $alertBanner) {
|
||||||
|
@ -37,8 +37,13 @@ use Illuminate\Support\Facades\URL;
|
|||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Laravel\Sanctum\Sanctum;
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Livewire\Livewire;
|
||||||
use Spatie\Health\Facades\Health;
|
use Spatie\Health\Facades\Health;
|
||||||
|
|
||||||
|
use function Livewire\on;
|
||||||
|
use function Livewire\store;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -139,6 +144,22 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
fn () => Blade::render('filament.layouts.footer'),
|
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
|
// Don't run any health checks during tests
|
||||||
if (!$app->runningUnitTests()) {
|
if (!$app->runningUnitTests()) {
|
||||||
Health::checks([
|
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)
|
@foreach (array_values($alertBanners) as $alertBanner)
|
||||||
@include('livewire.alerts.alert-banner', ['alertBanner' => $alertBanner])
|
@include('livewire.alerts.alert-banner', ['alertBanner' => $alertBanner])
|
||||||
@endforeach
|
@endforeach
|
||||||
|
Loading…
x
Reference in New Issue
Block a user