Repository navigation
Conversation
Flo0807
marked this pull request as draft
October 26, 2026 14:34
This was referenced Oct 26, 2026
This was referenced Oct 28, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- Configure the built-in filters in the LiveResource like fields - Document configuring filters in the LiveResource - Configure the demo filters in the LiveResources - Cover the options of the generic filters in tests
Flo0807
force-pushed
the
feature/generic-filters
branch
from
November 13, 2026 09:46
26ae38d to
7ae5489
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #357.
Stack (merge in this order)
developNote
Stacked on #2340 (which is stacked on #2338). It builds on the expression-based filter contract of #2340, so the base branch is
feature/adapter-neutral-filters-and-metrics. Both PRs target v0.25, so users migratequery/4once, straight to the callbacks of this PR.What changes
Filters now work like fields: a LiveResource configures the built-in filters with options instead of defining a module per filter.
use Backpex.Filter, config_schema: [...].Backpex.Filter.validate_config!/2validates every filter with NimbleOptions against the general options (module,label,default,presets,can?,condition) and the module's schema. It raises on unknown or invalid options, or when a filter has neither a:labelnorlabel/0.Backpex.LiveResource.active_filters/1returns validated filters.SelectandMultiSelecttake:options(a list or a function of the assigns) and:prompt.Rangetakes:type(:date,:datetimeor:number) andBooleantakes:options.use Backpex.Filters.Selectand the other built-in filters keep their callbacks (options/1,prompt/0,type/0). The callbacks become the defaults of the options, and options in the LiveResource take precedence. Modules that only set label, prompt, options andcan?keep working unchanged.:can?is ANDed with the module'scan?/1, so per-resource visibility no longer needs a module.:conditionreplaces the module'scondition/3for a single filter. It covers filters that only exist to change the condition, e.g. soft-delete selects, overlap ranges or timezone-shifted date ranges.{name, config}, consistent with fields:type/1is nowtype/2andvalidate/2is nowvalidate/3. A filter that still defines either doesn't compile.changeset/3andcondition/3receive the tuple instead of the field. Oldchangeset/3code raises aFunctionClauseErrorin Ecto instead of passing silently (verified).render/1andrender_form/1get@filter.Backpex.Filter.to_condition/3, which honours the:conditionoption."Select an option..."(default prompt of the select filter).Why the tuple instead of passing options through assigns
Fields already pass
{name, field_options}to their callbacks, and the issue asks for filters to work the same way. The breaking surface stays small:condition/3is new in Let the adapter turn filter conditions and metric aggregates into queries #2340, so users have no extra migration there.type/1,validate/2) or raise on first render (changeset/3).Demo
PostCategorySelectas an example of a reusable filter module.roleandagefilters to Users;ageuses:condition.Docs
Merged with #2340 (and
developthrough it)develop's filter fixes are ported to the generic filters:Backpex.Filters.Booleanignores selected keys without an option.Backpex.Filters.Rangerefuses nested boundaries as a cast error and parses the boundaries of a:numberrange on an integer field as integers, with the field type fromBackpex.Resource.field_type/2.develop's new filter tests use the{name, config}callbacks and validated filter configs.Checks
Backpex.Exprexpressions; the:conditionoption and the demo'sagefilter useexpr/1.mix testincl.integration_test/1442 passed (182 doctests),mix test --only e2e60 passed,mix format --check-formatted,mix credo,mix deps.unlock --check-unusedandmix gettext.extract --check-up-to-datepass. Demo: 51 tests, the 38 Playwright tests andbun run lintpass. Thecreate-filterskill now shows the{field, _config}callbacks of this PR.mix testincl.integration_test/1406 passed (173 doctests),mix test --only e2e60 passed,mix format --check-formatted,mix credoandmix deps.unlock --check-unusedpass. Demo: 51 tests, the 38 Playwright tests andbun run lintpass.mix credo(no issues),mix compile --warnings-as-errors --force,mix format --check-formatted,mix docs(no warnings), Sobelow,mix deps.unlock --check-unusedandmix gettext.extract --check-up-to-datepass.bun run lintpass.defaultredirect works, and the "Last 7 Days" preset applies.