SelectoComponents.Actions (selecto_components v0.4.8)
Components-facing helpers for domain action contracts.
This module adapts Updato-style write contract actions into stable UI items
without depending on selecto_updato. Callers can pass a write contract
document and optional capability decisions from preview/apply responses.
Hidden actions are removed, disabled actions are retained with reason
metadata, and enabled actions carry their preview/apply links.
Link to this section Summary
Functions
Returns action items suitable for row/global/bulk action renderers.
Builds generated action-form configs for bulk action surfaces.
Groups visible action items by scope, using "unscoped" when no scope exists.
Returns the decision for an action entry from action id or capability id.
Converts a preview/apply result into normalized decision metadata.
Builds a detail-action config that opens a domain action as an action form.
Builds a map of generated detail-action configs for all visible actions.
Normalizes one domain action for use by ActionFormModal.
Builds assign data for SelectoComponents.Modal.ActionFormModal.
Merges a new preview/apply capability decision into an existing decision map.
Merges a decision extracted from an action preview/apply result.
Builds a portable action request template for preview/apply/availability calls.
Counts visible action items by normalized status.
Link to this section Types
action_item()
@type action_item() :: %{ id: String.t(), label: String.t(), description: String.t() | nil, scope: String.t() | nil, operation: String.t() | nil, capability: String.t() | nil, icon: String.t() | nil, status: String.t(), disabled?: boolean(), hidden?: boolean(), destructive?: boolean(), requires_confirmation?: boolean(), confirmation: map(), confirmation_message: String.t() | nil, inputs: [map()], input_template: map(), required_inputs: [String.t()], variants: [map()], reason: String.t() | nil, links: map(), endpoints: map(), preview_link: String.t() | nil, apply_link: String.t() | nil, attrs: map(), contract: map() }
Link to this section Functions
available(contract, opts \\ [])
@spec available( term(), keyword() ) :: [action_item()]
Returns action items suitable for row/global/bulk action renderers.
Options:
:scopefilters actions to a scope such as:rowor"bulk":decisionssupplies%{"action_id" => decision}or%{"capability" => decision}:capability_resolversupplies a host-owned resolver function invoked with a%Selecto.Capabilities.Request{}for actions that declare a capability:actor,:tenant,:domain, and:contextare copied into resolver requests:default_statusdefaults to"enabled"
bulk_actions(contract, opts \\ [])
Builds generated action-form configs for bulk action surfaces.
This mirrors detail_actions/2, but filters to domain actions whose
normalized scope is "bulk" or whose row action contract explicitly opts
into batching with bulk: true or bulk: %{enabled: true}. It defaults the
target template to selected row ids. The returned configs intentionally use
the same modal payload shape so hosts can route bulk preview/apply through
ActionFormHost.
by_scope(actions)
@spec by_scope([action_item()]) :: map()
Groups visible action items by scope, using "unscoped" when no scope exists.
decision_for(action, decisions, default_status \\ "enabled")
Returns the decision for an action entry from action id or capability id.
decision_from_result(payload)
Converts a preview/apply result into normalized decision metadata.
detail_action(action, opts \\ [])
Builds a detail-action config that opens a domain action as an action form.
detail_actions(contract, opts \\ [])
Builds a map of generated detail-action configs for all visible actions.
form_action(action, opts \\ [])
@spec form_action( map(), keyword() ) :: action_item() | nil
Normalizes one domain action for use by ActionFormModal.
This is the bridge for host apps that already have a domain action contract
and only need a Selecto Components form shell. :endpoint_base can be passed
to derive standard preview/apply endpoints from the action id.
form_assigns(action, opts \\ [])
Builds assign data for SelectoComponents.Modal.ActionFormModal.
put_decision(decisions, action_id, decision)
Merges a new preview/apply capability decision into an existing decision map.
put_result_decision(decisions, action_id, result)
Merges a decision extracted from an action preview/apply result.
Successful preview/apply payloads usually carry capability_decision; errors
can be converted into disabled decisions with their validation reason.
request_template(action, opts \\ [])
Builds a portable action request template for preview/apply/availability calls.
status_counts(actions)
@spec status_counts([action_item()]) :: map()
Counts visible action items by normalized status.