Built-in state-transition rules for tables.
Configured under the hooks.builtins DSL section. Each rule is opt-in
(default false) except :clear_selection_after_bulk, which defaults to
true.
Rules:
:switch_to_active_on_empty_archive— after a successful unarchive / permanent_destroy in:archivedmode, switch to:activemode once the archive list is observed empty on the next load.:switch_to_archive_on_empty_active— symmetric (rare; opt-in).:clear_selection_after_bulk— read by the bulk action handler.:reset_page_on_empty_current_page— if the current page becomes empty andpage > 1, reload page 1.:redirect_on_empty— whentotal_count == 0after a load, navigate to a path (string) orfn state -> path end.
Flow
Row actions don't normally reload, so after_row_action/3 triggers a reload
when any rule is enabled and stores :armed_action on the socket assigns.
Bulk actions already reload; after_bulk_action/3 just arms the flag.
after_load/2 (called from DataLoader.handle_async) reads the armed flag,
applies the relevant rule, and clears the flag.
See MishkaGervaz.Table.Web.State,
MishkaGervaz.Table.Web.DataLoader,
MishkaGervaz.Table.Web.Refresh,
MishkaGervaz.Table.Dsl.Hooks (rules live under the hooks DSL section).
Summary
Functions
Arm flags after a bulk action — the bulk handler already triggers a reload.
Apply built-in rules right after DataLoader.handle_async finishes loading.
Apply rules after a row action completed.
The built-in state-transition flags declared in hooks do … end.
Whether one built-in transition is switched on.
The raw value of one built-in, for the flags that carry more than a boolean.
Types
@type socket() :: Phoenix.LiveView.Socket.t()
Functions
@spec after_bulk_action(socket(), MishkaGervaz.Table.Web.State.t(), map() | nil) :: socket()
Arm flags after a bulk action — the bulk handler already triggers a reload.
@spec after_load(socket(), MishkaGervaz.Table.Web.State.t()) :: socket()
Apply built-in rules right after DataLoader.handle_async finishes loading.
@spec after_row_action(socket(), MishkaGervaz.Table.Web.State.t(), atom()) :: socket()
Apply rules after a row action completed.
If any rule is enabled, arm the socket and trigger a fresh load so
after_load/2 can react to the new total_count.
@spec config(MishkaGervaz.Table.Web.State.t()) :: map()
The built-in state-transition flags declared in hooks do … end.
Falls back to the shipped defaults — only clear_selection_after_bulk is on — so a resource
that declares no hooks still gets sane behaviour.
@spec enabled?(MishkaGervaz.Table.Web.State.t(), atom()) :: boolean()
Whether one built-in transition is switched on.
if AutoState.enabled?(state, :switch_to_active_on_empty_archive), do: ...
@spec value(MishkaGervaz.Table.Web.State.t(), atom()) :: term()
The raw value of one built-in, for the flags that carry more than a boolean.
AutoState.value(state, :redirect_on_empty)
#=> "/admin/dashboard"