Fixes #39340 - PageLayout accept JSX to title prop#10992
Conversation
|
This seems to work similarly to I think we should think how to unite them a bit better so we dont fix issues in only one of our templates |
241f797 to
cd90e4c
Compare
cd90e4c to
2f67677
Compare
2f67677 to
f79816b
Compare
fd7afdc to
eaeba28
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors PageLayout to better support non-primitive headings and expands regression coverage, while also reusing PageLayout inside TableIndexPage to reduce duplicated page-structure code.
Changes:
- Updated
PageLayoutto introducecustomHeader,customToolbar, wrapper/className customization, and safer<title>handling. - Expanded
PageLayouttests to cover breadcrumbs viabreadcrumbOptions, custom header rendering, and additional layout slots. - Refactored
TableIndexPageto render viaPageLayout(moving title/breadcrumb/toolbar structure responsibility intoPageLayout).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| webpack/assets/javascripts/react_app/routes/common/PageLayout/PageLayout.js | Adds new layout customization props and adjusts title/header rendering logic. |
| webpack/assets/javascripts/react_app/routes/common/PageLayout/PageLayout.test.js | Adds test coverage for new PageLayout behaviors and slots. |
| webpack/assets/javascripts/react_app/routes/Audits/AuditsPage/tests/snapshots/AuditsPage.test.js.snap | Updates snapshots to reflect new PageLayout props/defaults. |
| webpack/assets/javascripts/react_app/components/PF4/TableIndexPage/TableIndexPage.js | Replaces bespoke page chrome with PageLayout usage and a custom toolbar. |
Comments suppressed due to low confidence (2)
webpack/assets/javascripts/react_app/routes/common/PageLayout/PageLayout.js:76
- The
<title>is now forced to''wheneverheaderis not a string/number (or when onlycustomHeaderis provided), which can silently clear the browser tab title. The PR description mentions falling back to an explicitdocumentTitle—that prop isn’t implemented here, so consider adding it and using it as the<title>source whenheaderis a React node.
<Head>
<title>{titleForHead}</title>
</Head>
webpack/assets/javascripts/react_app/routes/common/PageLayout/PageLayout.js:205
headeris typed asPropTypes.string, but the implementation explicitly supports numbers (typeof header === 'number') and the PR intent is to allow JSX/ReactNode headings. Update the prop type to reflect the supported inputs (e.g., string/number/node) to avoid misleading warnings and to document the intended API.
toolbarButtons: PropTypes.node,
customToolbar: PropTypes.node,
header: PropTypes.string,
customHeader: PropTypes.node,
headerTitleOuiaId: PropTypes.string,
alwaysShowStandaloneTitleSection: PropTypes.bool,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d0e5e9c to
0311bb4
Compare
0311bb4 to
e940cad
Compare
e940cad to
6ebbbbc
Compare
| toolbarSpinnerSize, | ||
| pageSectionType, | ||
| outerWrapperId, | ||
| titleSectionClassName, | ||
| toolbarSectionClassName, | ||
| contentSectionClassName, |
There was a problem hiding this comment.
toolbarSpinnerSize is used to customize the size of the spinner loader
outerWrapperId - this is used for scoping the css from TableIndexPage.
The rest were added if further customization is needed for the layout section.
There was a problem hiding this comment.
We do not want to customize those, please remove them
| const titleSectionBody = customHeader ?? ( | ||
| <TextContent> | ||
| <Text ouiaId="breadcrumb_title" component="h1"> | ||
| <Text ouiaId={headerTitleOuiaId} component="h1"> |
| <div id="breadcrumb"> | ||
| {customBreadcrumbs || | ||
| (breadcrumbOptions && <BreadcrumbBar {...breadcrumbOptions} />)} | ||
| </div> | ||
| </PageSection> | ||
| )} | ||
|
|
||
| {(searchable || !toolbarButtons) && ( | ||
| <PageSection variant={PageSectionVariants.light} type="breadcrumb"> | ||
| <div id="breadcrumb">{title}</div> | ||
| {showStandaloneTitleSection && ( | ||
| <PageSection | ||
| variant={PageSectionVariants.light} | ||
| type="breadcrumb" | ||
| className={titleSectionClassName || undefined} | ||
| > | ||
| <div id="breadcrumb">{titleSectionBody}</div> |
There was a problem hiding this comment.
this duplicates id="breadcrumb">
|
|
||
| return ( | ||
| <PageLayout | ||
| outerWrapperId="foreman-page" |
There was a problem hiding this comment.
This should apply to pagelayout always, not only under the title
| toolbarSpinnerSize, | ||
| pageSectionType, | ||
| outerWrapperId, | ||
| titleSectionClassName, | ||
| toolbarSectionClassName, | ||
| contentSectionClassName, |
There was a problem hiding this comment.
We do not want to customize those, please remove them
Summary
Improves PageLayout reliability and regression coverage:
header(PropTypes.stringmust not be invoked), which prevented the test file from importing the component.<title>/ react-helmet safe whenheaderis not a primitive: document title uses optionaldocumentTitle, otherwise the string or number form ofheader; avoids passing a React tree into<title>.PageLayouttests forbreadcrumbOptions,beforeToolbarComponent, andheaderas a React component (composite heading inside the PFh1).Prerequisites for testing
enginesinpackage.jsonnpm installas usual)No extra Foreman infra (proxies, compute, DB fixtures beyond normal dev).
Test plan
npm test -- --testPathPattern=PageLayout.test.jsPageLayoutwith stringheader— heading and browser title unchanged from before.If anything uses
headeras a React node, optionally verifydocumentTitlesets the intended tab/window title when needed.