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

Copy Markdown View Source

Built-in column type registry.

Provides lookup for built-in column types by atom name. Custom column types can be used directly by passing the module.

Built-in Types

  • :text - Plain text (default)
  • :boolean - Boolean with checkmark/X icons
  • :number - Numeric values
  • :date - Date formatting
  • :datetime - DateTime formatting
  • :uuid - UUID with truncation
  • :array - Array/list values
  • :badge - Status badges with colors
  • :link - Clickable links

Usage in DSL

columns do
  column :name                          # Auto-detects type
  column :status, type: :badge          # Built-in type
  column :color, type: MyApp.ColorType  # Custom type
end

See MishkaGervaz.Table.Behaviours.TypeRegistry (base), MishkaGervaz.Table.Behaviours.ColumnType, and MishkaGervaz.Table.Entities.Column.

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.

Infer column type module from Ash attribute type.

Resolve column type module from explicit type or Ash attribute.

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).

infer_from_ash_type(arg1)

@spec infer_from_ash_type(map() | nil) :: module()

Infer column type module from Ash attribute type.

Maps Ash types to appropriate column type modules for rendering. Returns default type when attribute is nil or type is unknown.

Auto-generated from builtin type registry mappings.

resolve_type(column, attributes)

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

Resolve column type module from explicit type or Ash attribute.

Checks in order:

  1. If type_module is already set (from DSL transform), use it
  2. If ui.type is set and is a module with render/4, use it directly
  3. If ui.type is set and is an atom, look up in built-in registry
  4. Otherwise, infer from Ash attribute type

Examples

iex> MishkaGervaz.Table.Types.Column.resolve_type(%{ui: %{type: :badge}}, %{})
MishkaGervaz.Table.Types.Column.Badge

iex> MishkaGervaz.Table.Types.Column.resolve_type(%{name: :active}, %{active: %{type: Ash.Type.Boolean}})
MishkaGervaz.Table.Types.Column.Boolean