Skip to content

Commit b5f92ff

Browse files
authored
Core 899 add option to remove give button from landing page (#2727)
* Add option, remove links around images Tests * Prettier * Get showGive value from landing page data
1 parent 51a4c0a commit b5f92ff

File tree

4 files changed

+98
-48
lines changed

4 files changed

+98
-48
lines changed

src/app/layouts/landing/header/header.scss

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
width: auto;
1616
}
1717

18-
menu {
18+
menu,
19+
.pseudo-menu {
1920
overflow: hidden;
2021
height: 8rem;
2122
margin: 0;
@@ -25,7 +26,8 @@
2526
letter-spacing: -0.072rem;
2627
line-height: 2.5rem;
2728

28-
li {
29+
li,
30+
> img {
2931
display: inline-block;
3032
height: 100%;
3133
margin: 0 1rem;
@@ -60,7 +62,8 @@
6062
}
6163

6264
@include width-up-to($tablet-max) {
63-
menu {
65+
menu,
66+
.pseudo-menu {
6467
width: 100%;
6568
}
6669
menu li {

src/app/layouts/landing/header/header.tsx

+42-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
import React from 'react';
22
import useOptimizedImage from '~/helpers/use-optimized-image';
3-
import { LinkFields, Link } from '../../../pages/flex-page/components/Link';
3+
import {LinkFields, Link} from '../../../pages/flex-page/components/Link';
44
import './header.scss';
55

6-
export default function Header({links}: {links: LinkFields[]}) {
7-
const riceLogo = useOptimizedImage('https://openstax.org/dist/images/rice.webp', 150);
6+
export default function Header({
7+
links,
8+
showGive = true
9+
}: {
10+
links: LinkFields[];
11+
showGive?: boolean;
12+
}) {
13+
const riceLogo = useOptimizedImage(
14+
'https://openstax.org/dist/images/rice.webp',
15+
150
16+
);
817

918
return (
1019
<div className="container" data-analytics-label="Header">
20+
<div className="pseudo-menu">
21+
<img
22+
src="/dist/images/logo.svg"
23+
alt="OpenStax logo"
24+
width="354"
25+
height="81"
26+
/>
27+
<img
28+
src={riceLogo}
29+
alt="Rice University logo"
30+
height="57"
31+
width="150"
32+
/>
33+
</div>
1134
<menu data-analytics-nav="Landing Menu">
12-
<li>
13-
<a href="/" aria-label="Home Page" data-analytics-link>
14-
<img src="/dist/images/logo.svg" alt="OpenStax logo" width="354" height="81" />
15-
</a>
16-
</li>
17-
<li>
18-
<a href="http://www.rice.edu">
19-
<img src={riceLogo} alt="Rice University logo" height="57" width="150" />
20-
</a>
21-
</li>
22-
</menu>
23-
<menu data-analytics-nav="Landing Menu">
24-
{links.map((link, i) => <li key={i}><Link link={link} /></li>)}
25-
<li>
26-
<a href="/give" className="give-button" data-analytics-link>Give</a>
27-
</li>
35+
{links.map((link, i) => (
36+
<li key={i}>
37+
<Link link={link} />
38+
</li>
39+
))}
40+
{showGive && (
41+
<li>
42+
<a
43+
href="/give"
44+
className="give-button"
45+
data-analytics-link
46+
>
47+
Give
48+
</a>
49+
</li>
50+
)}
2851
</menu>
2952
</div>
3053
);

src/app/layouts/landing/landing.tsx

+16-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useMainClassContext, {
88
import useLanguageContext from '~/contexts/language';
99
import ReactModal from 'react-modal';
1010
import cn from 'classnames';
11-
import { LinkFields } from '../../pages/flex-page/components/Link';
11+
import {LinkFields} from '../../pages/flex-page/components/Link';
1212
import './landing.scss';
1313

1414
type Props = {
@@ -17,18 +17,26 @@ type Props = {
1717
layout: Array<{
1818
value: {
1919
navLinks: LinkFields[];
20-
}
21-
}>
22-
}
23-
}
20+
showGive?: boolean;
21+
};
22+
}>;
23+
};
24+
};
2425

25-
export default function LandingLayout({children, data}: React.PropsWithChildren<Props>) {
26-
// BrowserRouter has to include everything that uses useLocation
26+
export default function LandingLayout({
27+
children,
28+
data
29+
}: React.PropsWithChildren<Props>) {
30+
const showGive = data.layout[0]?.value.showGive;
2731

32+
// BrowserRouter has to include everything that uses useLocation
2833
return (
2934
<React.Fragment>
3035
<header className="landing-page-header">
31-
<Header links={data.layout[0]?.value.navLinks ?? []} />
36+
<Header
37+
links={data.layout[0]?.value.navLinks ?? []}
38+
showGive={showGive}
39+
/>
3240
</header>
3341
<SalesforceContextProvider>
3442
<MainClassContextProvider>

test/src/layouts/layouts.test.tsx

+34-18
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,46 @@ import {describe, it} from '@jest/globals';
44
import { MemoryRouter } from 'react-router-dom';
55
import LandingLayout from '~/layouts/landing/landing';
66

7+
// @ts-expect-error does not exist on
8+
const {routerFuture} = global;
9+
10+
type Layout = Parameters<typeof LandingLayout>[0]['data']['layout'];
11+
712
describe('layouts/landing', () => {
8-
const data: Parameters<typeof LandingLayout>[0]['data'] = {
9-
title: 'the-title',
10-
layout: []
11-
};
13+
function Component({layout}: {layout: Layout}) {
14+
const data: Parameters<typeof LandingLayout>[0]['data'] = {
15+
title: 'the-title',
16+
layout
17+
};
1218

13-
it('renders without layout values', () => {
14-
render(
15-
<MemoryRouter initialEntries={['']}>
19+
return (
20+
<MemoryRouter initialEntries={['']} future={routerFuture}>
1621
<LandingLayout data={data}>
1722
<div>child contents</div>
1823
</LandingLayout>
1924
</MemoryRouter>
2025
);
26+
}
27+
28+
it('renders without layout values', () => {
29+
render(<Component layout={[]} />);
30+
expect(screen.getAllByRole('img')).toHaveLength(2);
31+
expect(screen.getAllByRole('link')).toHaveLength(1);
32+
});
33+
it('suppresses the Give link when specified', () => {
34+
const layout = [{
35+
value: {
36+
navLinks: [],
37+
showGive: false
38+
}
39+
}];
40+
41+
render(<Component layout={layout} />);
2142
expect(screen.getAllByRole('img')).toHaveLength(2);
22-
expect(screen.getAllByRole('link')).toHaveLength(3);
43+
expect(screen.queryAllByRole('link')).toHaveLength(0);
2344
});
2445
it('renders with layout values', () => {
25-
data.layout.push({
46+
const layout = [{
2647
value: {
2748
navLinks: [
2849
{
@@ -34,14 +55,9 @@ describe('layouts/landing', () => {
3455
}
3556
]
3657
}
37-
});
38-
render(
39-
<MemoryRouter initialEntries={['']}>
40-
<LandingLayout data={data}>
41-
<div>child contents</div>
42-
</LandingLayout>
43-
</MemoryRouter>
44-
);
45-
expect(screen.getAllByRole('link')).toHaveLength(4);
58+
}];
59+
60+
render(<Component layout={layout} />);
61+
expect(screen.getAllByRole('link')).toHaveLength(2);
4662
});
4763
});

0 commit comments

Comments
 (0)