MishkaGervaz.Table.Web.Events.BulkActionHandler behaviour (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Handles bulk action execution for Events module.

This module provides functions for executing bulk actions on selected records, including building queries and running Ash bulk operations.

Customization

You can create a custom BulkActionHandler:

defmodule MyApp.CustomBulkActionHandler do
  use MishkaGervaz.Table.Web.Events.BulkActionHandler

  # Custom bulk action with additional logging
  def execute_ash_bulk_action(action, ash_action, selected_ids, state, socket) do
    MyApp.Logger.info("Executing bulk action", action: ash_action, count: length(selected_ids))
    super(action, ash_action, selected_ids, state, socket)
  end
end

Then configure it in your resource's DSL:

mishka_gervaz do
  table do
    events do
      bulk_action MyApp.CustomBulkActionHandler
    end
  end
end

See MishkaGervaz.Table.Web.Events, MishkaGervaz.Table.Entities.BulkAction, MishkaGervaz.Table.Web.DataLoader, and the sibling handlers SanitizationHandler, RecordHandler, SelectionHandler, HookRunner, RelationFilterHandler.

Summary

Callbacks

Builds a query for bulk operations.

Executes a bulk action based on its handler type.

Types

bulk_action()

@type bulk_action() :: map()

selected_ids()

@type selected_ids() :: list() | :all | {:all_except, list()}

socket()

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

state()

@type state() :: MishkaGervaz.Table.Web.State.t()

Callbacks

build_bulk_query(resource, state, filter)

@callback build_bulk_query(
  resource :: module(),
  state :: state(),
  filter :: {:exclude, list()} | nil
) :: Ash.Query.t()

Builds a query for bulk operations.

Applies any necessary filters based on the selection.

execute(bulk_action, selected_ids, state, socket)

@callback execute(
  bulk_action :: bulk_action() | nil,
  selected_ids :: selected_ids(),
  state :: state(),
  socket :: socket()
) :: {:noreply, socket()}

Executes a bulk action based on its handler type.

Dispatches to the appropriate handler: :parent, function, or Ash action.

execute_ash_bulk_action(action, ash_action, selected_ids, state, socket)

@callback execute_ash_bulk_action(
  action :: bulk_action(),
  ash_action :: atom(),
  selected_ids :: selected_ids(),
  state :: state(),
  socket :: socket()
) :: {:noreply, socket()}

Executes an Ash bulk action.

Handles both bulk_update and bulk_destroy based on action type.