Skip to main content

Module filters

Module filters 

Source
Expand description

Field classification + filter inference (renamed from intelligence per Section 4 of the strategic reset plan).

Pure helpers that turn schema metadata into user-facing hints: the form-field label beside an input, the masked display of a sensitive value on a list page, the filter dropdown inferred from a status column. Nothing in this module touches the filesystem, the database, or produces HTML — it returns structured data that the admin renderer consumes.

§Public API

  • classify_field — labels a field by role (Id, Email, Status, …). Every downstream renderer branches on this enum.
  • field_ui_metadata — packages the label, placeholder, hint, and sensitivity marker a form needs to render one input.
  • infer_filters — walks a model’s fields and decides which filters make sense on its list page.
  • format_relation_cell — render a foreign-key cell on the list page as Target #42 (or 42 when the target name is unknown).
  • mask_pii — deterministic string masker used to hide personal data by default on list views.

Slimmed for Tier 1: the legacy module’s country/industry/GDPR ContextConfig plumbing was wired through crate::ai (Tier 2) so it’s been removed; classification is now shape-based only. classify_search / SearchIntent are dropped per Section 3.

Structs§

FieldUI
Everything a form / list renderer needs to present one field to a human. All strings are plain text (no HTML) — the caller escapes before emitting.
FilterDef
One filter the list page should show for a model.

Enums§

FieldRole
The role a field plays in the admin UI. One field maps to exactly one role; the ordering of branches in classify_field resolves overlaps (e.g. an email column is FieldRole::Email, not FieldRole::PlainText).
FilterKind
What shape of filter the admin list page should render for a given field.

Functions§

classify_field
Assign a FieldRole to one field.
field_ui_metadata
Package a field’s display metadata for the admin form / list renderers. All strings are plain text — escape before emitting.
field_ui_metadata_with_relation
Like field_ui_metadata but relation-aware. Pass the singular display name of the target model when the schema records a relation for this field; the returned FieldUI then carries relation_label and a hint of the form “Foreign key to Target”.
format_relation_cell
Render “Target #42” for a foreign-key cell on a list view. Falls back to the raw id when the caller doesn’t have a target name.
infer_filters
Infer the filter controls for a model’s list page from its fields. Order follows the order of fields; every filter references a field that actually exists on the model.
infer_filters_with_registry
Like infer_filters_with_relations but consults the super::relations::RelationRegistry so FK fields can be promoted to FilterKind::FkAutocomplete — the registry carries the target’s admin slug, which the autocomplete endpoint URL depends on.
infer_filters_with_relations
Like infer_filters but invokes relation_target_of for each field to detect relation columns. If the callback returns Some(target), the filter is emitted as FilterKind::RelationSelect instead of the numeric-exact fallback.
mask_pii
Produce a masked display string for a sensitive value. Keeps the first few characters so a reviewer can tell which row they’re looking at, replaces the rest with . Length of the output matches the input. Deterministic, Unicode-safe.