Refactor Site Translations List Page and Enhance DataGrid Functionality: Updated the ListSiteTranslations page to improve session handling for view toggling between traditional table and DataGrid formats. Enhanced the getHeaderActions method for better readability and session management. Additionally, modified the render method to ensure the latest session value is utilized for rendering the appropriate view. Updated the DataGrid view to dynamically adjust the theme based on the current body class, improving user experience across different themes.
This commit is contained in:
@@ -24,34 +24,37 @@ class ListSiteTranslations extends ListRecords
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('toggleView')
|
||||
->label(fn() => $this->useDataGrid ? 'Tablo Görünümü' : 'DataGrid Görünümü')
|
||||
->icon(fn() => $this->useDataGrid ? 'heroicon-o-table-cells' : 'heroicon-o-squares-2x2')
|
||||
->color('gray')
|
||||
->action(function () {
|
||||
$this->useDataGrid = !$this->useDataGrid;
|
||||
session(['site_translations_use_datagrid' => $this->useDataGrid]);
|
||||
|
||||
// Sayfayı yenile ki getContent() yeniden çağrılsın
|
||||
return redirect()->to($this->getResource()::getUrl('index'));
|
||||
}),
|
||||
CreateAction::make()
|
||||
->visible(fn() => !$this->useDataGrid), // Sadece eski görünümde göster
|
||||
];
|
||||
}
|
||||
|
||||
public function getContent(): View
|
||||
{
|
||||
// Session'dan direkt oku ki her render'da güncel değeri alsın
|
||||
$useDataGrid = session('site_translations_use_datagrid', false);
|
||||
|
||||
return [
|
||||
Action::make('toggleView')
|
||||
->label($useDataGrid ? 'Tablo Görünümü' : 'DataGrid Görünümü')
|
||||
->icon($useDataGrid ? 'heroicon-o-table-cells' : 'heroicon-o-squares-2x2')
|
||||
->color('gray')
|
||||
->action(function () {
|
||||
$currentValue = session('site_translations_use_datagrid', false);
|
||||
$newValue = !$currentValue;
|
||||
session(['site_translations_use_datagrid' => $newValue]);
|
||||
session()->save(); // Session'ı hemen kaydet
|
||||
|
||||
// Sayfayı yenile
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
}),
|
||||
CreateAction::make()
|
||||
->visible(!$useDataGrid), // Sadece eski görünümde göster
|
||||
];
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$useDataGrid = session('site_translations_use_datagrid', false);
|
||||
|
||||
if ($useDataGrid) {
|
||||
return view('filament.admin.resources.site-translations.datagrid');
|
||||
return view('filament.admin.resources.site-translations.datagrid')
|
||||
->layout($this->getLayout());
|
||||
}
|
||||
|
||||
// Eski Filament table görünümü
|
||||
return parent::getContent();
|
||||
|
||||
return parent::render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user