Skip to content

Commit 56d7ba5

Browse files
committed
Fix showing updated tree
1 parent bbc2025 commit 56d7ba5

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

resources/views/filament/resources/menu-resource/pages/manage-menu-items.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class="space-y-6"
2525
</div>
2626
@else
2727
<!-- Tree Items -->
28-
<div class="space-y-2" id="menu-items-container">
28+
<div class="space-y-2" id="menu-items-container" wire:key="tree-{{ $refreshKey }}">
2929
@foreach($this->record->menuItems()->with(['children', 'linkable'])->whereNull('parent_id')->orderBy('_lft')->get() as $item)
3030
@livewire('filament-flexible-content-block-pages::menu-tree-item', [
3131
'item' => $item,
3232
'maxDepth' => $this->getMaxDepth()
33-
], key($item->id))
33+
], key: "item-{$item->id}-{$refreshKey}")
3434
@endforeach
3535
</div>
3636
@endif

src/Resources/MenuResource/Pages/ManageMenuItems.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ class ManageMenuItems extends Page implements HasActions, HasForms
3131

3232
public mixed $record;
3333

34+
public $refreshKey = 0;
35+
3436
public function mount(int|string $record): void
3537
{
3638
$menuModel = static::getResource()::getModel();
3739
$this->record = $menuModel::findOrFail($record);
3840
}
3941

42+
protected function refreshTree(): void
43+
{
44+
$this->refreshKey++;
45+
$this->dispatch('menu-items-updated');
46+
}
47+
4048
public function getTitle(): string
4149
{
4250
return flexiblePagesTrans('menu_items.manage.title', [
@@ -220,7 +228,7 @@ public function deleteMenuItem(int $itemId): void
220228
// Delete the item
221229
$item->delete();
222230

223-
$this->dispatch('menu-items-updated');
231+
$this->refreshTree();
224232

225233
Notification::make()
226234
->title(flexiblePagesTrans('menu_items.messages.item_deleted'))
@@ -246,7 +254,7 @@ public function confirmDeleteWithChildren(int $itemId): void
246254
// Delete the item and all its descendants
247255
$item->delete();
248256

249-
$this->dispatch('menu-items-updated');
257+
$this->refreshTree();
250258

251259
Notification::make()
252260
->title(flexiblePagesTrans('menu_items.messages.item_and_children_deleted'))
@@ -302,7 +310,7 @@ public function reorderMenuItems(array $orderedItems): void
302310
// Process the reordering with proper nested set operations
303311
$this->processNestedSetReorder($orderedItems);
304312

305-
$this->dispatch('menu-items-updated');
313+
$this->refreshTree();
306314

307315
Notification::make()
308316
->title(flexiblePagesTrans('menu_items.messages.items_reordered'))
@@ -506,7 +514,7 @@ public function moveMenuItem(int $itemId, ?int $newParentId = null, ?int $afterI
506514
}
507515
}
508516

509-
$this->dispatch('menu-items-updated');
517+
$this->refreshTree();
510518

511519
Notification::make()
512520
->title(flexiblePagesTrans('menu_items.messages.item_moved'))
@@ -702,7 +710,7 @@ public function createMenuItem(array $data): void
702710
->send();
703711

704712
// Refresh the menu items tree view
705-
$this->dispatch('menu-items-updated');
713+
$this->refreshTree();
706714

707715
} catch (Exception $e) {
708716
Notification::make()
@@ -756,7 +764,7 @@ public function updateMenuItem(int $itemId, array $data): void
756764
->send();
757765

758766
// Refresh the menu items tree view
759-
$this->dispatch('menu-items-updated');
767+
$this->refreshTree();
760768

761769
} catch (Exception $e) {
762770
Notification::make()

0 commit comments

Comments
 (0)