AshBackpex.Filters.Boolean (Ash Backpex v0.1.6)
View SourceA Boolean filter for AshBackpex that renders checkboxes for true/false filtering.
This module provides both the UI rendering (via Backpex.Filters.Boolean) and
the Ash.Expr generation (via AshBackpex.Filters.Filter behavior) for filtering
boolean attributes.
Usage
The Boolean filter is automatically derived for :boolean type attributes when
using AshBackpex.LiveResource. You can also use it directly:
defmodule MyApp.Filters.Published do
use AshBackpex.Filters.Boolean
@impl Backpex.Filter
def label, do: "Published"
endFilter Values
The filter receives values as a list of strings:
["true"]- Filter fortruevalues only["false"]- Filter forfalsevalues only["true", "false"]- No filter applied (both selected = show all)[]- No filter applied (none selected)
Options
By default, this filter provides "True" and "False" checkboxes. You can
customize the options by overriding the options/1 callback:
@impl Backpex.Filters.Boolean
def options(_assigns) do
[
%{label: "Published", key: "true", predicate: nil},
%{label: "Draft", key: "false", predicate: nil}
]
endNote: The predicate field is not used by AshBackpex (it's for Backpex's
Ecto-based filtering). The Ash expression is generated by to_ash_expr/3.
Summary
Functions
Converts a boolean filter value to an Ash.Expr expression.
Functions
Converts a boolean filter value to an Ash.Expr expression.
Parameters
field- The atom name of the boolean attributevalue- The filter value (list of strings or single string)assigns- The LiveView assigns (unused by this filter)
Returns
Ash.Expr.t()- When filtering for true or false onlynil- When no filter should be applied (both selected, none selected, or invalid)
Examples
iex> Boolean.to_ash_expr(:published, ["true"], %{})
#Ash.Expr<published == true>
iex> Boolean.to_ash_expr(:published, ["false"], %{})
#Ash.Expr<published == false>
iex> Boolean.to_ash_expr(:published, ["true", "false"], %{})
nil
iex> Boolean.to_ash_expr(:published, [], %{})
nil