Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split page layout component into two functions, simplifying testing #639

Merged
merged 43 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
17dd08e
chore: export NavbarProps
hollandjg Oct 11, 2023
d99e81e
fix: allow pages to be null
hollandjg Oct 11, 2023
64fa32e
test: add examples of empty data for Navbar
hollandjg Oct 11, 2023
0a0f4d8
refactor: Footer – allow heading to be null
hollandjg Oct 11, 2023
10015dc
refactor: Footer – allow copyright and links to be null
hollandjg Oct 11, 2023
f52524b
fix: allow image to be null
hollandjg Oct 11, 2023
713d298
test: Footer – add examples of nulls in Footer
hollandjg Oct 11, 2023
45dedb7
test: BottomBanner – add examples of nulls
hollandjg Oct 11, 2023
e55802c
test: BottomBanner – add examples of no arguments
hollandjg Oct 11, 2023
22d112d
test: Footer – add examples of no arguments
hollandjg Oct 11, 2023
010db4a
test: Navbar – add examples of no arguments
hollandjg Oct 11, 2023
a08f887
refactor: add new component PageLayoutNested with examples
hollandjg Oct 11, 2023
b5c465f
refactor: use new PageLayoutNested in Layout component, adding new tests
hollandjg Oct 11, 2023
82bb165
refactor: add navbar to statictexttype
hollandjg Oct 11, 2023
3823769
refactor: reorder title imports in Layout
hollandjg Oct 11, 2023
ed3fd7e
refactor: make siteTitle accept nulls
hollandjg Oct 11, 2023
ae932e4
refactor: Navbar – allow title to be null
hollandjg Oct 11, 2023
6e512cb
refactor: rename PageLayout from PageLayoutNested
hollandjg Oct 11, 2023
c3764b7
fix: siteTitle import
hollandjg Oct 11, 2023
2293225
refactor: allow path to be null
hollandjg Oct 11, 2023
f41afd0
chore: removed unused Link
hollandjg Oct 11, 2023
d5545f9
chore: fix image resolution check
hollandjg Oct 11, 2023
3c3ee63
chore: export PageLayout
hollandjg Oct 11, 2023
11110b9
test: add new empty examples for SiteTitle
hollandjg Oct 11, 2023
96cbb6d
test: fix import of contactImage
hollandjg Oct 11, 2023
d5a772d
Merge branch 'refactor/remove-project-portal-config-node-replace-site…
hollandjg Oct 11, 2023
122bb31
Merge branch 'refactor/remove-project-portal-config-node-replace-site…
hollandjg Oct 20, 2023
6b9a8cf
Merge branch 'refactor/remove-project-portal-config-node-replace-site…
hollandjg Oct 20, 2023
5163342
Merge branch 'main' into refactor/simplify-page-layout-components
hollandjg Oct 31, 2023
c4733d3
Merge branch 'main' into refactor/simplify-page-layout-components
hollandjg Oct 31, 2023
ca0e2f7
test: add examples of contact not showing image for XS screens, then …
hollandjg Oct 31, 2023
f765f2b
test: add a navbar test in XL viewport wth no image
hollandjg Oct 31, 2023
36e449f
test: add an example of a navbar with no title
hollandjg Oct 31, 2023
2395765
refactor: delete independent navbarItem
hollandjg Oct 31, 2023
279ef9c
refactor: delete independent SiteTitle
hollandjg Oct 31, 2023
ec2cfe5
fix: positioning of siteTitle if no image present.
hollandjg Oct 31, 2023
50dd518
test: move site title stories bits into Navbar
hollandjg Oct 31, 2023
08ba155
Revert "test: move site title stories bits into Navbar"
hollandjg Oct 31, 2023
83ea305
Revert "fix: positioning of siteTitle if no image present."
hollandjg Oct 31, 2023
b3a0b7f
Revert "refactor: delete independent SiteTitle"
hollandjg Oct 31, 2023
6d87016
Revert "refactor: delete independent navbarItem"
hollandjg Oct 31, 2023
1be7fe9
fix: positioning of siteTitle if no image present.
hollandjg Oct 31, 2023
91e1d0a
Merge branch 'main' into refactor/simplify-page-layout-components
hollandjg Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ export const Primary: Story = {
image: bottomBannerLogo,
},
}

export const Nulls: Story = {
args: {
text: null,
link: null,
linkId: null,
image: null,
},
}

