MishkaGervaz.Table.Web.AutoState (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

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 because it matches existing behavior.

Rules:

  • :switch_to_active_on_empty_archive — after a successful unarchive / permanent_destroy in :archived mode, switch to :active mode 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 and page > 1, reload page 1.
  • :redirect_on_empty — when total_count == 0 after a load, navigate to a path (string) or fn 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.

Types

socket()

@type socket() :: Phoenix.LiveView.Socket.t()

Functions

after_bulk_action(socket, state, arg3)

@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.

after_load(socket, state)

@spec after_load(socket(), MishkaGervaz.Table.Web.State.t()) :: socket()

Apply built-in rules right after DataLoader.handle_async finishes loading.

after_row_action(socket, state, action_name)

@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.

config(state)

@spec config(MishkaGervaz.Table.Web.State.t()) :: map()

enabled?(state, key)

@spec enabled?(MishkaGervaz.Table.Web.State.t(), atom()) :: boolean()

value(state, key)

@spec value(MishkaGervaz.Table.Web.State.t(), atom()) :: term()