Skip to content

Commit 4c14a53

Browse files
committed
Add documentation for tree toolbar actions
Updated .github/copilot-instructions.md and README.md to document the new getTreeToolbarActions() method for adding global toolbar actions above the tree. Includes usage examples and notes version support (3.1.0+).
1 parent 540d54b commit 4c14a53

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.github/copilot-instructions.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ public function getTreeRecordIcon(?Model $record = null): ?string
119119
}
120120
```
121121

122+
**Toolbar Actions**: Add global actions displayed above the tree:
123+
124+
```php
125+
protected function getTreeToolbarActions(): array
126+
{
127+
return [
128+
CreateAction::make(),
129+
ExportAction::make(),
130+
ImportAction::make(),
131+
];
132+
}
133+
```
134+
135+
> **Note**: Toolbar actions are only supported in version 3.1.0 and later.
136+
122137
## Key File Locations
123138

124139
- Models: Add `ModelTree` trait to any hierarchical model

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,32 @@ class ProductCategoryWidget extends BaseWidget
544544
}
545545
```
546546

547+
#### Toolbar Actions
548+
549+
You can add global actions that appear in the toolbar above the tree by implementing the `getTreeToolbarActions()` method. These actions are displayed alongside the default expand/collapse and save buttons:
550+
551+
```php
552+
protected function getTreeToolbarActions(): array
553+
{
554+
return [
555+
\SolutionForest\FilamentTree\Actions\CreateAction::make()
556+
->label('Add Category')
557+
->icon('heroicon-o-plus')
558+
->color('primary'),
559+
\Filament\Actions\ExportAction::make()
560+
->label('Export Tree')
561+
->icon('heroicon-o-document-arrow-down'),
562+
\Filament\Actions\ImportAction::make()
563+
->label('Import Tree')
564+
->icon('heroicon-o-document-arrow-up'),
565+
];
566+
}
567+
```
568+
569+
The toolbar actions are automatically generated by the Artisan command and include a `CreateAction` by default for tree widgets, but return an empty array for tree pages. You can customize this method to add any actions you need.
570+
571+
> **Note**: Toolbar actions are only supported in version 3.1.0 and later.
572+
547573
### Pages
548574

549575
This plugin enables you to create tree pages in the admin panel. To create a tree page for a model, use the `make:filament-tree-page` command. For example, to create a tree page for the ProductCategory model, you can run:

0 commit comments

Comments
 (0)