22541 consolidate breadcrumb mapped route maps into grouped constants

This commit is contained in:
2026-04-09 10:21:09 +01:00
parent ee3f3eae74
commit 78d62c541f
3 changed files with 148 additions and 119 deletions
+19 -37
View File
@@ -113,7 +113,6 @@ const Breadcrumbs = (props) => {
return staticTextCrumbByPath[path] || null; return staticTextCrumbByPath[path] || null;
}; };
const getSimpleRouteRenderer = (path) => {
const simpleRouteRenderersByPath = { const simpleRouteRenderersByPath = {
"/myportal": () => renderTextCrumb(t("myportal:page-title")), "/myportal": () => renderTextCrumb(t("myportal:page-title")),
"/searchresults": () => "/searchresults": () =>
@@ -130,10 +129,6 @@ const Breadcrumbs = (props) => {
renderMyPortalSectionCrumbs(t("dnsCommon:service-name")) renderMyPortalSectionCrumbs(t("dnsCommon:service-name"))
}; };
return simpleRouteRenderersByPath[path] || null;
};
const getSimpleLinkTextPairRenderer = (path) => {
const simpleLinkTextPairRenderersByPath = { const simpleLinkTextPairRenderersByPath = {
"/addresssearchresults": () => ( "/addresssearchresults": () => (
<> <>
@@ -143,9 +138,7 @@ const Breadcrumbs = (props) => {
: "/addresssearch", : "/addresssearch",
t("common:breadcrumb-address-search") t("common:breadcrumb-address-search")
)} )}
{renderTextCrumb( {renderTextCrumb(t("common:breadcrumb-address-search-results"))}
t("common:breadcrumb-address-search-results")
)}
</> </>
), ),
"/advancedsearchresults": () => ( "/advancedsearchresults": () => (
@@ -163,10 +156,6 @@ const Breadcrumbs = (props) => {
) )
}; };
return simpleLinkTextPairRenderersByPath[path] || null;
};
const getSimpleMyPortalRouteRenderer = (path) => {
const simpleMyPortalRouteRenderersByPath = { const simpleMyPortalRouteRenderersByPath = {
"/myportal/searchresults": () => ( "/myportal/searchresults": () => (
<> <>
@@ -178,22 +167,16 @@ const Breadcrumbs = (props) => {
</> </>
), ),
"/myportal/addresssearch": () => "/myportal/addresssearch": () =>
renderMyPortalSectionCrumbs( renderMyPortalSectionCrumbs(t("common:breadcrumb-address-search")),
t("common:breadcrumb-address-search")
),
"/myportal/advancedsearch": () => "/myportal/advancedsearch": () =>
renderMyPortalSectionCrumbs( renderMyPortalSectionCrumbs(t("common:breadcrumb-advanced-search")),
t("common:breadcrumb-advanced-search")
),
"/myportal/contactus": () => "/myportal/contactus": () =>
renderMyPortalSectionCrumbs( renderMyPortalSectionCrumbs(
t("common:footer-contact-us-link-label") t("common:footer-contact-us-link-label")
), ),
"/myportal/viewall": () => "/myportal/viewall": () =>
renderMyPortalSectionCrumbs( renderMyPortalSectionCrumbs(
getViewAllLabel( getViewAllLabel(currentViewState.viewKey || router.query.key)
currentViewState.viewKey || router.query.key
)
), ),
"/myportal/advancedsearchresults": () => ( "/myportal/advancedsearchresults": () => (
<> <>
@@ -214,31 +197,30 @@ const Breadcrumbs = (props) => {
{renderMyPortalCrumb()} {renderMyPortalCrumb()}
{renderLinkCrumb( {renderLinkCrumb(
isWelsh isWelsh
? "/" + ? "/" + router.locale + "/fymhorth/chwiliadcyfeiriadau"
router.locale +
"/fymhorth/chwiliadcyfeiriadau"
: "/myportal/addresssearch", : "/myportal/addresssearch",
t("common:breadcrumb-address-search") t("common:breadcrumb-address-search")
)} )}
{renderTextCrumb( {renderTextCrumb(t("common:breadcrumb-address-search-results"))}
t("common:breadcrumb-address-search-results")
)}
</> </>
) )
}; };
return simpleMyPortalRouteRenderersByPath[path] || null; const mappedRouteRendererMaps = [
}; simpleRouteRenderersByPath,
simpleLinkTextPairRenderersByPath,
const resolveMappedRouteRenderer = (path) => { simpleMyPortalRouteRenderersByPath
const mappedResolvers = [
getSimpleRouteRenderer,
getSimpleLinkTextPairRenderer,
getSimpleMyPortalRouteRenderer
]; ];
for (const resolveRenderer of mappedResolvers) { const getMappedRendererByPath = (path, routeRendererMap) =>
const routeRenderer = resolveRenderer(path); routeRendererMap[path] || null;
const resolveMappedRouteRenderer = (path) => {
for (const routeRendererMap of mappedRouteRendererMaps) {
const routeRenderer = getMappedRendererByPath(
path,
routeRendererMap
);
if (routeRenderer) { if (routeRenderer) {
return routeRenderer; return routeRenderer;
} }
+33
View File
@@ -459,6 +459,39 @@ Follow-ups:
- Next wider slice candidate: split map resolver sections into clearly named grouped constants (simple/public/myportal) near one composition point, then optionally move map-only route renderers to a local pure helper module if continued growth impacts scanability. - Next wider slice candidate: split map resolver sections into clearly named grouped constants (simple/public/myportal) near one composition point, then optionally move map-only route renderers to a local pure helper module if continued growth impacts scanability.
### CL-22541-P: breadcrumbs grouped route-map constants + unified map composition point
date: 2026-04-09
author: Cline
scope: `components/breadcrumbs.js`, `tests/phase22/breadcrumbs-route-map-structure.test.cjs`
type: change
rationale: Execute the next wider slice by replacing per-group resolver functions with grouped route-map constants and a single composition array to further improve scanability while preserving route precedence semantics.
impact: Refactor-only structural readability improvement; no intended route/auth/session/API/EN-CY/a11y behavior change.
status: completed
Summary:
- Replaced function-based map accessors with grouped route-map constants in `components/breadcrumbs.js`:
- `simpleRouteRenderersByPath`
- `simpleLinkTextPairRenderersByPath`
- `simpleMyPortalRouteRenderersByPath`
- Added unified map composition point:
- `mappedRouteRendererMaps` (ordered array preserving precedence)
- `getMappedRendererByPath(path, routeRendererMap)` helper
- Updated `resolveMappedRouteRenderer(path)` to iterate the composed map list while retaining previous resolution order and behavior.
- Kept dynamic/callback branches explicit and unchanged outside map-driven paths.
- Expanded structure tests to assert grouped map composition contracts (`mappedRouteRendererMaps`, `getMappedRendererByPath`) in addition to existing resolver and invocation guardrails.
Validation:
- `npx eslint components/breadcrumbs.js tests/phase22/breadcrumbs-route-map-structure.test.cjs tests/phase22/index.test.cjs` -> pass.
- `node tests/phase22/index.test.cjs` -> pass (combined suite; breadcrumbs-route-map tests 3/3).
Follow-ups:
- Next slice option A (larger): extract map constants + resolver helpers into a local `lib/routing/breadcrumbRouteMaps.js` pure module with focused tests, keeping callback/stateful branch rendering in component.
- Next slice option B (smaller): expand structure tests to assert explicit map ordering invariants so future reordering regressions are caught early.
### CL-00X: 22500 `components/elements/index.js` Phase 1 helper extraction ### CL-00X: 22500 `components/elements/index.js` Phase 1 helper extraction
date: 2026-04-07 date: 2026-04-07
@@ -59,6 +59,20 @@ test("breadcrumbs/simple-link-text map includes address and advanced search resu
test("breadcrumbs/merged resolver renders mapped routes through single helper invocation", async () => { test("breadcrumbs/merged resolver renders mapped routes through single helper invocation", async () => {
const source = loadBreadcrumbSource(); const source = loadBreadcrumbSource();
assert.strictEqual(
source.includes("const mappedRouteRendererMaps = ["),
true,
"Expected grouped mapped route renderer map composition to exist"
);
assert.strictEqual(
source.includes(
"const getMappedRendererByPath = (path, routeRendererMap) =>"
),
true,
"Expected shared mapped renderer lookup helper to exist"
);
assert.strictEqual( assert.strictEqual(
source.includes("const resolveMappedRouteRenderer = (path) =>"), source.includes("const resolveMappedRouteRenderer = (path) =>"),
true, true,