Aurora.Uix.Filter (Aurora UIX v0.1.4-rc.0)

Copy Markdown

Provides a structured filter representation for query conditions with support for multiple comparison operators, value storage, and type-safe construction.

Key Features

  • Multiple comparison operators (equality, range, set membership)
  • Type-safe construction with enforced keys
  • Flexible value storage in list format
  • Support for enabled/disabled state management

Supported Operators

SymbolAtomDescription
=:eqEqual to
>:gtGreater than
<:ltLess than
:geGreater than or equal
:leLess than or equal
b:betweenBetween two values
i:inIn a set of values

Examples

# Creating a basic equality filter
filter = Aurora.Uix.Filter.new(:user_id)
%Aurora.Uix.Filter{key: :user_id, condition: :eq, enabled?: false, values: [nil]}

# Creating with custom attributes
filter = Aurora.Uix.Filter.new(%{
  key: :age,
  condition: :gt,
  values: [18],
  enabled?: true
})
%Aurora.Uix.Filter{key: :age, condition: :gt, enabled?: true, values: [18]}

# Creating from string key
Aurora.Uix.Filter.new("status")
%Aurora.Uix.Filter{key: :status, condition: :eq, enabled?: false, values: [nil]}

Constraints

  • :key must be an atom (enforced at struct creation)
  • :condition must be one of the supported operators
  • :values are always stored in a list, even for single-value conditions
  • :enabled? defaults to false for new filters

Summary

Functions

Updates an existing filter with new attributes.

Returns the supported condition mappings.

Creates a new filter struct from various input types.

Types

t()

@type t() :: %Aurora.Uix.Filter{
  condition: atom(),
  enabled?: boolean(),
  from: term(),
  key: atom(),
  to: term()
}

Functions

change(filter, attrs)

@spec change(t(), map()) :: t()

Updates an existing filter with new attributes.

Parameters

  • filter (t()) - Existing filter struct to modify
  • attrs (map()) - Map of attributes to update

Returns

  • t() - Updated filter struct with merged attributes

Examples

filter = Aurora.Uix.Filter.new(:status)
Aurora.Uix.Filter.change(filter, %{condition: :in, values: ["active", "pending"]})
%Aurora.Uix.Filter{
  key: :status,
  condition: :in,
  enabled?: false,
  values: ["active", "pending"]
}

conditions(field \\ %{})

@spec conditions(map()) :: [{binary(), atom()}]

Returns the supported condition mappings.

Each tuple contains a human-readable symbol and its corresponding internal atom representation used in filter conditions.

Returns

  • list({binary(), atom()}) - Ordered list of condition mappings

Examples

Aurora.Uix.Filter.conditions()
[
  {"=", :eq},
  {">", :gt},
  {"<", :lt},
  {"≥", :ge},
  {"≤", :le},
  {"b", :between},
  {"i", :in}
]

new(attrs)

@spec new(map() | atom() | binary()) :: t()

Creates a new filter struct from various input types.

Parameters

  • attrs (map() | atom() | binary()) - Filter configuration where:

    • Map must contain :key (atom) and :condition (atom)
    • Atom creates equality filter for that key
    • String converts to atom and creates equality filter

Returns

  • t() - New filter struct with provided or default values

Examples

# From map with all attributes
Aurora.Uix.Filter.new(%{key: :price, condition: :between, values: [10, 50]})
%Aurora.Uix.Filter{key: :price, condition: :between, enabled?: false, values: [10, 50]}

# From atom key (defaults to equality)
Aurora.Uix.Filter.new(:category)
%Aurora.Uix.Filter{key: :category, condition: :eq, enabled?: false, values: [nil]}

# From string key
Aurora.Uix.Filter.new("created_at")
%Aurora.Uix.Filter{key: :created_at, condition: :eq, enabled?: false, values: [nil]}