Skip to main content

Module intelligence

Module intelligence 

Source
Expand description

Admin Intelligence Layer — 0.7.0.

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

§Principles

  • Inference, not configuration. Rules are derived from (field name, field type, nullability) + ContextConfig. No per-project hooks.
  • Conservative sensitivity. Under GDPR / country rules, the layer marks a field as sensitive up, never down. A project without context gets 0.6.x behaviour.
  • Deterministic. Same inputs → same outputs. No ordering surprises, no random masking length.

§Public API

  • classify_field — labels a field by role (Id, Email, Personnummer, …). 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.
  • classify_search — inspects a search query and tells the list handler what the user probably meant (NumericId, Email, Personnummer, Text).
  • mask_pii — deterministic string masker used to hide personal data by default on list views.

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. Produced by infer_filters.

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. Each variant maps to a concrete HTML control.
SearchIntent
What the user probably typed into the list-page search box. Letting the handler branch on this gives cleaner narrow-match behaviour than “grep every String field”.

Functions§

classify_field
Assign a FieldRole to one field, taking context into account.
classify_search
Guess what the user meant by the text in the list-page search box. Order of tries: numeric → email → personnummer → text.
classify_search_for_field
0.8.0 — variant of classify_search that knows the field is a relation. When the query parses as a non-negative integer, emits SearchIntent::RelationId carrying the target model; otherwise falls through to classify_search for the usual shape-based routing. Called by the admin search handler when the user is searching a specific FK column.
context_global
Process-global cache for the project’s rustio.context.json.
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
0.8.0 — like field_ui_metadata but relation-aware. Pass the singular display name of the target model (e.g. "Applicant") when the schema records a relation for this field; the returned FieldUI then carries relation_label and a form hint of the form “Foreign key to Applicant”. Passing None is equivalent to calling field_ui_metadata.
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. Kept as a free function so the admin list renderer doesn’t have to reach into FieldUI directly for the common case.
infer_filters
Infer the filter controls for a model’s list page from its fields plus active context. Order follows the order of fields; every filter references a field that actually exists on the model.
infer_filters_with_relations
0.8.0 — 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 so the layout doesn’t jump when a user toggles visibility.