Alternera. Resource. UI. ActionHandler behaviour
(alternera_resource_ui v0.9.0)
Copy Markdown
View Source
An action declared with handler: (action :id, "Label" do handler M … end), for work that is not one Ash action of the resource: call a
service, then write many records. An action that is one Ash action
declares run: instead and needs no code.
handle_action/4 gets the action's id, what it acts on, the input the
dialog asked for (cast to the declared arguments' types) and the context.
Read and write with the context (Alternera.Resource.UI.Records or
Ash with Alternera.Resource.UI.opts/1), so the policies decide, and
log every error before returning it.
It answers:
{:ok, message}or{:error, message}: the message in the action's dialog, as a success or an error, and the list reloads;{:ok, message, open: target}:targetopens (Alternera.Resource.UI.open/2's targets) and the dialog closes;{:ok, message, download: {filename, iodata}}: the message in the dialog, and the browser saves the file.
The host sends no notification of an outcome; a handler that wants one
(work that goes on after the dialog, a note to the reader) calls
Alternera.Resource.UI.notify/3.
The host runs it in a task of its own (start_async), so a slow call
does not hold the page. What it asks of the host while it runs
(Alternera.Resource.UI.notify/3, open/2, records_changed/1)
waits in that task and reaches the host, in order, when it is done.
Summary
Types
Callbacks
@callback handle_action( id :: atom(), target(), input :: map(), Alternera.Resource.UI.Context.t() ) :: result()