Skip to content

Commit 150387a

Browse files
committed
Remove drag and drop reordering and work with btns.
1 parent 7f16f7a commit 150387a

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

resources/views/livewire/menu-tree-item.blade.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<div class="menu-tree-item" data-item-id="{{ $item->id }}" wire:key="tree-item-{{ $item->id }}">
22
<div class="flex items-center p-4 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 group hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors {{ $depth > 0 ? 'ml-' . ($depth * 8) : '' }}">
33

4-
@if($showActions)
5-
<!-- Drag Handle -->
6-
<div class="drag-handle cursor-move text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 mr-4">
7-
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
8-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16"></path>
9-
</svg>
10-
</div>
11-
@endif
124

135
<!-- Expand/Collapse Button for items with children -->
146
@if($this->hasChildren())
@@ -54,6 +46,24 @@ class="h-5 w-5 text-gray-500 text-lg"/>
5446
@if($showActions)
5547
<!-- Actions -->
5648
<div class="flex items-center gap-1">
49+
<x-filament::button
50+
color="gray"
51+
size="xs"
52+
icon="heroicon-o-arrow-up"
53+
tooltip="Move up"
54+
label-sr-only="Move up"
55+
wire:click="moveUp"
56+
></x-filament::button>
57+
58+
<x-filament::button
59+
color="gray"
60+
size="xs"
61+
icon="heroicon-o-arrow-down"
62+
tooltip="Move down"
63+
label-sr-only="Move down"
64+
wire:click="moveDown"
65+
></x-filament::button>
66+
5767
@if($this->canHaveChildren())
5868
<x-filament::button
5969
color="gray"

src/Resources/MenuResource/Pages/ManageMenuItems.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,84 @@ public function handleShowDeleteModal(array $data): void
886886
$this->mountAction('deleteMenuItem', ['itemId' => $itemId]);
887887
}
888888
}
889+
890+
#[On('move-item-up')]
891+
public function handleMoveItemUp(array $data): void
892+
{
893+
$itemId = $data['itemId'] ?? null;
894+
if ($itemId) {
895+
$this->moveItemUp($itemId);
896+
}
897+
}
898+
899+
#[On('move-item-down')]
900+
public function handleMoveItemDown(array $data): void
901+
{
902+
$itemId = $data['itemId'] ?? null;
903+
if ($itemId) {
904+
$this->moveItemDown($itemId);
905+
}
906+
}
907+
908+
public function moveItemUp(int $itemId): void
909+
{
910+
try {
911+
$item = $this->getMenuItemSecurely($itemId);
912+
if (!$item) {
913+
Notification::make()
914+
->title(flexiblePagesTrans('menu_items.errors.item_not_found'))
915+
->danger()
916+
->send();
917+
return;
918+
}
919+
920+
// Move up means move to previous sibling
921+
$previousSibling = $item->getPrevSibling();
922+
if ($previousSibling) {
923+
$item->beforeNode($previousSibling)->save();
924+
$this->refreshTree();
925+
926+
Notification::make()
927+
->title('Menu item moved up successfully.')
928+
->success()
929+
->send();
930+
}
931+
} catch (Exception $e) {
932+
Notification::make()
933+
->title('Failed to move menu item: ' . $e->getMessage())
934+
->danger()
935+
->send();
936+
}
937+
}
938+
939+
public function moveItemDown(int $itemId): void
940+
{
941+
try {
942+
$item = $this->getMenuItemSecurely($itemId);
943+
if (!$item) {
944+
Notification::make()
945+
->title(flexiblePagesTrans('menu_items.errors.item_not_found'))
946+
->danger()
947+
->send();
948+
return;
949+
}
950+
951+
// Move down means move to next sibling
952+
$nextSibling = $item->getNextSibling();
953+
if ($nextSibling) {
954+
$item->afterNode($nextSibling)->save();
955+
$this->refreshTree();
956+
957+
Notification::make()
958+
->title('Menu item moved down successfully.')
959+
->success()
960+
->send();
961+
}
962+
} catch (Exception $e) {
963+
Notification::make()
964+
->title('Failed to move menu item: ' . $e->getMessage())
965+
->danger()
966+
->send();
967+
}
968+
}
889969
}

0 commit comments

Comments
 (0)