SelectoComponents.Form.EventHandlers (selecto_components v0.4.5)

Consolidated event handlers for SelectoComponents forms.

This module serves as a single entry point for all form event handlers, organizing them into logical groups based on functionality:

  • ViewLifecycle - View configuration, validation, and application
  • FilterOperations - Adding, removing, and configuring filters
  • DrillDown - Drill-down operations from aggregates and graphs
  • ListOperations - List picker operations (add, remove, reorder)
  • QueryOperations - Query execution, sorting, and pagination
  • ModalOperations - Modal dialog display and interaction
  • ExportOperations - Export current results as CSV/JSON

architecture

Architecture

Each event handler group is defined in its own module under SelectoComponents.Form.EventHandlers.* namespace. This provides:

  • Better code organization and maintainability
  • Clear separation of concerns
  • Easier testing of individual handler groups
  • Improved documentation and discoverability

usage

Usage

This module is automatically imported when using SelectoComponents.Form:

defmodule MyLive do
  use SelectoComponents.Form
  # All event handlers are now available
end

event-handler-groups

Event Handler Groups

viewlifecycle

ViewLifecycle

  • set_active_tab - Switch between view/filter/save tabs
  • view-validate - Form validation without execution
  • view-apply - Form submission and query execution
  • load_view_config - Load saved view configuration

filteroperations

FilterOperations

  • treedrop - Add filter via drag-and-drop
  • filter_remove - Remove filter from list

drilldown

DrillDown

  • agg_add_filters - Drill down from aggregate view
  • graph_drill_down - Drill down from graph
  • chart_click - Drill down from chart element

listoperations

ListOperations

  • {:list_picker_add, ...} - Add item to list
  • {:list_picker_remove, ...} - Remove item from list
  • {:list_picker_move, ...} - Reorder item in list

queryoperations

QueryOperations

  • handle_params/3 - URL parameter routing
  • {:rerun_query_with_sort, ...} - Sort query results
  • {:update_detail_page, ...} - Pagination
  • {:query_executed, ...} - Handle query completion
  • {:update_view_config, ...} - Update configuration
  • {:filters_updated, ...} - Update filters

### ModalOperations

  • {:show_detail_modal, ...} - Show detail modal
  • {:close_detail_modal, ...} - Close detail modal

### ExportOperations

  • export_data - Export current results (CSV/JSON)
  • send_export_email - Email current results via configured delivery adapter

adding-new-event-handlers

Adding New Event Handlers

When adding new event handlers:

  1. Identify the appropriate handler group (or create a new one)
  2. Add the handler to the corresponding module
  3. Document the handler with @doc
  4. Add integration tests
  5. Update this module's documentation

implementation-notes

Implementation Notes

All event handler modules use the __using__ macro pattern to inject handlers into the calling LiveView. This allows handlers to access the LiveView's socket and assigns directly while keeping code organized.

Error handling is provided by SelectoComponents.Form.ErrorHandling, which wraps operations in try/rescue blocks and provides user-friendly error messages.