Skip to content

Commit 0f23fc5

Browse files
committed
move treeview components to support and configure actions for tree node
1 parent 5684b64 commit 0f23fc5

File tree

5 files changed

+41
-170
lines changed

5 files changed

+41
-170
lines changed

resources/dist/inspirecms.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/components/tree/drop-indicator.blade.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

resources/views/components/tree/navigation/recursive-node.blade.php

Lines changed: 0 additions & 139 deletions
This file was deleted.

resources/views/livewire/navigation-tree.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class="search-input"
5959
<div class="min-h-[200px]">
6060
<div class="relative tree-container">
6161
<template x-for="(node, index) in treeData" :key="node.id + '-' + index">
62-
<x-inspirecms::tree.navigation.recursive-node
62+
<x-inspirecms-support::tree-node.recursive-node
6363
:level="1"
6464
nodeVariable="node"
6565
indexVariable="index"

src/Livewire/NavigationTree.php

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function resetTree()
5656
$this->refreshNodes();
5757
}
5858

59-
public function editNode($id)
59+
public function editTreeNode($id)
6060
{
6161
$url = FilamentResourceHelper::attemptToGetUrl($this->getResource(), 'edit', [
6262
'record' => $id,
@@ -75,7 +75,7 @@ public function editNode($id)
7575
return redirect()->to($url);
7676
}
7777

78-
public function viewNode($id)
78+
public function viewTreeNode($id)
7979
{
8080
$url = FilamentResourceHelper::attemptToGetUrl($this->getResource(), 'view', [
8181
'record' => $id,
@@ -94,24 +94,7 @@ public function viewNode($id)
9494
return redirect()->to($url);
9595
}
9696

97-
public function deleteAction()
98-
{
99-
return Action::make('delete')
100-
->model($this->getModel())
101-
->requiresConfirmation()
102-
->modalHeading('Delete Navigation Item')
103-
->modalDescription('Are you sure you want to delete this navigation item?')
104-
->modalAlignment(Alignment::Center)
105-
->action(function ($arguments) {
106-
$this->confirmDelete($arguments['id'] ?? null);
107-
})
108-
->after(function () {
109-
// Reload 'nodes' after deletion
110-
$this->refreshNodes();
111-
});
112-
}
113-
114-
private function confirmDelete($id)
97+
public function deleteTreeNode($id)
11598
{
11699
try {
117100
$record = $this->getModel()::findOrFail($id);
@@ -127,15 +110,47 @@ private function confirmDelete($id)
127110
->body('Navigation item not found.')
128111
->danger()
129112
->send();
113+
} finally {
114+
$this->dispatch('refreshAllTree');
130115
}
131116
}
132117

118+
protected function getTreeNodeActions(): array
119+
{
120+
return [
121+
Action::make('view')
122+
->icon('heroicon-m-eye')
123+
->iconButton()
124+
->color('gray')
125+
->label('View')
126+
->size('xs')
127+
->visible(fn () => $this->authorizeAction('view')),
128+
Action::make('edit')
129+
->icon('heroicon-m-pencil')
130+
->iconButton()
131+
->color('primary')
132+
->label('Edit')
133+
->size('xs')
134+
->visible(fn () => $this->authorizeAction('update')),
135+
Action::make('delete')
136+
->icon('heroicon-m-trash')
137+
->iconButton()
138+
->color('danger')
139+
->label('Delete')
140+
->size('xs')
141+
->model($this->getModel())
142+
->requiresConfirmation()
143+
->modalHeading('Delete Navigation Item')
144+
->modalDescription('Are you sure you want to delete this navigation item?')
145+
->modalAlignment(Alignment::Center),
146+
];
147+
}
148+
133149
public function getAvailableActions(): array
134150
{
135-
return collect(['view', 'update', 'delete'])
136-
->filter(function ($action) {
137-
return $this->authorizeAction($action);
138-
})->all();
151+
return collect($this->getTreeNodeActions())
152+
->where(fn (Action $action) => $action->isVisible())
153+
->all();
139154
}
140155

141156
public function save()

0 commit comments

Comments
 (0)