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.

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

Link to this type

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

Link to this function

available(contract, opts \\ [])

@spec available(
  term(),
  keyword()
) :: [action_item()]

Returns action items suitable for row/global/bulk action renderers.

Options:

  • :scope filters actions to a scope such as :row or "bulk"
  • :decisions supplies %{"action_id" => decision} or %{"capability" => decision}
  • :capability_resolver supplies a host-owned resolver function invoked with a %Selecto.Capabilities.Request{} for actions that declare a capability
  • :actor, :tenant, :domain, and :context are copied into resolver requests
  • :default_status defaults to "enabled"
Link to this function

bulk_actions(contract, opts \\ [])

@spec bulk_actions(
  term(),
  keyword()
) :: map()

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.

Link to this function

by_scope(actions)

@spec by_scope([action_item()]) :: map()

Groups visible action items by scope, using "unscoped" when no scope exists.

Link to this function

decision_for(action, decisions, default_status \\ "enabled")

@spec decision_for(map(), map(), String.t()) :: map()

Returns the decision for an action entry from action id or capability id.

Link to this function

decision_from_result(payload)

@spec decision_from_result(term()) :: map()

Converts a preview/apply result into normalized decision metadata.

Link to this function

detail_action(action, opts \\ [])

@spec detail_action(
  map(),
  keyword()
) :: map()

Builds a detail-action config that opens a domain action as an action form.

Link to this function

detail_actions(contract, opts \\ [])

@spec detail_actions(
  term(),
  keyword()
) :: map()

Builds a map of generated detail-action configs for all visible actions.

Link to this function

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.

Link to this function

form_assigns(action, opts \\ [])

@spec form_assigns(
  map(),
  keyword()
) :: map()

Builds assign data for SelectoComponents.Modal.ActionFormModal.

Link to this function

put_decision(decisions, action_id, decision)

@spec put_decision(map(), term(), map()) :: map()

Merges a new preview/apply capability decision into an existing decision map.

Link to this function

put_result_decision(decisions, action_id, result)

@spec put_result_decision(map(), term(), term()) :: map()

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.

Link to this function

request_template(action, opts \\ [])

@spec request_template(
  map(),
  keyword()
) :: map()

Builds a portable action request template for preview/apply/availability calls.

Link to this function

status_counts(actions)

@spec status_counts([action_item()]) :: map()

Counts visible action items by normalized status.