Cinder.FilterManager (Cinder v0.5.0)

View Source

Coordinator for Cinder's modular filter system.

Acts as the main interface for filter operations while delegating to individual filter type modules for specific implementations.

Summary

Functions

Builds filter values map for form inputs using modular filter system.

Clears all filters from the filter state.

Clears a specific filter from the filter state.

Counts the number of active filters.

Renders an individual filter input by delegating to the appropriate filter module.

Checks if a filter has a meaningful value using modular system.

Infers filter configuration from Ash resource attribute definitions.

Transforms form values into structured filter objects using modular filter system.

Processes filter parameters from form submission using modular filter system.

Processes raw filter value using the appropriate filter module.

Renders filter controls for a list of columns.

Validates all registered custom filters at application startup.

Types

column()

@type column() :: %{
  field: String.t(),
  label: String.t(),
  filterable: boolean(),
  filter_type: filter_type(),
  filter_options: keyword()
}

filter()

@type filter() :: %{type: filter_type(), value: filter_value(), operator: atom()}

filter_type()

@type filter_type() ::
  :text
  | :select
  | :multi_select
  | :multi_checkboxes
  | :date_range
  | :number_range
  | :boolean

filter_value()

@type filter_value() ::
  String.t()
  | [String.t()]
  | %{from: String.t(), to: String.t()}
  | %{min: String.t(), max: String.t()}

filters()

@type filters() :: %{required(String.t()) => filter()}

Functions

build_filter_values(filterable_columns, filters)

Builds filter values map for form inputs using modular filter system.

clear_all_filters(filters)

Clears all filters from the filter state.

clear_filter(filters, key)

Clears a specific filter from the filter state.

count_active_filters(filters)

Counts the number of active filters.

filter_input(assigns)

Renders an individual filter input by delegating to the appropriate filter module.

has_filter_value?(value)

Checks if a filter has a meaningful value using modular system.

infer_filter_config(key, resource, slot)

Infers filter configuration from Ash resource attribute definitions.

params_to_filters(filter_params, columns)

Transforms form values into structured filter objects using modular filter system.

process_filter_params(filter_params, columns)

Processes filter parameters from form submission using modular filter system.

process_filter_value(raw_value, column)

Processes raw filter value using the appropriate filter module.

This function is public to enable comprehensive testing of custom filter processing.

render_filter_controls(assigns)

Renders filter controls for a list of columns.

Parameters

  • columns - List of column definitions
  • filters - Current filter state map
  • theme - Theme configuration
  • target - LiveComponent target for events

Returns

HEEx template for filter controls

validate_runtime_filters()

Validates all registered custom filters at application startup.

This function should be called during application initialization to ensure all custom filters are properly implemented and available.

Returns

:ok if all filters are valid, logs warnings for any issues

Examples

# In your application.ex start/2 function
case Cinder.FilterManager.validate_runtime_filters() do
  :ok -> :ok
  {:error, _} -> :ok  # Continue startup but log issues
end