SelectoComponents.Form.FilterRendering (selecto_components v0.3.21)
Handles rendering of filter forms for SelectoComponents.
This module contains all the logic for rendering different types of filters:
- Standard text/number filters
- Datetime filters with shortcuts, relative dates, and between ranges
- Custom component filters
Also provides helper functions for:
- Building filter lists from Selecto definitions
- Formatting datetime values for HTML inputs
- Detecting date shortcuts and relative date patterns
Link to this section Summary
Functions
Build a list of available filters from Selecto configuration.
Format datetime value for HTML input fields.
Hash filter structure and comparator mode, not filter values.
Check if a value is a date shortcut (today, this_week, last_month, etc.).
Check if a value is a relative date format (5, 3-7, -30, 30-).
Render datetime filter with appropriate controls.
Render a filter form based on the filter definition and field type.
Render standard text/number filter with basic comparison operators.
Render text search filter for tsvector columns.
Link to this section Functions
build_filter_list(selecto)
Build a list of available filters from Selecto configuration.
Includes:
- Explicit filters defined in Selecto.filters()
- Columns marked as filterable (make_filter: true)
- Columns without custom formatting (assumed to be filterable)
format_datetime_value(value, type)
Format datetime value for HTML input fields.
Handles different datetime types:
- :date -> YYYY-MM-DD format
- :naive_datetime/:utc_datetime -> YYYY-MM-DDTHH:MM format for datetime-local inputs
hash_filter_structure(filters)
Hash filter structure and comparator mode, not filter values.
This ensures the component remounts when filters are added/removed or comparator mode changes, but not when filter values change.
is_date_shortcut(value)
Check if a value is a date shortcut (today, this_week, last_month, etc.).
is_relative_date(value)
Check if a value is a relative date format (5, 3-7, -30, 30-).
Patterns:
- N = N days ago (e.g., 5 = 5 days ago)
- N-M = between N and M days ago (e.g., 3-7 = 3-7 days ago)
- -N = more than N days ago (e.g., -30 = over 30 days ago)
- N- = within N days (e.g., 30- = within 30 days)
render_datetime_filter(assigns)
Render datetime filter with appropriate controls.
Supports multiple comparison modes:
- Standard comparisons (=, !=, >, >=, <, <=)
- Date-only comparisons (DATE=, DATE!=)
- Range filters (BETWEEN, DATE_BETWEEN)
- Quick shortcuts (today, this_week, last_month, etc.)
- Relative dates (5, 3-7, -30, 30-)
- Null checks (IS NULL, IS NOT NULL)
render_filter_form(assigns, uuid, index, section, filter_value)
Render a filter form based on the filter definition and field type.
Handles three types of filters:
- Custom component filters (with :component type)
- Datetime filters (for :date, :naive_datetime, :utc_datetime types)
- Standard filters (for all other types)
render_standard_filter(assigns)
Render standard text/number filter with basic comparison operators.
Supports:
- Equality (=, !=)
- Comparisons (>, >=, <, <=)
- Text search (LIKE, NOT LIKE)
- Null checks (IS NULL, IS NOT NULL)
render_text_search_filter(assigns)
Render text search filter for tsvector columns.
This filter type uses PostgreSQL's full-text search with websearch_to_tsquery, which supports natural language search queries including:
- Simple words: "matrix" finds documents containing "matrix"
- Phrases: "the matrix" finds documents with those words near each other
- OR searches: "matrix OR reloaded" finds documents with either word
- Exclusions: "matrix -reloaded" excludes documents with "reloaded"