22541 introduce simple route renderer map for static breadcrumb branches

This commit is contained in:
2026-04-09 09:54:49 +01:00
parent a8ef55c65a
commit c464fbf13b
2 changed files with 55 additions and 48 deletions
+27 -48
View File
@@ -113,6 +113,26 @@ const Breadcrumbs = (props) => {
return staticTextCrumbByPath[path] || null; return staticTextCrumbByPath[path] || null;
}; };
const getSimpleRouteRenderer = (path) => {
const simpleRouteRenderersByPath = {
"/myportal": () => renderTextCrumb(t("myportal:page-title")),
"/searchresults": () =>
renderTextCrumb(t("common:breadcrumb-search-results")),
"/advancedsearch": () =>
renderTextCrumb(t("common:breadcrumb-advanced-search")),
"/addresssearch": () =>
renderTextCrumb(t("common:breadcrumb-address-search")),
"/contactus": () =>
renderTextCrumb(t("common:footer-contact-us-link-label")),
"/viewall": () =>
renderMyPortalSectionCrumbs(t("common:breadcrumb-your-cases")),
"/myportal/dnsapplications": () =>
renderMyPortalSectionCrumbs(t("dnsCommon:service-name"))
};
return simpleRouteRenderersByPath[path] || null;
};
const renderMyPortalCrumb = () => ( const renderMyPortalCrumb = () => (
<li className="govuk-breadcrumbs__list-item"> <li className="govuk-breadcrumbs__list-item">
<Link href={myPortalHref} className="govuk-breadcrumbs__link"> <Link href={myPortalHref} className="govuk-breadcrumbs__link">
@@ -208,11 +228,13 @@ const Breadcrumbs = (props) => {
t("common:service-name-breadcrumb") t("common:service-name-breadcrumb")
)} )}
{isPath("/myportal") && ( {(() => {
<li className="govuk-breadcrumbs__list-item"> const renderSimpleRoute =
{t("myportal:page-title")} getSimpleRouteRenderer(pathname);
</li> return renderSimpleRoute
)} ? renderSimpleRoute()
: null;
})()}
{isPath("/myportal/searchresults") && ( {isPath("/myportal/searchresults") && (
<> <>
{renderAnchorCrumb( {renderAnchorCrumb(
@@ -224,27 +246,6 @@ const Breadcrumbs = (props) => {
</li> </li>
</> </>
)} )}
{isPath("/searchresults") && (
<>
{renderTextCrumb(
t("common:breadcrumb-search-results")
)}
</>
)}
{isPath("/advancedsearch") && (
<>
{renderTextCrumb(
t("common:breadcrumb-advanced-search")
)}
</>
)}
{isPath("/addresssearch") && (
<>
{renderTextCrumb(
t("common:breadcrumb-address-search")
)}
</>
)}
{isPath("/myportal/addresssearch") && {isPath("/myportal/addresssearch") &&
renderMyPortalSectionCrumbs( renderMyPortalSectionCrumbs(
t("common:breadcrumb-address-search") t("common:breadcrumb-address-search")
@@ -257,13 +258,6 @@ const Breadcrumbs = (props) => {
renderMyPortalSectionCrumbs( renderMyPortalSectionCrumbs(
t("common:footer-contact-us-link-label") t("common:footer-contact-us-link-label")
)} )}
{isPath("/contactus") && (
<>
{renderTextCrumb(
t("common:footer-contact-us-link-label")
)}
</>
)}
{isPath("/addresssearchresults") && ( {isPath("/addresssearchresults") && (
<> <>
{" "} {" "}
@@ -384,14 +378,6 @@ const Breadcrumbs = (props) => {
</li> </li>
</> </>
)} )}
{isPath("/viewall") && (
<>
{renderMyPortalCrumb()}
{renderTextCrumb(
t("common:breadcrumb-your-cases")
)}
</>
)}
{isPath("/myportal/viewall") && ( {isPath("/myportal/viewall") && (
<> <>
{renderMyPortalCrumb()} {renderMyPortalCrumb()}
@@ -489,13 +475,6 @@ const Breadcrumbs = (props) => {
{renderCaseReferenceCrumb(caseReferenceDisplay)} {renderCaseReferenceCrumb(caseReferenceDisplay)}
</> </>
)} )}
{isPath("/myportal/dnsapplications") && (
<>
{" "}
{renderMyPortalCrumb()}
{renderTextCrumb(t("dnsCommon:service-name"))}
</>
)}
{isPath("/myportal/dnsdetails") && ( {isPath("/myportal/dnsdetails") && (
<> <>
{renderMyPortalCrumb()} {renderMyPortalCrumb()}
+28
View File
@@ -333,6 +333,34 @@ Follow-ups:
- Next slice recommendation: extract a small route-to-renderer map for static single-branch crumbs (where branch has no bespoke side-effects) so the main JSX conditional chain shrinks further without altering explicit behavior in dynamic/sensitive branches. - Next slice recommendation: extract a small route-to-renderer map for static single-branch crumbs (where branch has no bespoke side-effects) so the main JSX conditional chain shrinks further without altering explicit behavior in dynamic/sensitive branches.
### CL-22541-L: breadcrumbs simple-route renderer map introduction
date: 2026-04-09
author: Cline
scope: `components/breadcrumbs.js`
type: change
rationale: Continue bounded readability refactor by introducing a small route-to-renderer map for simple static branches, reducing conditional-chain length while preserving explicit dynamic branches.
impact: Refactor-only structural deduplication/readability improvement; no intended route/auth/session/API/EN-CY/a11y behavior change.
status: completed
Summary:
- Added `getSimpleRouteRenderer(path)` in `components/breadcrumbs.js` for simple routes with no bespoke side effects.
- Introduced a single invocation block that resolves and renders mapped simple routes when present.
- Migrated simple route branches into the map, including:
- `/myportal`, `/searchresults`, `/advancedsearch`, `/addresssearch`, `/contactus`
- `/viewall`, `/myportal/dnsapplications`
- Preserved existing label text, helper usage, and rendered crumb sequence semantics.
Validation:
- `npx eslint components/breadcrumbs.js` -> pass.
- `node tests/phase22/index.test.cjs` -> pass (combined suite).
Follow-ups:
- Next slice recommendation: extract a second tiny map for simple "link + text" pair routes (no callbacks, no side effects) to further shrink the conditional chain while keeping callback/dynamic branches explicit.
### 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