Simple Filters
Simple Filters component in Lens.
🧼 Simple Filters
The SimpleFilters component provides a minimal, plug-and-play way to create dropdown or date filters powered by your Lens view config. It supports filtering fields based on enums, relationships, or date values and can express hierarchical filters using dependency chains.
✨ Overview
At its core, SimpleFilters reads from a special config object (typically called lensSimpleFilters) and renders interactive filter elements. These filters are most useful for quick filtering of data in views such as tables, cards, or dashboards.
🧱 Configuration Object
The filters are defined in the lensSimpleFilters config within a view:
🧠 Internals and Context Behavior
SimpleFilters relies on a SimpleFilterContextProvider, which connects to two key providers:
LensContext: Provides access to APIs and global config likeread_relation_option.ViewContext: Provides thefilters,setFilters, andconfigfor the current view.
🔄 Initialization Flow
- It reads the config from the current view (
ViewContext.config.filters) - Filters marked with
asSimple: trueare selected - These filters are converted into an
attributesArray - Default filter values are initialized via the
initilizeFilterutility - The
SimpleFiltersContextexposes methods to update conditions and apply filters
📦 Provided Context Values
The SimpleFiltersContext shares the following via React context:
| Key | Description |
|---|---|
attributesArray | List of simple filters to render |
initialisedFilter | Either provided defaultFiltersValue or generated from the config |
filterContainerRef | Ref used for scrolling/styling |
setFilters | View-level function to apply updated filters |
updateCondition | Function to update a specific filter condition |
filter | Flattened version of active filters (excluding nested conditions) |
queryEndpoint | API endpoint used to load enum filter options dynamically |
permissionHeaders | Any extra headers needed for backend permission enforcement |
classNames | Optional class overrides for styling the wrapper and filters |
🧩 Component Usage
🧠 Best Practices
- Use
dependsOnin your filter config to enforce selection order (state → district → city). - Provide static
optionsonly for standalone filters; prefermodelwhen dynamic loading is needed. - Wrap
SimpleFiltersinside views powered byLensProviderandViewContext.
Let me know if you'd like to go deeper into SimpleFiltersList, rendering filters as chips, or overriding filter UI!