The declared actions of a resource (action :id, "Label" in its ui):
who may run one, what it asks for, and running it. The host's buttons,
its dialog (Alternera.Resource.UI.ActionRunner) and the contract
kit's harness all run actions through here, so an action behaves the same
wherever it is drawn.
An action with run: runs that Ash action of the resource with the
context's tenant and actor: the policies decide, the history records the
change. Its input is the Ash action's public arguments and the attributes
it accepts. An action with handler: calls
Alternera.Resource.UI.ActionHandler.handle_action/4 with the
arguments it declares. A selection runs the action once per record, so
each record gets its own policy check and version.
Summary
Functions
Whether the viewer may run action: a read-only action always, any other
only with can_write?. The resource's policies still decide when it runs.
The dialog's params (string keys) cast to the inputs' types:
{:ok, input} with atom keys, or {:error, %{name => message}}. A blank
value is nil; a required input that is nil is refused; a missing one
takes its default.
The inputs the dialog asks for, in order.
Whether to offer action for record (nil for the resource or a
selection): allowed, and its visible function, if any, says yes. A
visible function that raises is logged and hides the action.
The actions of actions that act on on (:resource, :record or :selection).
What the dialog shows first for target: on one record, each input
that is one of its attributes holds the record's value (string keys, as
the dialog's params), so an update starts from what is there. Elsewhere
nothing; the inputs show their defaults.
Runs action on target (:resource, {:record, record} or
{:selection, records}) with the cast input. Every error is logged.
Types
@type input() :: %{ name: atom(), type: module(), constraints: keyword(), label: String.t(), description: String.t() | nil, default: term(), required?: boolean() }
An input the dialog asks for.
@type result() :: %{ status: :ok | :error, message: String.t(), failed: [%{key: String.t(), message: String.t()}], open: tuple() | nil, download: {String.t(), iodata()} | nil }
What running an action came to.
Functions
@spec allowed?( Alternera.Resource.Extension.Action.t(), Alternera.Resource.UI.Context.t() ) :: boolean()
Whether the viewer may run action: a read-only action always, any other
only with can_write?. The resource's policies still decide when it runs.
@spec cast([input()], map(), keyword()) :: {:ok, map()} | {:error, %{required(atom()) => String.t()}}
The dialog's params (string keys) cast to the inputs' types:
{:ok, input} with atom keys, or {:error, %{name => message}}. A blank
value is nil; a required input that is nil is refused; a missing one
takes its default.
With clear: true (one record, its values prefilled) an optional input
without a default that the reader emptied is passed as nil, so the
action clears it; otherwise a blank input is left out (unchanged).
@spec inputs(module(), Alternera.Resource.Extension.Action.t()) :: [input()]
The inputs the dialog asks for, in order.
@spec offered?( Alternera.Resource.Extension.Action.t(), struct() | nil, Alternera.Resource.UI.Context.t() ) :: boolean()
Whether to offer action for record (nil for the resource or a
selection): allowed, and its visible function, if any, says yes. A
visible function that raises is logged and hides the action.
@spec on( [Alternera.Resource.Extension.Action.t()], Alternera.Resource.Extension.Action.on() ) :: [ Alternera.Resource.Extension.Action.t() ]
The actions of actions that act on on (:resource, :record or :selection).
What the dialog shows first for target: on one record, each input
that is one of its attributes holds the record's value (string keys, as
the dialog's params), so an update starts from what is there. Elsewhere
nothing; the inputs show their defaults.
@spec run( module(), Alternera.Resource.Extension.Action.t(), :resource | {:record, struct()} | {:selection, [struct()]}, map(), Alternera.Resource.UI.Context.t() ) :: result()
Runs action on target (:resource, {:record, record} or
{:selection, records}) with the cast input. Every error is logged.