PhoenixKitCatalogue.Web.TableConfig (PhoenixKitCatalogue v0.28.3)

Copy Markdown View Source

Column metadata for the catalogue admin tables, keyed by scope (:catalogues, :suppliers, :manufacturers). Pure data — cell and card rendering live in the LiveView. Labels are zero-arity fns so they resolve in the request's current locale.

For :detail_items / :detail_categories, the list also folds in enabled extensions' contributed columns (PhoenixKitCatalogue.Extensions.columns/1) — off by default, ids namespaced under the extension's key, and carrying their own render fn (see extension_columns/1) since the catalogue can't hardcode a case clause for a column it doesn't know about.

Summary

Functions

This scope's extension-contributed columns, keyed by their (already namespaced) id — the shape a cell renderer needs: %{id => %{label:, render:}}. Empty for scopes extensions don't contribute to.

Types

column()

@type column() :: %{
  id: String.t(),
  label: (-> String.t()),
  default?: boolean(),
  managed?: boolean(),
  sortable?: boolean(),
  sort_key: (map() -> term()) | nil,
  align: :left | :right,
  filterable?: boolean(),
  filter_type: :enum | nil,
  render: (map() -> Phoenix.LiveView.Rendered.t()) | nil
}

scope()

@type scope() ::
  :catalogues
  | :suppliers
  | :manufacturers
  | :attribute_groups
  | :detail_items
  | :detail_categories

Functions

column_map(scope)

@spec column_map(scope()) :: %{required(String.t()) => column()}

columns(scope)

@spec columns(scope()) :: [column()]

default_columns(scope)

@spec default_columns(scope()) :: [String.t()]

default_sort(arg1)

@spec default_sort(scope()) :: {String.t(), :asc | :desc}

extension_columns(scope)

@spec extension_columns(scope()) :: %{required(String.t()) => column()}

This scope's extension-contributed columns, keyed by their (already namespaced) id — the shape a cell renderer needs: %{id => %{label:, render:}}. Empty for scopes extensions don't contribute to.

Callers that render a table once per page (not once per row) should fetch this ONCE and pass it down, the same discipline CatalogueDetailLive already applies to any_media_thumb?/2 — an extension lookup inside a per-row loop would rescan on every cell.

managed_columns(scope)

@spec managed_columns(scope()) :: [column()]

sortable_visible(scope, ids)

@spec sortable_visible(scope(), [String.t()]) :: [column()]

validate_columns(scope, ids)

@spec validate_columns(scope(), [String.t()]) :: [String.t()]