22500 Phase 1: extract pure helpers from elements index

This commit is contained in:
2026-04-07 09:34:50 +01:00
parent 02512ec403
commit 06b7855826
5 changed files with 252 additions and 174 deletions
+34
View File
@@ -18,6 +18,40 @@ Follow-ups:
---
### CL-00X: 22500 `components/elements/index.js` Phase 1 helper extraction
date: 2026-04-07
author: Cline
scope: `components/elements/index.js`, `components/elements/helpers/fileUploadHelpers.js`, `components/elements/helpers/translationHelpers.js`, `memory-bank/refactor-backlog.md`
type: change
rationale: Execute Phase 1 of the approved `components/elements/index.js` decomposition plan by extracting pure helper logic only, reducing monolith coupling while preserving UI/component behavior.
impact: No route/API contract changes; refactor-only extraction of translation/file-upload helper functions with expected behavior parity for EN/CY field labels, file naming, thumbnail icon mapping, and filename validation.
status: completed
Summary:
- Created work branch from `origin/SIPS-Development`: `22500-elements-index-phase1`.
- Added helper modules:
- `components/elements/helpers/fileUploadHelpers.js`
- `getThumbnailIconByMimeType`
- `getDocumentTypePrefix`
- `validateUploadFilename`
- `components/elements/helpers/translationHelpers.js`
- `getFieldTranslation`
- `getPickListTranslation`
- Updated `components/elements/index.js` to consume these helpers and removed duplicated inline helper implementations.
- Kept field renderer/component placement and external prop contracts unchanged (Phase 1 non-goals respected).
- Updated `memory-bank/refactor-backlog.md` with a phased Priority 6 track and Phase 1 guardrail-aligned acceptance criteria.
Validation:
- `npx eslint components/elements/index.js components/elements/helpers/fileUploadHelpers.js components/elements/helpers/translationHelpers.js` -> pass
Follow-ups:
- Phase 2: extract low-risk leaf field renderer components from `components/elements/index.js` in bounded slices.
- Perform manual EN/CY + a11y smoke matrix on new appeal/myportal form journeys before merge.
### CL-001: TASK22211 endpoint search-document contract consistency slice
date: 2026-03-23
+53
View File
@@ -65,6 +65,59 @@ Last updated: 2026-03-12
3. hash utility behavior
4. locale rewrite mapping sanity checks
## Priority 6 — Decompose `components/elements/index.js` monolith (phased)
- **Problem:** `components/elements/index.js` has grown into a high-coupling UI monolith (~2700+ LOC) combining field primitives, validation/conditional logic, translation helpers, file-upload orchestration, and field-array behavior.
- **Why it matters:** Very high regression surface for new appeal/my portal forms, slower change velocity, and poor testability/isolation.
- **Target outcome:** `components/elements/index.js` reduced to a thin barrel export with responsibility split into focused modules.
- **Context alignment:** Matches architecture direction in `context/architecture.md` (endpoint/component sprawl reduction, bounded slices) and file boundary guidance in `context/coding-conventions.md` (`pages` thin, reusable logic/components split by concern).
- **Guardrail constraints:**
- Preserve public-service reliability for core flows (`search`, `case`, `myportal`, `newappeal`).
- No auth/session/security header behavior changes (out of scope).
- Maintain EN/CY parity for user-facing behavior.
- Keep accessibility behavior unchanged (labels, focus, keyboard flow, errors).
### Priority 6 — Phase 1 (start here): extract pure helpers only
- **Scope (Phase 1 only):**
- Move pure/helper logic from `components/elements/index.js` into focused helper modules under `components/elements/` (or `components/elements/helpers/`) without behavior change.
- Candidate helper extraction set:
- translation helpers (`FieldsTranslations`, picklist translation helper)
- file upload helper utilities (icon/doc type naming/pure format helpers)
- other deterministic pure functions used by field renderers
- Keep all field renderers/components in place for Phase 1.
- **Non-goals (Phase 1):**
- No JSX component relocation yet.
- No upload flow logic rewrites.
- No validation rule behavior changes.
- No prop contract changes for existing consumers.
- **Acceptance criteria (Phase 1):**
- `components/elements/index.js` imports extracted helpers from new helper modules and behavior remains equivalent.
- No route/API changes.
- Existing new appeal + myportal form journeys continue to function in EN and CY.
- Accessibility smoke unchanged for touched form controls (label association, keyboard reachability, inline error visibility).
- Lint passes for touched files.
- **Validation matrix (minimum):**
1. `npm run lint`
2. Manual smoke:
- new appeal form step rendering + validation messages
- myportal representation/new appeal editing flow controls
- file upload field icon/name behavior unchanged
3. Locale parity checks (EN/CY) for touched user-facing labels/routes.
4. A11y smoke checks on touched fields (focus, labels, errors).
- **Rollback plan (Phase 1):**
- Revert helper module extraction commit(s) to restore single-file implementation.
- No migration/data rollback required.
- **Next phases (for tracking):**
- **Phase 2:** extract low-risk leaf field renderer components.
- **Phase 3:** extract `RenderFileUpload` and upload container.
- **Phase 4:** extract field-array/repeater components.
- **Phase 5:** finalize `components/elements/index.js` as barrel-only export.
## Sequencing recommendation
1. Priorities 2 + 4 (security/integrity foundation)