Skip to content

Commit

Permalink
Merge pull request #695 from naymspace/feature/make-default-actions-p…
Browse files Browse the repository at this point in the history
…ublic

Add `Backpex.ItemAction.default_actions/0`
  • Loading branch information
Flo0807 authored Dec 11, 2024
2 parents ebcd779 + 8ef8da3 commit 8c14563
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
20 changes: 20 additions & 0 deletions lib/backpex/item_actions/item_action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,24 @@ defmodule Backpex.ItemAction do

module.fields() != []
end

@doc """
Returns default item actions.
"""
def default_actions do
[
show: %{
module: Backpex.ItemActions.Show,
only: [:row]
},
edit: %{
module: Backpex.ItemActions.Edit,
only: [:row, :show]
},
delete: %{
module: Backpex.ItemActions.Delete,
only: [:row, :index, :show]
}
]
end
end
19 changes: 1 addition & 18 deletions lib/backpex/live_resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ defmodule Backpex.LiveResource do
end

defp apply_item_actions(socket, action) when action in [:index, :resource_action] do
item_actions = socket.assigns.live_resource.item_actions(default_item_actions())
item_actions = Backpex.ItemAction.default_actions() |> socket.assigns.live_resource.item_actions()
assign(socket, :item_actions, item_actions)
end

Expand Down Expand Up @@ -1575,23 +1575,6 @@ defmodule Backpex.LiveResource do
if value in permitted, do: value, else: default
end

defp default_item_actions do
[
show: %{
module: Backpex.ItemActions.Show,
only: [:row]
},
edit: %{
module: Backpex.ItemActions.Edit,
only: [:row, :show]
},
delete: %{
module: Backpex.ItemActions.Delete,
only: [:row, :index, :show]
}
]
end

defp maybe_put_empty_filter(%{} = filters, empty_filter_key) when filters == %{} do
Map.put(filters, Atom.to_string(empty_filter_key), true)
end
Expand Down

0 comments on commit 8c14563

Please sign in to comment.