From cdc4d442b0b1152fdf624de03749496a6f5c99e0 Mon Sep 17 00:00:00 2001 From: Richard Pentecost Date: Tue, 23 Jan 2024 11:36:07 +0000 Subject: [PATCH 1/2] change project details to render the layout before loading the resource, create new layout and layout header for investments --- .../InvestmentLocalHeader/index.jsx | 161 +++++ .../InvestmentProjectLocalHeader/index.jsx | 6 +- .../components/Layout/InvestmentLayout.jsx | 70 ++ .../components/Layout/ProjectLayoutNew.jsx | 176 +++++ src/client/components/Resource/Resource.jsx | 4 +- src/client/components/index.jsx | 2 + .../Projects/Details/ProjectDetails.jsx | 647 +++++++++--------- 7 files changed, 744 insertions(+), 322 deletions(-) create mode 100644 src/client/components/InvestmentLocalHeader/index.jsx create mode 100644 src/client/components/Layout/InvestmentLayout.jsx create mode 100644 src/client/components/Layout/ProjectLayoutNew.jsx diff --git a/src/client/components/InvestmentLocalHeader/index.jsx b/src/client/components/InvestmentLocalHeader/index.jsx new file mode 100644 index 00000000000..71ab7e509b6 --- /dev/null +++ b/src/client/components/InvestmentLocalHeader/index.jsx @@ -0,0 +1,161 @@ +import React, { Children, Fragment, cloneElement } from 'react' +import PropTypes from 'prop-types' +import styled from 'styled-components' +import { SPACING } from '@govuk-react/constants' +import Main from '@govuk-react/main' +import Breadcrumbs from '@govuk-react/breadcrumbs' +import { Link } from 'react-router-dom' + +import { GREY_4 } from '../../../client/utils/colours' +import LocalHeaderHeading from '../LocalHeader/LocalHeaderHeading' +import FlashMessages from '../LocalHeader/FlashMessages' +import { InvestmentResource } from '../Resource' +import urls from '../../../lib/urls' + +// Using
as there is already a
on the page +// role="region" gives the element significance as a landmark +const StyledHeader = styled('div')` + padding-bottom: ${SPACING.SCALE_5}; + background-color: ${GREY_4}; + padding-top: ${SPACING.SCALE_3}; +` + +const StyledMain = styled(Main)` + padding-top: 0; +` + +const BreadcrumbsWrapper = styled(Breadcrumbs)` + margin-bottom: ${SPACING.SCALE_5}; + margin-top: 0; +` + +const StyledLink = styled('a')({ + fontSize: 20, + display: 'inline-block', + fontFamily: 'Arial, sans-serif', + marginTop: 8, + marginBottom: 8, +}) + +/** + * The generic local header component. + */ +const InvestmentLocalHeader = ({ + breadcrumbs, + flashMessages, + projectId, + children, + useReactRouter = false, +}) => { + const renderChildren = (project) => { + return Children.map(children, (child) => { + return cloneElement(child, { + investment: project, + }) + }) + } + + return ( + + + + {breadcrumbs?.map((breadcrumb) => + breadcrumb.link ? ( + useReactRouter && breadcrumb.text !== 'Home' ? ( + + {breadcrumb.text} + + ) : ( + + {breadcrumb.text} + + ) + ) : ( + {breadcrumb.text} + ) + )} + + + + {(project) => ( + <> + + {project.investorCompany.name} + + + {project.name} + + {renderChildren(project)} + + )} + + + + ) +} + +InvestmentLocalHeader.propTypes = { + /** + * Contains the breadcrumbs + */ + breadcrumbs: PropTypes.arrayOf( + PropTypes.shape({ + link: PropTypes.string, + text: PropTypes.oneOfType([PropTypes.string, PropTypes.element]) + .isRequired, + }) + ), + /** + * Contains the flash messages + */ + flashMessages: PropTypes.shape({ + type: PropTypes.oneOfType([ + PropTypes.arrayOf( + PropTypes.shape({ + body: PropTypes.string.isRequired, + heading: PropTypes.string.isRequired, + id: PropTypes.string, + }) + ), + PropTypes.arrayOf(PropTypes.string).isRequired, + ]), + }), + /** + * Contains the heading text to be displayed + */ + heading: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), + + /** + * Contains the subheading text to be displayed + */ + subheading: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), + /** + * Contains a link that appears above the heading + */ + headingLink: PropTypes.shape({ + url: PropTypes.string.isRequired, + text: PropTypes.string.isRequired, + }), + /** + * Contains an item that renders above the heading (in the same position as the headingLink) + */ + superheading: PropTypes.node, + /** + * Contains an item that renders below the heading + */ + children: PropTypes.node, +} + +export default InvestmentLocalHeader diff --git a/src/client/components/InvestmentProjectLocalHeader/index.jsx b/src/client/components/InvestmentProjectLocalHeader/index.jsx index c8dc4514d79..b527f0f73a9 100644 --- a/src/client/components/InvestmentProjectLocalHeader/index.jsx +++ b/src/client/components/InvestmentProjectLocalHeader/index.jsx @@ -79,11 +79,11 @@ const InvestmentProjectLocalHeader = ({ investment }) => ( {formatMediumDateTime(investment.createdOn)} - {investment.createdBy?.ditTeam?.name && ( + {investment.createdBy?.ditTeam?.name ? ( {investment.createdBy.ditTeam.name} - )} + ) : null} { + const [showVerticalNav, setShowVerticalNav] = useState(false) + useEffect(() => { + document.title = `${pageTitle} - DBT Data Hub` + }, [pageTitle]) + return ( + <> + + + + {localHeaderChildren} + +
+ + {children} + +
+