View Source Backpex.ItemAction behaviour (Backpex v0.6.0)

Behaviour implemented by all item actions.

Summary

Callbacks

cancel button label

The changeset to be used in the resource action. It may be used to validate form inputs.

This text is being displayed in the confirm dialog.

Confirm button label

A list of fields to be displayed in the item action. See Backpex.Field. In addition you have to provide a type for each field in order to support changeset generation.

Performs the action. It takes the socket and the casted and validated data (received from Ecto.Changeset.apply_action/2).

Action icon

Initial change. The result will be passed to changeset/3 in order to generate a changeset.

Action label (Show label on hover)

Functions

Defines Backpex.ItemAction behaviour and provides default implementations.

Callbacks

Link to this callback

cancel_label(assigns)

View Source (optional)
@callback cancel_label(assigns :: map()) :: binary()

cancel button label

Link to this callback

changeset(change, attrs, metadata)

View Source (optional)
@callback changeset(
  change ::
    Ecto.Schema.t()
    | Ecto.Changeset.t()
    | {Ecto.Changeset.data(), Ecto.Changeset.types()},
  attrs :: map(),
  metadata :: keyword()
) :: Ecto.Changeset.t()

The changeset to be used in the resource action. It may be used to validate form inputs.

Additional metadata is passed as a keyword list via the third parameter.

The list of metadata:

  • :assigns - the assigns
  • :target - the name of the form target that triggered the changeset call. Default to nil if the call was not triggered by a form field.
Link to this callback

confirm(assigns)

View Source (optional)
@callback confirm(assigns :: map()) :: binary()

This text is being displayed in the confirm dialog.

There won't be any confirmation when this function is not defined.

Link to this callback

confirm_label(assigns)

View Source (optional)
@callback confirm_label(assigns :: map()) :: binary()

Confirm button label

@callback fields() :: list()

A list of fields to be displayed in the item action. See Backpex.Field. In addition you have to provide a type for each field in order to support changeset generation.

The following fields are currently not supported:

Link to this callback

handle(socket, items, params)

View Source
@callback handle(
  socket :: Phoenix.LiveView.Socket.t(),
  items :: [map()],
  params :: map() | struct()
) ::
  {:noreply, Phoenix.LiveView.Socket.t()}
  | {:reply, map(), Phoenix.LiveView.Socket.t()}

Performs the action. It takes the socket and the casted and validated data (received from Ecto.Changeset.apply_action/2).

@callback icon(assigns :: map()) :: %Phoenix.LiveView.Rendered{
  caller: term(),
  dynamic: term(),
  fingerprint: term(),
  root: term(),
  static: term()
}

Action icon

@callback init_change(assigns :: map()) ::
  Ecto.Schema.t()
  | Ecto.Changeset.t()
  | {Ecto.Changeset.data(), Ecto.Changeset.types()}

Initial change. The result will be passed to changeset/3 in order to generate a changeset.

This function is optional and can be used to use changesets with schemas in item actions. If this function is not provided a changeset will be generated automatically based on the provided types in fields/0.

@callback label(assigns :: map()) :: binary()

Action label (Show label on hover)

Functions

Defines Backpex.ItemAction behaviour and provides default implementations.