Skip to content

Commit a05dd92

Browse files
author
thapacodes4u
committed
feat: separate pages and sections management with improved navigation
-[x] Remove Pages link from navigation menu -[x] Reorder dynamic section links before Sections link with document icon -[x] Remove page management from section view (deleted PagesRelationManager) -[x] Use section name for page title and breadcrumb on dynamic pages -[x] Hide Section column when viewing pages filtered by section -[x] Fix table filtering bug by moving section filter to getTableQuery
1 parent cc92be7 commit a05dd92

5 files changed

Lines changed: 44 additions & 93 deletions

File tree

src/Admin/Filament/Resources/PageResource.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PageResource extends Resource
4343

4444
protected static ?string $navigationGroup = 'CMS';
4545

46-
protected static bool $shouldRegisterNavigation = true;
46+
protected static bool $shouldRegisterNavigation = false;
4747

4848
protected static ?string $navigationLabel = 'Pages';
4949

@@ -165,10 +165,6 @@ public static function form(Form $form): Form
165165
public static function table(Table $table): Table
166166
{
167167
return $table
168-
->modifyQueryUsing(fn (Builder $query) => $query->when(
169-
request()->get('sId'),
170-
fn (Builder $q, $sId) => $q->where('section_id', $sId)
171-
))
172168
->columns([
173169
TextColumn::make('title')
174170
->label('Page Title')
@@ -186,7 +182,8 @@ public static function table(Table $table): Table
186182
->label('Section')
187183
->sortable()
188184
->badge()
189-
->color('gray'),
185+
->color('gray')
186+
->hidden(fn () => request()->has('sId')),
190187

191188
TextColumn::make('sef_key')
192189
->label('URL Slug')

src/Admin/Filament/Resources/PageResource/Pages/ListPages.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,53 @@
33
namespace Eclipse\Cms\Admin\Filament\Resources\PageResource\Pages;
44

55
use Eclipse\Cms\Admin\Filament\Resources\PageResource;
6+
use Eclipse\Cms\Models\Section;
67
use Eclipse\Common\Foundation\Pages\HasScoutSearch;
78
use Filament\Actions\CreateAction;
89
use Filament\Resources\Pages\ListRecords;
10+
use Illuminate\Database\Eloquent\Builder;
911

1012
class ListPages extends ListRecords
1113
{
1214
use HasScoutSearch;
1315

1416
protected static string $resource = PageResource::class;
1517

18+
public function getTitle(): string
19+
{
20+
if ($sectionId = request()->get('sId')) {
21+
$section = Section::find($sectionId);
22+
if ($section) {
23+
return $section->name;
24+
}
25+
}
26+
27+
return parent::getTitle();
28+
}
29+
30+
public function getBreadcrumb(): ?string
31+
{
32+
if ($sectionId = request()->get('sId')) {
33+
$section = Section::find($sectionId);
34+
if ($section) {
35+
return $section->name;
36+
}
37+
}
38+
39+
return parent::getBreadcrumb();
40+
}
41+
42+
protected function getTableQuery(): Builder
43+
{
44+
$query = parent::getTableQuery();
45+
46+
if ($sectionId = request()->get('sId')) {
47+
$query->where('section_id', $sectionId);
48+
}
49+
50+
return $query;
51+
}
52+
1653
protected function getHeaderActions(): array
1754
{
1855
$createAction = CreateAction::make();

src/Admin/Filament/Resources/SectionResource.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Eclipse\Cms\Admin\Filament\Resources;
44

55
use Eclipse\Cms\Admin\Filament\Resources\SectionResource\Pages;
6-
use Eclipse\Cms\Admin\Filament\Resources\SectionResource\RelationManagers;
76
use Eclipse\Cms\Enums\SectionType;
87
use Eclipse\Cms\Models\Section;
98
use Filament\Forms\Components\Placeholder;
@@ -44,6 +43,8 @@ class SectionResource extends Resource
4443

4544
protected static ?string $navigationLabel = 'Sections';
4645

46+
protected static ?int $navigationSort = 20;
47+
4748
public static function form(Form $form): Form
4849
{
4950
return $form
@@ -143,9 +144,7 @@ public static function table(Table $table): Table
143144

144145
public static function getRelations(): array
145146
{
146-
return [
147-
RelationManagers\PagesRelationManager::class,
148-
];
147+
return [];
149148
}
150149

151150
public static function getPages(): array

src/Admin/Filament/Resources/SectionResource/RelationManagers/PagesRelationManager.php

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/CmsPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getSectionNavigationItems(): array
3131
'sId' => $section->id,
3232
])
3333
)
34-
->icon('heroicon-o-arrow-turn-down-right')
34+
->icon('heroicon-o-document-text')
3535
->group('CMS')
3636
->sort(10)
3737
->visible(fn (): bool => $section->{config('eclipse-cms.tenancy.foreign_key')} === Filament::getTenant()?->id)

0 commit comments

Comments
 (0)