@@ -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