mirror of
https://github.com/pelican-dev/panel.git
synced 2025-10-29 23:26:52 +01:00
Redirect to previous page when clicking "cancel" on EditFiles page (#1747)
This commit is contained in:
parent
5373f1e30a
commit
81178f81b4
@ -27,11 +27,13 @@ use Filament\Schemas\Components\Section;
|
|||||||
use Filament\Schemas\Components\Utilities\Get;
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
use Filament\Support\Enums\Alignment;
|
use Filament\Support\Enums\Alignment;
|
||||||
|
use Filament\Support\Facades\FilamentView;
|
||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\Client\ConnectionException;
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Facades\Route as RouteFacade;
|
use Illuminate\Support\Facades\Route as RouteFacade;
|
||||||
|
use Illuminate\Support\Js;
|
||||||
use Livewire\Attributes\Locked;
|
use Livewire\Attributes\Locked;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@ -54,6 +56,8 @@ class EditFiles extends Page
|
|||||||
#[Locked]
|
#[Locked]
|
||||||
public string $path;
|
public string $path;
|
||||||
|
|
||||||
|
public ?string $previousUrl = null;
|
||||||
|
|
||||||
private DaemonFileRepository $fileRepository;
|
private DaemonFileRepository $fileRepository;
|
||||||
|
|
||||||
/** @var array<string, mixed>|null */
|
/** @var array<string, mixed>|null */
|
||||||
@ -93,7 +97,8 @@ class EditFiles extends Page
|
|||||||
->body(fn () => $this->path)
|
->body(fn () => $this->path)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$this->redirect(ListFiles::getUrl(['path' => dirname($this->path)]));
|
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
}),
|
}),
|
||||||
Action::make('save')
|
Action::make('save')
|
||||||
->label(trans('server/file.actions.edit.save'))
|
->label(trans('server/file.actions.edit.save'))
|
||||||
@ -117,7 +122,13 @@ class EditFiles extends Page
|
|||||||
->label(trans('server/file.actions.edit.cancel'))
|
->label(trans('server/file.actions.edit.cancel'))
|
||||||
->color('danger')
|
->color('danger')
|
||||||
->icon('tabler-x')
|
->icon('tabler-x')
|
||||||
->url(fn () => ListFiles::getUrl(['path' => dirname($this->path)])),
|
->alpineClickHandler(function () {
|
||||||
|
$url = $this->previousUrl ?? ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
|
||||||
|
return FilamentView::hasSpaMode($url)
|
||||||
|
? 'document.referrer ? window.history.back() : Livewire.navigate(' . Js::from($url) . ')'
|
||||||
|
: 'document.referrer ? window.history.back() : (window.location.href = ' . Js::from($url) . ')';
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
->footerActionsAlignment(Alignment::End)
|
->footerActionsAlignment(Alignment::End)
|
||||||
->schema([
|
->schema([
|
||||||
@ -168,7 +179,8 @@ class EditFiles extends Page
|
|||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$this->redirect(ListFiles::getUrl(['path' => dirname($this->path)]));
|
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
} catch (FileNotFoundException) {
|
} catch (FileNotFoundException) {
|
||||||
AlertBanner::make('file_not_found')
|
AlertBanner::make('file_not_found')
|
||||||
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
||||||
@ -176,7 +188,8 @@ class EditFiles extends Page
|
|||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$this->redirect(ListFiles::getUrl(['path' => dirname($this->path)]));
|
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
} catch (FileNotEditableException) {
|
} catch (FileNotEditableException) {
|
||||||
AlertBanner::make('file_is_directory')
|
AlertBanner::make('file_is_directory')
|
||||||
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
->title(trans('server/file.alerts.file_not_found.title', ['name' => basename($this->path)]))
|
||||||
@ -184,11 +197,13 @@ class EditFiles extends Page
|
|||||||
->closable()
|
->closable()
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
$this->redirect(ListFiles::getUrl(['path' => dirname($this->path)]));
|
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
} catch (ConnectionException) {
|
} catch (ConnectionException) {
|
||||||
// Alert banner for this one will be handled by ListFiles
|
// Alert banner for this one will be handled by ListFiles
|
||||||
|
|
||||||
$this->redirect(ListFiles::getUrl(['path' => dirname($this->path)]));
|
$url = ListFiles::getUrl(['path' => dirname($this->path)]);
|
||||||
|
$this->redirect($url, FilamentView::hasSpaMode($url));
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
@ -204,6 +219,8 @@ class EditFiles extends Page
|
|||||||
|
|
||||||
$this->form->fill();
|
$this->form->fill();
|
||||||
|
|
||||||
|
$this->previousUrl = url()->previous();
|
||||||
|
|
||||||
if (str($path)->endsWith('.pelicanignore')) {
|
if (str($path)->endsWith('.pelicanignore')) {
|
||||||
AlertBanner::make('.pelicanignore_info')
|
AlertBanner::make('.pelicanignore_info')
|
||||||
->title(trans('server/file.alerts.pelicanignore.title'))
|
->title(trans('server/file.alerts.pelicanignore.title'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user