|
2 | 2 |
|
3 | 3 | namespace Statikbe\FilamentFlexibleContentBlockPages\Livewire;
|
4 | 4 |
|
5 |
| -use Filament\Actions\Action; |
6 |
| -use Filament\Actions\Concerns\InteractsWithActions; |
7 |
| -use Filament\Actions\Contracts\HasActions; |
8 |
| -use Filament\Actions\LocaleSwitcher; |
9 |
| -use Filament\Forms\Concerns\InteractsWithForms; |
10 |
| -use Filament\Forms\Contracts\HasForms; |
11 | 5 | use Livewire\Component;
|
12 | 6 | use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
|
13 |
| -use Statikbe\FilamentFlexibleContentBlockPages\Filament\Form\Forms\MenuItemForm; |
14 | 7 |
|
15 |
| -class MenuTreeItem extends Component implements HasActions, HasForms |
| 8 | +class MenuTreeItem extends Component |
16 | 9 | {
|
17 |
| - use InteractsWithActions; |
18 |
| - use InteractsWithForms; |
19 | 10 |
|
20 | 11 | public $item; // MenuItem model
|
21 | 12 |
|
@@ -80,85 +71,24 @@ public function getItemTypeLabel(): string
|
80 | 71 | return flexiblePagesTrans('menu_items.tree.no_link');
|
81 | 72 | }
|
82 | 73 |
|
83 |
| - public function addChildAction(): Action |
| 74 | + public function addChild(): void |
84 | 75 | {
|
85 |
| - return Action::make('addChild') |
86 |
| - ->form(MenuItemForm::getSchema()) |
87 |
| - ->fillForm([ |
88 |
| - 'parent_id' => $this->item->id, |
89 |
| - 'is_visible' => true, |
90 |
| - 'target' => '_self', |
91 |
| - ]) |
92 |
| - ->action(function (array $data): void { |
93 |
| - $data['parent_id'] = $this->item->id; |
94 |
| - $this->createMenuItem($data); |
95 |
| - }) |
96 |
| - ->modalHeading(flexiblePagesTrans('menu_items.tree.add_child')) |
97 |
| - ->modalSubmitActionLabel(__('Create')) |
98 |
| - ->modalWidth('2xl') |
99 |
| - ->slideOver() |
100 |
| - ->extraModalFooterActions([ |
101 |
| - LocaleSwitcher::make(), |
102 |
| - ]); |
| 76 | + // Dispatch event to parent component with item ID for adding child |
| 77 | + $this->dispatch('show-add-child-modal', ['parent_id' => $this->item->id]); |
103 | 78 | }
|
104 | 79 |
|
105 |
| - public function editAction(): Action |
| 80 | + public function edit(): void |
106 | 81 | {
|
107 |
| - return Action::make('edit') |
108 |
| - ->form(MenuItemForm::getSchema()) |
109 |
| - ->fillForm([ |
110 |
| - 'link_type' => $this->item->link_type, |
111 |
| - 'label' => $this->item->label, |
112 |
| - 'use_model_title' => $this->item->use_model_title, |
113 |
| - 'url' => $this->item->url, |
114 |
| - 'route' => $this->item->route, |
115 |
| - 'linkable_id' => $this->item->linkable_id, |
116 |
| - 'target' => $this->item->target ?? '_self', |
117 |
| - 'icon' => $this->item->icon, |
118 |
| - 'is_visible' => $this->item->is_visible, |
119 |
| - ]) |
120 |
| - ->action(function (array $data): void { |
121 |
| - $this->updateMenuItem($this->item->id, $data); |
122 |
| - }) |
123 |
| - ->modalHeading(flexiblePagesTrans('menu_items.tree.edit')) |
124 |
| - ->modalSubmitActionLabel(__('Update')) |
125 |
| - ->modalWidth('2xl') |
126 |
| - ->slideOver() |
127 |
| - ->extraModalFooterActions([ |
128 |
| - LocaleSwitcher::make(), |
129 |
| - ]); |
| 82 | + // Dispatch event to parent component with item ID for editing |
| 83 | + $this->dispatch('show-edit-modal', ['itemId' => $this->item->id]); |
130 | 84 | }
|
131 | 85 |
|
132 |
| - public function deleteAction(): Action |
| 86 | + public function delete(): void |
133 | 87 | {
|
134 |
| - return Action::make('delete') |
135 |
| - ->requiresConfirmation() |
136 |
| - ->modalHeading(flexiblePagesTrans('menu_items.tree.delete_confirm_title')) |
137 |
| - ->modalDescription(flexiblePagesTrans('menu_items.tree.delete_confirm_text')) |
138 |
| - ->modalSubmitActionLabel(flexiblePagesTrans('menu_items.tree.delete')) |
139 |
| - ->color('danger') |
140 |
| - ->action(function (): void { |
141 |
| - $this->deleteMenuItem($this->item->id); |
142 |
| - }); |
| 88 | + // Dispatch event to parent component with item ID for deletion |
| 89 | + $this->dispatch('show-delete-modal', ['itemId' => $this->item->id]); |
143 | 90 | }
|
144 | 91 |
|
145 |
| - protected function createMenuItem(array $data): void |
146 |
| - { |
147 |
| - // Dispatch event to parent component to handle creation |
148 |
| - $this->dispatch('menu-item-created', $data); |
149 |
| - } |
150 |
| - |
151 |
| - protected function updateMenuItem(int $itemId, array $data): void |
152 |
| - { |
153 |
| - // Dispatch event to parent component to handle update |
154 |
| - $this->dispatch('menu-item-updated', $itemId, $data); |
155 |
| - } |
156 |
| - |
157 |
| - protected function deleteMenuItem(int $itemId): void |
158 |
| - { |
159 |
| - // Dispatch event to parent component to handle deletion |
160 |
| - $this->dispatch('menu-item-deleted', $itemId); |
161 |
| - } |
162 | 92 |
|
163 | 93 | public function render()
|
164 | 94 | {
|
|
0 commit comments