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
A row action that takes its row out of the view takes it off the total too,
so after_row_action/3 answers the rules at once from that total, reading
no rows. Bulk actions reload; after_bulk_action/3 arms the flag on the
socket assigns. 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 took its row out of the view.
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 took its row out of the view.
state carries the total the action left, its row already taken off, and
the rules are answered from it at once, as after_load/2 answers them after
a load: no rows are read to learn it. A rule that moves the table, such as
switching to the active view, loads what it moves to.
@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"