PhoenixKitProjects.Web.ListUi (PhoenixKitProjects v0.19.0)

Copy Markdown View Source

Shared plumbing for the admin list pages (Projects / Tasks / Templates): column-visibility persistence, search-param coercion, the client-search haystack builder, and the Columns dropdown component.

Each list page keeps its own column roster and settings key; these helpers only own the mechanics so the three pages can't drift apart.

Summary

Functions

Coerces the search event payload to a binary. A forged search[x]=y body arrives as a map — the query side would shrug it off, but rendering a map back into the input's value would crash the LV.

The Columns dropdown: a focus-based daisyUI dropdown (closes when focus leaves) with one checkbox per optional column, each pushing toggle_column with its column key. options is the page's {key, translated_label} roster; visible its current visible set.

Reads a page's visible-column set from settings. nil (never saved) falls back to defaults; an empty string is a deliberate "all optional columns hidden". Unknown names are dropped and order is normalized to the optional roster.

Lowercased match target for the TableLocalSearch hook: the record's primary fields plus every language's translated values for the same fields — the same coverage as the server-side ilike search, so the instant client filter and the authoritative server result agree.

Toggles one column in the visible set and persists the result (comma-joined, one settings row per page). Returns the new set.

Functions

coerce_search(params)

@spec coerce_search(map()) :: String.t()

Coerces the search event payload to a binary. A forged search[x]=y body arrives as a map — the query side would shrug it off, but rendering a map back into the input's value would crash the LV.

columns_control(assigns)

The Columns dropdown: a focus-based daisyUI dropdown (closes when focus leaves) with one checkbox per optional column, each pushing toggle_column with its column key. options is the page's {key, translated_label} roster; visible its current visible set.

Attributes

  • options (:list) (required)
  • visible (:list) (required)

read_visible_columns(key, optional, defaults)

@spec read_visible_columns(String.t(), [String.t()], [String.t()]) :: [String.t()]

Reads a page's visible-column set from settings. nil (never saved) falls back to defaults; an empty string is a deliberate "all optional columns hidden". Unknown names are dropped and order is normalized to the optional roster.

search_haystack(record, fields)

@spec search_haystack(
  struct(),
  [String.t()]
) :: String.t()

Lowercased match target for the TableLocalSearch hook: the record's primary fields plus every language's translated values for the same fields — the same coverage as the server-side ilike search, so the instant client filter and the authoritative server result agree.

fields are the translation-map keys (strings); each must also name a schema field (e.g. ["name", "description"], ["title", "description"]).

toggle_visible_column(key, optional, visible, col)

@spec toggle_visible_column(String.t(), [String.t()], [String.t()], String.t()) :: [
  String.t()
]

Toggles one column in the visible set and persists the result (comma-joined, one settings row per page). Returns the new set.