22541 introduce simple route renderer map for static breadcrumb branches
This commit is contained in:
+27
-48
@@ -113,6 +113,26 @@ const Breadcrumbs = (props) => {
|
||||
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 = () => (
|
||||
<li className="govuk-breadcrumbs__list-item">
|
||||
<Link href={myPortalHref} className="govuk-breadcrumbs__link">
|
||||
@@ -208,11 +228,13 @@ const Breadcrumbs = (props) => {
|
||||
t("common:service-name-breadcrumb")
|
||||
)}
|
||||
|
||||
{isPath("/myportal") && (
|
||||
<li className="govuk-breadcrumbs__list-item">
|
||||
{t("myportal:page-title")}
|
||||
</li>
|
||||
)}
|
||||
{(() => {
|
||||
const renderSimpleRoute =
|
||||
getSimpleRouteRenderer(pathname);
|
||||
return renderSimpleRoute
|
||||
? renderSimpleRoute()
|
||||
: null;
|
||||
})()}
|
||||
{isPath("/myportal/searchresults") && (
|
||||
<>
|
||||
{renderAnchorCrumb(
|
||||
@@ -224,27 +246,6 @@ const Breadcrumbs = (props) => {
|
||||
</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") &&
|
||||
renderMyPortalSectionCrumbs(
|
||||
t("common:breadcrumb-address-search")
|
||||
@@ -257,13 +258,6 @@ const Breadcrumbs = (props) => {
|
||||
renderMyPortalSectionCrumbs(
|
||||
t("common:footer-contact-us-link-label")
|
||||
)}
|
||||
{isPath("/contactus") && (
|
||||
<>
|
||||
{renderTextCrumb(
|
||||
t("common:footer-contact-us-link-label")
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{isPath("/addresssearchresults") && (
|
||||
<>
|
||||
{" "}
|
||||
@@ -384,14 +378,6 @@ const Breadcrumbs = (props) => {
|
||||
</li>
|
||||
</>
|
||||
)}
|
||||
{isPath("/viewall") && (
|
||||
<>
|
||||
{renderMyPortalCrumb()}
|
||||
{renderTextCrumb(
|
||||
t("common:breadcrumb-your-cases")
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{isPath("/myportal/viewall") && (
|
||||
<>
|
||||
{renderMyPortalCrumb()}
|
||||
@@ -489,13 +475,6 @@ const Breadcrumbs = (props) => {
|
||||
{renderCaseReferenceCrumb(caseReferenceDisplay)}
|
||||
</>
|
||||
)}
|
||||
{isPath("/myportal/dnsapplications") && (
|
||||
<>
|
||||
{" "}
|
||||
{renderMyPortalCrumb()}
|
||||
{renderTextCrumb(t("dnsCommon:service-name"))}
|
||||
</>
|
||||
)}
|
||||
{isPath("/myportal/dnsdetails") && (
|
||||
<>
|
||||
{renderMyPortalCrumb()}
|
||||
|
||||
@@ -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.
|
||||
|
||||
### 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
|
||||
|
||||
date: 2026-04-07
|
||||
|
||||
Reference in New Issue
Block a user