Skip to content

Better label format for evidence tray#7608

Open
lucanovera wants to merge 4 commits intomainfrom
ENG-2748-UI-Evidence-tray-label-cleanup
Open

Better label format for evidence tray#7608
lucanovera wants to merge 4 commits intomainfrom
ENG-2748-UI-Evidence-tray-label-cleanup

Conversation

@lucanovera
Copy link
Contributor

@lucanovera lucanovera commented Mar 10, 2026

Ticket ENG-2748

Description Of Changes

Evidence items in the assessment detail view display a field_name label derived from the backend. The backend emits this value in two different formats depending on whether the evidence was generated by the AI path or the non-AI (template) path:

  • AI path returns a bare key: "legal_basis", "retention_period"
  • Non-AI path returns a full dotted path: "privacy_declaration.legal_basis_for_processing", "system.data_security_practices"

Our normal pattern for this kind of display mapping is a static Record<string, string> constant (e.g. ANSWER_SOURCE_LABELS, ASSESSMENT_STATUS_LABELS).

That approach doesn't work here because the set of possible field_name values is open-ended — the non-AI path reflects whatever fields are defined on PrivacyDeclarationSummary and SystemSummary, and the AI path is LLM-generated free text. A static map would silently miss new fields or any unexpected LLM output.

Instead, we introduce a small formatFieldName utility in ~/features/common/utils that:

  1. Strips the dotted prefix (if present), taking only the leaf segment
  2. Replaces underscores with spaces
  3. Applies sentenceCase

This handles both path formats and degrades gracefully for any unseen value. Examples:

Raw field_name Source Label
legal_basis AI Legal basis
retention_period AI Retention period
data_categories AI Data categories
privacy_declaration.legal_basis_for_processing Non-AI Legal basis for processing
privacy_declaration.data_use Non-AI Data use
privacy_declaration.processes_special_category_data Non-AI Processes special category data
system.data_security_practices Non-AI Data security practices
system.does_international_transfers Non-AI Does international transfers

Also, it updates the label "Privacy declaration" to "Data uses" after product feedback.

Code Changes

  • Added formatFieldName(raw: string): string to clients/admin-ui/src/features/common/utils.ts
  • Removed unused FIELD_NAME_LABELS constant from clients/admin-ui/src/features/privacy-assessments/constants.ts
  • Updated EvidenceCardGroup.tsx to use formatFieldName
  • Updated filterEvidence in clients/admin-ui/src/features/privacy-assessments/utils.ts to use formatFieldName

Steps to Confirm

  1. Enable alpha flag for assessments
  2. Navigate to an assessment detail page that has evidence items (nightly be appears to be outdated, better to test locally)
  3. Verify that field name labels render as human-readable sentence-cased strings (e.g. "Legal basis for processing", "Data categories")
  4. Use the evidence search/filter and confirm it matches against the displayed label text

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • No UX review needed
  • Followup issues:
    • No followup issues
  • Database migrations:
    • No migrations
  • Documentation:
    • No documentation updates required

Summary by CodeRabbit

  • Improvements
    • Evidence field names now display in human-readable format with proper spacing and capitalization
    • Updated source type label for privacy declarations to "Data uses"

@vercel
Copy link
Contributor

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fides-plus-nightly Ready Ready Preview, Comment Mar 10, 2026 3:29am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
fides-privacy-center Ignored Ignored Mar 10, 2026 3:29am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

This refactoring replaces a static FIELD_NAME_LABELS lookup map with a new formatFieldName utility function for dynamically converting evidence field names to human-readable labels. The function derives leaf segment names, replaces underscores with spaces, and applies sentence casing. A source type label is also updated from "Privacy declaration" to "Data uses."

Changes

Cohort / File(s) Summary
New Field Name Formatting Utility
clients/admin-ui/src/features/common/utils.ts
Added formatFieldName(raw: string) function that converts evidence field names to human-readable labels by extracting the leaf segment, replacing underscores with spaces, and applying sentence casing.
Privacy Assessments Integration
clients/admin-ui/src/features/privacy-assessments/EvidenceCardGroup.tsx, clients/admin-ui/src/features/privacy-assessments/utils.ts
Replaced FIELD_NAME_LABELS import with formatFieldName utility function. Updated field name rendering to use the new formatting function instead of static label lookup.
Constants Cleanup
clients/admin-ui/src/features/privacy-assessments/constants.ts
Removed FIELD_NAME_LABELS constant entirely. Updated SOURCE_TYPE_LABELS entry for privacy_declaration from "Privacy declaration" to "Data uses".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Assessments evidence tray #7560 - Main PR refactoring field-name labeling by replacing the FIELD_NAME_LABELS lookup with a new formatFieldName utility, directly touching the same constants, utils, and EvidenceCardGroup code.