export const NoArgs: Story = {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Link } from "gatsby"
import React, { FunctionComponent } from "react"
import { GatsbyImage, ImageDataLike, getImage } from "gatsby-plugin-image"
import { MarkdownText } from "."
Expand Down Expand Up @@ -32,7 +31,7 @@ export const BottomBanner: FunctionComponent<BottomBannerProps> = ({
/>
</a>
)}
{isNA(link) && { resolvedImage } && (
{isNA(link) && resolvedImage && (
<GatsbyImage
className="inline-block logotype"
image={resolvedImage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ export const NoEmail: Story = {
export const NoImage: Story = {
args: { ...Primary.args, image: null },
}

export const TailwindXSWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindXS" } },
}

export const TailwindSMWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindSM" } },
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,14 @@ export const ThreeLinks: Story = {
],
},
}

export const Nulls: Story = {
args: {
heading: null,
copyright: null,
links: null,
image: null,
},
}

export const NoArgs: Story = {}
16 changes: 8 additions & 8 deletions packages/gatsby-theme-project-portal/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { FunctionComponent } from "react"
import { GatsbyImage, ImageDataLike, getImage } from "gatsby-plugin-image"

export interface FooterProps {
heading: {
heading?: {
title: String
link: string
}
copyright: String
links: {
copyright?: String
links?: {
title: String
link: String
}[]
Expand All @@ -23,15 +23,15 @@ export const Footer: FunctionComponent<FooterProps> = ({
links,
image,
}) => {
const resolvedImage = getImage(image.imageData)
const resolvedImage = getImage(image?.imageData)
return (
<footer className="w-full px-2 py-8 bg-footer xl:container xl:px-12">
<div className="flex items-center justify-center mt-6 lg:my-auto">
<div className="text-nav text-footertext">{copyright}</div>
</div>
<div className="flex items-center justify-center mt-6 lg:my-auto">
<ul className="text-nav text-footertext list-none">
{links.map(({ title, link }, i) => (
{links?.map(({ title, link }, i) => (
<ListItem key={"link_" + i} target={link}>
{title}
</ListItem>
Expand All @@ -41,17 +41,17 @@ export const Footer: FunctionComponent<FooterProps> = ({
<div className="block w-full lg:w-auto mt-5">
<a
className="flex items-center gap-4 justify-center flex-wrap"
href={heading.link}
href={heading?.link}
>
{resolvedImage && (
<GatsbyImage
className="xl:inline-block logotype"
image={resolvedImage}
alt={image.altText}
alt={image?.altText}
/>
)}
<p className="text-center inline-block text-h4 font-bold text-footertext">
{heading.title}
{heading?.title}
</p>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export const NoLogo: Story = {
args: { ...Primary.args, activePage: "Open", image: null },
}

export const NoLogoXL: Story = {
args: { ...Primary.args, activePage: "Open", image: null },
parameters: { viewport: { defaultViewport: "tailwindXL" } },
}

export const NoTitle: Story = {
args: { ...Primary.args, activePage: "Open", title: null },
}

export const TailwindXSWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindXS" } },
Expand Down Expand Up @@ -66,3 +75,23 @@ export const Tailwind2XLWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwind2XL" } },
}

export const EmptyStrings: Story = {
args: {
title: "",
image: SiteTitleStories.siteTitleLogo,
activePage: "",
pages: [],
},
}

export const Nulls: Story = {
args: {
title: null,
image: null,
activePage: null,
pages: null,
},
}

export const NoArgs: Story = {}
10 changes: 5 additions & 5 deletions packages/gatsby-theme-project-portal/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { FaBars, FaTimes } from "react-icons/fa"
import { ImageDataLike } from "gatsby-plugin-image"
import { SiteTitle, NavbarItem } from "."

interface NavbarProps {
title: string
export interface NavbarProps {
title?: string
activePage?: string
image?: ImageDataLike
pages: {
pages?: {
name: string
link: string
show: boolean
Expand Down Expand Up @@ -41,7 +41,7 @@ export const Navbar: FunctionComponent<NavbarProps> = ({
{navbarOpen ? <FaTimes /> : <FaBars />}
</button>
<Link
className="block mx-4 my-3 xl:my-auto overflow-hidden text-nav text-black font-bold flex gap-4 items-center whitespace-nowrap"
className="block xl:min-h-full mx-4 my-3 xl:my-auto overflow-hidden text-nav text-black font-bold flex gap-4 items-center whitespace-nowrap"
to="/"
>
<SiteTitle image={image} title={title} />
Expand All @@ -55,7 +55,7 @@ export const Navbar: FunctionComponent<NavbarProps> = ({
id="example-navbar-danger"
>
<ul className="flex flex-col list-none xl:flex-row xl:ml-auto">
{pages.map(({ name, link, show }, i) =>
{pages?.map(({ name, link, show }, i) =>
show ? (
<Link
key={"nav" + i}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { Meta, StoryObj } from "@storybook/react"
import { PageLayout } from "./PageLayout"
import * as bottomBannerStories from "../components/BottomBanner.stories"
import * as footerStories from "../components/Footer.stories"
import * as navbarStories from "../components/Navbar.stories"

const meta: Meta<typeof PageLayout> = {
component: PageLayout,
tags: ["autodocs"],
}

export default meta

type Story = StoryObj<typeof PageLayout>

export const Primary: Story = {
args: {
devBanner: { show: true },
navbar: navbarStories.Primary.args,
bottomBanner: bottomBannerStories.Primary.args,
footer: footerStories.Primary.args,
},
}

export const TailwindXSWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindXS" } },
}

export const TailwindSMWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindSM" } },
}

export const TailwindMDWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindMD" } },
}

export const TailwindLGWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindLG" } },
}

export const TailwindXLWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindXL" } },
}

export const Tailwind2XLWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwind2XL" } },
}

export const Nulls: Story = {
args: {
devBanner: { show: true },
navbar: navbarStories.Nulls.args,
bottomBanner: bottomBannerStories.Nulls.args,
footer: footerStories.Nulls.args,
},
}

export const NoArgs: Story = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { FunctionComponent, ReactNode } from "react"
import { DevelopmentBanner } from "./DevelopmentBanner"
import { Navbar, NavbarProps } from "./Navbar"
import { BottomBanner, BottomBannerProps } from "./BottomBanner"
import { Footer, FooterProps } from "./Footer"

export interface PageLayoutProps {
children: ReactNode
devBanner?: { show?: boolean }
navbar?: NavbarProps
bottomBanner?: BottomBannerProps
footer?: FooterProps
}

export const PageLayout: FunctionComponent<PageLayoutProps> = ({
children,
devBanner,
navbar,
bottomBanner,
footer,
}) => {
return (
<div className="w-full mx-0 bg-white border-0 xl:container xl:p-0 xl:mx-auto xl:border-l xl:border-r xl:border-gray-200 flex flex-col min-h-screen">
{devBanner?.show && <DevelopmentBanner />}
<Navbar {...navbar} />
<div className="flex-1">{children}</div>
<BottomBanner {...bottomBanner} />
<Footer {...footer} />
</div>
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react"
import { ProjectTeam } from "./ProjectTeam"
import * as ContactStories from "./Contact.stories"
import { contactImage } from "./Story.utilities"

const meta: Meta<typeof ProjectTeam> = {
component: ProjectTeam,
Expand All @@ -16,7 +15,7 @@ export const Primary: Story = {
args: {
title: "The Project Team",
contacts: [ContactStories.Primary.args, ContactStories.NoEmail.args],
defaultImage: contactImage,
defaultImage: ContactStories.contactImage,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Meta, StoryObj } from "@storybook/react"
import { SiteTitle } from "./SiteTitle"

import { loadImage } from "./Story.utilities"
import { IGatsbyImageData } from "gatsby-plugin-image"

const meta: Meta<typeof SiteTitle> = {
component: SiteTitle,
Expand All @@ -22,3 +21,19 @@ export const Primary: Story = {
title: "The Site Title",
},
}

export const Nulls: Story = {
args: {
image: null,
title: null,
},
}

export const EmptyString: Story = {
args: {
image: null,
title: "",
},
}

export const NoArgs: Story = {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { FunctionComponent } from "react"
import { GatsbyImage, getImage, ImageDataLike } from "gatsby-plugin-image"

export interface SiteTitleProps {
image: ImageDataLike
title: string
image?: ImageDataLike
title?: string
}

export const SiteTitle: FunctionComponent<SiteTitleProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export { Topics } from "./Topics"
export { Accordion } from "./Accordion"
export { KeyDate } from "./KeyDate"
export { NavbarItem } from "./NavbarItem"
export { PageLayout } from "./PageLayout"
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ export const Primary: Story = {
data: {
site: {
siteMetadata: {
title: "The Site Title",
showDevBanner: true,
pages: NavbarStories.Primary.args.pages,

staticText: {
navbar: {
title: "The Site Title",
pages: NavbarStories.Primary.args.pages,
},
bottomBanner: BottomBannerStories.Primary.args,
footer: FooterStories.Primary.args,
},
Expand Down Expand Up @@ -70,3 +73,31 @@ export const Tailwind2XLWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwind2XL" } },
}

export const Nulls: Story = {
args: {
data: {
site: {
siteMetadata: {
showDevBanner: null,
staticText: {
navbar: { title: null, pages: [] },
bottomBanner: { text: null, link: null },
footer: {
copyright: null,
heading: { title: null, link: null },
links: [],
},
},
},
},
navbarLogo: null,
bottomBannerLogo: null,
footerLogo: null,
},
path: null,
children: null,
},
}

export const NoArgs: Story = {}
Loading