edisonywh / backoffice

Admin tool built with the PETAL stack
MIT License
217 stars 15 forks source link

Add `actions` macro DSL #22

Closed edisonywh closed 3 years ago

edisonywh commented 3 years ago

Use the actions macro like so:

actions do
  action :retry, type: :single, enabled: true, handler: &__MODULE__.retry/2
end

def retry(socket, id) do
    ...
    socket
end

There are two types of action available, Single actions that appear within each row, and Page actions that appear at the top right corner of the page.

Both actions need a handler that takes in 2-arity, and must return a socket (you can do whatever you want in this socket, like push_patch etc). The first argument to the handler function is socket, the second argument is the id, or nil in case of page actions (down the road we might pass down a list of ids for page actions).

This commit also (in a very hackish way) hide the create/edit button if you haven't defined the corresponding routes for them.