Suggested reviewers

  • kruulik

Poem

🐰 A humble rabbit hops with glee,
Replacing labels, wild and free!
From static maps to functions bright,
Field names dance in formatted light

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Better label format for evidence tray' accurately summarizes the main change—improving how field name labels are formatted and displayed for evidence items in the assessment detail view.
Description check ✅ Passed The PR description is comprehensive and well-structured, including ticket reference, clear explanation of the problem and solution, code changes, testing steps, and a completed pre-merge checklist with appropriate justifications for skipped items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ENG-2748-UI-Evidence-tray-label-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

@lucanovera lucanovera marked this pull request as ready for review March 10, 2026 03:39
@lucanovera lucanovera requested a review from a team as a code owner March 10, 2026 03:39
@lucanovera lucanovera requested review from kruulik and speaker-ender and removed request for a team and speaker-ender March 10, 2026 03:39
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 10, 2026

Greptile Summary

This PR introduces a small formatFieldName utility that normalizes the two different field_name formats emitted by the backend (bare key vs. dotted path) into human-readable, sentence-cased labels, and wires it into both the evidence card display and the evidence filter search. It also removes the now-unnecessary static FIELD_NAME_LABELS map and renames the privacy_declaration source-type label to "Data uses".

  • New formatFieldName(raw) in common/utils.ts: strips the dotted prefix, replaces underscores with spaces, and applies the existing sentenceCase helper — handles all known formats and degrades gracefully for future/unseen values.
  • EvidenceCardGroup.tsx and filterEvidence both updated to use formatFieldName, keeping display and search logic consistent.
  • Stale FIELD_NAME_LABELS constant cleanly removed from constants.ts.
  • SOURCE_TYPE_LABELS updated: privacy_declaration → "Data uses".

Confidence Score: 5/5

  • This PR is safe to merge — all changes are additive, well-scoped UI label improvements with no backend or data-model impact.
  • The change is small (4 files, ~30 net lines), the new utility delegates entirely to existing helpers (sentenceCase, String.prototype.split), the non-null assertion on pop() is provably safe given the includes(".") guard, and both call sites are updated consistently. No new dependencies, no migrations, and no behaviour change outside of label rendering.
  • No files require special attention.

Last reviewed commit: 5e5b6d7

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
clients/admin-ui/src/features/common/utils.ts (1)

319-332: Add a small test matrix for formatFieldName.

This helper now drives both evidence rendering and filtering, so a few focused cases for bare keys and dotted paths would make future label changes much safer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@clients/admin-ui/src/features/common/utils.ts` around lines 319 - 332, Add a
small unit test suite for the formatFieldName function that verifies behavior
for bare keys and dotted paths: test that "legal_basis" → "Legal basis",
"privacy_declaration.legal_basis" → "Legal basis", a multi-segment path like
"a.b.c_field" → "C field", and that multiple underscores are converted
("user_full_name" → "User full name"); import formatFieldName and assert exact
output strings to catch regressions in label rendering and filtering.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@clients/admin-ui/src/features/common/utils.ts`:
- Around line 319-332: Add a small unit test suite for the formatFieldName
function that verifies behavior for bare keys and dotted paths: test that
"legal_basis" → "Legal basis", "privacy_declaration.legal_basis" → "Legal
basis", a multi-segment path like "a.b.c_field" → "C field", and that multiple
underscores are converted ("user_full_name" → "User full name"); import
formatFieldName and assert exact output strings to catch regressions in label
rendering and filtering.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d391e464-0659-4ea9-bcf8-3bafc784bee4

📥 Commits

Reviewing files that changed from the base of the PR and between 9d24a80 and 5e5b6d7.

📒 Files selected for processing (4)
  • clients/admin-ui/src/features/common/utils.ts
  • clients/admin-ui/src/features/privacy-assessments/EvidenceCardGroup.tsx
  • clients/admin-ui/src/features/privacy-assessments/constants.ts
  • clients/admin-ui/src/features/privacy-assessments/utils.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant