Skip to content

Commit b22ddc0

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

File tree

2 files changed

+13
-50
lines changed

2 files changed

+13
-50
lines changed

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

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -85,56 +85,7 @@ function menuItemsManager(config) {
8585
},
8686
8787
initSortable() {
88-
if (typeof Sortable !== 'undefined') {
89-
const container = document.getElementById('menu-items-container');
90-
if (container) {
91-
Sortable.create(container, {
92-
group: 'menu-items',
93-
animation: 150,
94-
handle: '.drag-handle',
95-
onStart: (evt) => {
96-
// Store the original order and DOM state before drag
97-
this.originalOrder = Array.from(container.children).map(el => this.extractItemId(el));
98-
this.originalElements = Array.from(container.children);
99-
},
100-
onEnd: (evt) => {
101-
if (evt.oldIndex !== evt.newIndex) {
102-
// Calculate the new order based on the drag operation
103-
const newOrder = [...this.originalOrder];
104-
const movedItem = newOrder.splice(evt.oldIndex, 1)[0];
105-
newOrder.splice(evt.newIndex, 0, movedItem);
106-
107-
// Immediately revert DOM to original state to preserve Livewire
108-
container.innerHTML = '';
109-
this.originalElements.forEach(el => container.appendChild(el));
110-
111-
this.saveReorderFromOrder(newOrder);
112-
}
113-
}
114-
});
115-
}
116-
}
117-
},
118-
119-
saveReorderFromOrder(newOrder) {
120-
this.loading = true;
121-
122-
// Build items array from the calculated new order
123-
const items = newOrder.map((itemId, index) => {
124-
return {
125-
id: itemId,
126-
position: index,
127-
parent_id: null // Root level items for now
128-
};
129-
});
130-
131-
// Call the Livewire method to save the new order
132-
this.$wire.reorderMenuItems(items);
133-
},
134-
135-
extractItemId(element) {
136-
const itemId = element.dataset.itemId;
137-
return itemId ? parseInt(itemId) : null;
88+
// Drag and drop disabled - using up/down buttons instead
13889
},
13990
}
14091
}

src/Livewire/MenuTreeItem.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ public function delete(): void
8888
$this->dispatch('show-delete-modal', ['itemId' => $this->item->id]);
8989
}
9090

91+
public function moveUp(): void
92+
{
93+
// Dispatch event to parent component to move item up
94+
$this->dispatch('move-item-up', ['itemId' => $this->item->id]);
95+
}
96+
97+
public function moveDown(): void
98+
{
99+
// Dispatch event to parent component to move item down
100+
$this->dispatch('move-item-down', ['itemId' => $this->item->id]);
101+
}
102+
91103
public function render()
92104
{
93105
return view('filament-flexible-content-block-pages::livewire.menu-tree-item');

0 commit comments

Comments
 (0)