MishkaGervaz.Table.Types.Action (MishkaGervaz v0.0.1-alpha.3)

Copy Markdown View Source

Built-in action type registry.

Provides lookup for built-in action types by atom name. Action types define how row action buttons are rendered.

Built-in Types

  • :link - Navigation link
  • :event - Custom event button (default)
  • :edit - Edit action (opens form)
  • :destroy - Delete button with confirmation
  • :update - Ash update action trigger
  • :unarchive - Restore archived record
  • :permanent_destroy - Permanently delete archived record
  • :row_click - Full-row click handler
  • :accordion - Expandable row toggle (requires :expand feature)

Custom Action Types

Implement the MishkaGervaz.Table.Behaviours.ActionType behaviour:

defmodule MyApp.ActionTypes.Archive do
  @behaviour MishkaGervaz.Table.Behaviours.ActionType
  use Phoenix.Component

  @impl true
  def render(assigns, action, record, ui, target) do
    # Return rendered HEEx
  end
end

Then use in DSL:

row_actions do
  action :archive, type: MyApp.ActionTypes.Archive
end

See MishkaGervaz.Table.Behaviours.TypeRegistry (base), MishkaGervaz.Table.Behaviours.ActionType, and MishkaGervaz.Table.Entities.RowAction.

Summary

Functions

Check if type name is registered.

List all built-in type names.

Get the default type module.

Get module by type name.

Get module, falling back to type itself for custom modules.

Resolve action type module from action configuration.

Functions

builtin?(type)

@spec builtin?(atom()) :: boolean()

Check if type name is registered.

builtin_types()

@spec builtin_types() :: [atom()]

List all built-in type names.

default()

@spec default() :: module() | nil

Get the default type module.

get(type)

@spec get(atom()) :: module() | nil

Get module by type name.

Returns the module for built-in types, or the type itself if it's already a module (for custom types).

get_or_passthrough(type)

@spec get_or_passthrough(atom()) :: module()

Get module, falling back to type itself for custom modules.

Unlike get/1 which returns nil for unknown types, this returns the type as-is (assuming it's a custom module).

resolve_type(action)

@spec resolve_type(map()) :: module()

Resolve action type module from action configuration.

Checks in order:

  1. If type is a module with render/4, use it directly
  2. If type is an atom, look up in built-in registry
  3. Otherwise, default to Event action

Examples

iex> MishkaGervaz.Table.Types.Action.resolve_type(%{type: :link})
MishkaGervaz.Table.Types.Action.Link

iex> MishkaGervaz.Table.Types.Action.resolve_type(%{type: :destroy})
MishkaGervaz.Table.Types.Action.Destroy