Skip to content

Commit dff2d7c

Browse files
scott graysonscott grayson
authored andcommitted
feat: add 'View Folder' action to edit and view pages
- Add 'View Folder' action to EditLibraryItem page header actions - Add 'View Folder' action to ViewLibraryItem page header actions - Action only appears when item has a parent folder - Uses arrow-up icon and gray color for consistency - Allows users to navigate back to parent folder from individual item pages
1 parent 9f2125a commit dff2d7c

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/Resources/Pages/EditLibraryItem.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ public function getTitle(): string
2222

2323
protected function getHeaderActions(): array
2424
{
25-
return [
26-
Action::make('move')
25+
$actions = [];
26+
27+
// Add "View Folder" action if we have a parent
28+
if ($this->getRecord()->parent_id) {
29+
$actions[] = Action::make('view_folder')
30+
->label('View Folder')
31+
->icon('heroicon-o-arrow-up')
32+
->color('gray')
33+
->url(fn (): string =>
34+
static::getResource()::getUrl('index', ['parent' => $this->getRecord()->parent_id])
35+
);
36+
}
37+
38+
$actions[] = Action::make('move')
2739
->label('Move')
2840
->icon('heroicon-o-arrow-right-circle')
2941
->color('warning')
@@ -54,9 +66,11 @@ protected function getHeaderActions(): array
5466
]);
5567

5668
$this->redirect(static::getResource()::getUrl('index', $data['parent_id'] ? ['parent' => $data['parent_id']] : []));
57-
}),
58-
DeleteAction::make(),
59-
];
69+
});
70+
71+
$actions[] = DeleteAction::make();
72+
73+
return $actions;
6074
}
6175

6276
protected function mutateFormDataBeforeFill(array $data): array

src/Resources/Pages/ViewLibraryItem.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Filament\Resources\Pages\ViewRecord;
66
use Tapp\FilamentLibrary\Resources\LibraryItemResource;
7+
use Filament\Actions\Action;
78

89
class ViewLibraryItem extends ViewRecord
910
{
@@ -18,9 +19,22 @@ public function getTitle(): string
1819

1920
protected function getHeaderActions(): array
2021
{
21-
return [
22-
\Filament\Actions\EditAction::make(),
23-
\Filament\Actions\DeleteAction::make(),
24-
];
22+
$actions = [];
23+
24+
// Add "View Folder" action if we have a parent
25+
if ($this->getRecord()->parent_id) {
26+
$actions[] = Action::make('view_folder')
27+
->label('View Folder')
28+
->icon('heroicon-o-arrow-up')
29+
->color('gray')
30+
->url(fn (): string =>
31+
static::getResource()::getUrl('index', ['parent' => $this->getRecord()->parent_id])
32+
);
33+
}
34+
35+
$actions[] = \Filament\Actions\EditAction::make();
36+
$actions[] = \Filament\Actions\DeleteAction::make();
37+
38+
return $actions;
2539
}
2640
}

0 commit comments

Comments
 (0)