use-macro that injects column-management handle_event/3 callbacks into a
LiveView. Generic across scopes — pass the column-config module and scope via
options:
use PhoenixKitWarehouse.Web.ColumnManagement,
column_config: PhoenixKitWarehouse.ColumnConfig.InternalOrders,
scope: "warehouse_internal_orders"Required socket assigns (set them in mount/3)
:current_user_uuid— used for persistence keying.:selected_columns— initial list of visible column ids.:active_filters— initial list of column ids with active filter inputs.:filter_values— initial%{column_id => value}map (session-local).:show_column_modal—false.:temp_selected_columns/:temp_active_filters—nil.
Use assign_column_state/2 to bootstrap all of the above from the persisted
config.
View refresh
Filter changes (set_filter_value, clear_filter, save) need to recompute
the visible list. The macro calls __view_config_changed__/1 after mutating
state. The default implementation is identity; the host LV overrides it:
defoverridable __view_config_changed__: 1
def __view_config_changed__(socket) do
# rebuild socket.assigns.entries from source + selected/filters/sort
endPersisted shape (view_config)
%{
"columns" => ["id", ...],
"active_filters" => ["id", ...]
}Filter values are intentionally NOT persisted — they reset between sessions to avoid the "ghost filter" UX (user opens the page next week and finds zero results because of a saved filter they forgot about).
Summary
Functions
Bootstrap all column-management assigns from the persisted config. Pass the column-config module so this helper stays scope-agnostic.
Persist the selected columns + active filters for the current user and apply
them to the socket. Kept here (rather than in the __using__ quote) so the
macro stays thin; view_module.__view_config_changed__/1 lets each using
LiveView hook in after a successful save.
Functions
@spec assign_column_state(Phoenix.LiveView.Socket.t(), module()) :: Phoenix.LiveView.Socket.t()
Bootstrap all column-management assigns from the persisted config. Pass the column-config module so this helper stays scope-agnostic.
Persist the selected columns + active filters for the current user and apply
them to the socket. Kept here (rather than in the __using__ quote) so the
macro stays thin; view_module.__view_config_changed__/1 lets each using
LiveView hook in after a successful save.