Skip to content

Commit 8c3c769

Browse files
authored
fix: 1135 wiring up veda config (#1320)
2 parents 4e3a21a + 886912e commit 8c3c769

File tree

8 files changed

+84
-127
lines changed

8 files changed

+84
-127
lines changed

app/scripts/components/common/layout-root/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import Logo from '$components/common/page-header-legacy/logo';
2929
import {
3030
mainNavItems,
3131
subNavItems,
32-
footerSettings,
33-
footerPrimaryContactItems,
34-
footerPrimaryNavItems
32+
footerSettings
3533
} from '$components/common/page-header/default-config';
3634
import { checkEnvFlag } from '$utils/utils';
3735

@@ -112,8 +110,8 @@ function LayoutRoot(props: { children?: ReactNode }) {
112110
<PageFooter
113111
settings={footerSettings}
114112
primarySection={{
115-
footerPrimaryContactItems,
116-
footerPrimaryNavItems
113+
mainNavItems,
114+
subNavItems
117115
}}
118116
hideFooter={hideFooter}
119117
logoSvg={<NasaLogoColor />}

app/scripts/components/common/page-footer/index.tsx

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { Icon } from '@trussworks/react-uswds';
3-
3+
//TO DO: need to move NasaLogoColor outside of component and pass down as props
4+
import { NavItemType } from '../page-header/types';
5+
import { NavItemCTA } from '../page-header/nav/nav-item-cta';
46
import {
57
USWDSFooter,
68
USWDSFooterNav,
79
USWDSAddress
810
} from '$components/common/uswds';
11+
912
import './styles.scss';
1013

1114
interface PageFooterProps {
@@ -26,7 +29,7 @@ export default function PageFooter({
2629
return (
2730
<div
2831
id='return-to-top-container'
29-
className=' margin-left-auto margin-right-auto padding-x-4'
32+
className=' margin-left-auto margin-right-auto'
3033
>
3134
<a className='usa-link text-primary' href='#'>
3235
Return to top
@@ -37,7 +40,49 @@ export default function PageFooter({
3740

3841
const { returnToTop, secondarySection } = settings;
3942
/* eslint-disable */
40-
const { footerPrimaryContactItems, footerPrimaryNavItems } = primarySection;
43+
const { mainNavItems, subNavItems } = primarySection;
44+
45+
const createNavElement = (navItems, linkClasses) => {
46+
//removing 'dropdown' items from array
47+
let cleanedNavItems = navItems.filter((a) => {
48+
if (a.type !== 'dropdown') {
49+
return a;
50+
}
51+
});
52+
53+
return cleanedNavItems.map((item) => {
54+
switch (item.type) {
55+
case NavItemType.ACTION:
56+
return <NavItemCTA item={item} customClasses={linkClasses} />;
57+
58+
case NavItemType.EXTERNAL_LINK:
59+
return (
60+
<a className={linkClasses} href={item.to} key={item.id}>
61+
{item.title}
62+
</a>
63+
);
64+
case NavItemType.INTERNAL_LINK:
65+
return (
66+
<a className={linkClasses} href={item.to} key={item.id}>
67+
{item.title}
68+
</a>
69+
);
70+
71+
default:
72+
return <></>;
73+
}
74+
});
75+
};
76+
77+
const primaryItems = useMemo(
78+
() => createNavElement(mainNavItems, 'usa-footer__primary-link'),
79+
[mainNavItems]
80+
);
81+
const secondaryItems = useMemo(
82+
() =>
83+
createNavElement(subNavItems, 'usa-link text-base-dark text-underline'),
84+
[mainNavItems]
85+
);
4186
return (
4287
<>
4388
<USWDSFooter
@@ -53,28 +98,14 @@ export default function PageFooter({
5398
<USWDSFooterNav
5499
aria-label='Footer navigation'
55100
size='slim'
56-
links={Array(4).fill(
57-
<a className='usa-footer__primary-link' href='#'>
58-
PrimaryLink
59-
</a>
60-
)}
101+
links={primaryItems}
61102
/>
62103
</div>
63104
<div className='tablet:grid-col-4'>
64105
<USWDSAddress
65106
size='slim'
66107
className='flex-justify-end'
67-
items={[
68-
<a className='usa-link text-base-dark' key='#' href='#'>
69-
News and Events
70-
</a>,
71-
<a className='usa-link text-base-dark' key='#' href='#'>
72-
About
73-
</a>,
74-
<a className='usa-link text-base-dark' key='#' href='#'>
75-
Contact Us
76-
</a>
77-
]}
108+
items={secondaryItems}
78109
/>
79110
</div>
80111
</div>

app/scripts/components/common/page-header/default-config.ts

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
getString,
33
getNavItemsFromVedaConfig,
4-
getFooterItemsFromVedaConfig
4+
getFooterSettingsFromVedaConfig
55
} from 'veda';
66
import {
77
InternalNavLink,
@@ -78,42 +78,6 @@ const defaultFooterSettings = {
7878
returnToTop: true
7979
};
8080

81-
const defaultFooterPrimaryContactItems = [
82-
{
83-
title: 'News and Events',
84-
to: '/data-catalog',
85-
type: 'internalLink'
86-
},
87-
{
88-
title: 'About',
89-
to: '/data-catalog',
90-
type: 'internalLink'
91-
},
92-
{
93-
title: 'Contact Us',
94-
to: '/data-catalog',
95-
type: 'internalLink'
96-
}
97-
];
98-
99-
const defaultFooterPrimaryNavItems = [
100-
{
101-
title: 'Stories',
102-
to: '/data-catalog',
103-
type: 'internalLink'
104-
},
105-
{
106-
title: 'Topics',
107-
to: '/data-catalog',
108-
type: 'internalLink'
109-
},
110-
{
111-
title: 'Data Toolkit',
112-
to: '/data-catalog',
113-
type: 'internalLink'
114-
}
115-
];
116-
11781
if (process.env.GOOGLE_FORM !== undefined) {
11882
defaultSubNavItems = [
11983
...defaultSubNavItems,
@@ -131,18 +95,6 @@ const mainNavItems =
13195
const subNavItems =
13296
getNavItemsFromVedaConfig()?.subNavItems ?? defaultSubNavItems;
13397
const footerSettings =
134-
getFooterItemsFromVedaConfig()?.footerSettings ?? defaultFooterSettings;
135-
const footerPrimaryContactItems =
136-
getFooterItemsFromVedaConfig()?.footerPrimaryContactItems ??
137-
defaultFooterPrimaryContactItems;
138-
const footerPrimaryNavItems =
139-
getFooterItemsFromVedaConfig()?.footerPrimaryNavItems ??
140-
defaultFooterPrimaryNavItems;
98+
getFooterSettingsFromVedaConfig() ?? defaultFooterSettings;
14199

142-
export {
143-
mainNavItems,
144-
subNavItems,
145-
footerSettings,
146-
footerPrimaryContactItems,
147-
footerPrimaryNavItems
148-
};
100+
export { mainNavItems, subNavItems, footerSettings };

app/scripts/components/common/page-header/nav/create-dynamic-nav-menu-list.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const createDynamicNavMenuList = (
1212
isOpen?: boolean[],
1313
setIsOpen?: SetState<boolean[]>
1414
): JSX.Element[] => {
15+
// @TODO:Need to elevate this functionality to outside of the header. Allow this function to take classname as an argument so we can dynamcally create different types of links across multiple compoenents and apply various visual styling.
1516
return navItems.map((item, index) => {
1617
switch (item.type) {
1718
case NavItemType.DROPDOWN:

app/scripts/components/common/page-header/nav/nav-item-cta.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@ import { ActionNavItem } from '../types';
55

66
interface NavItemCTAProps {
77
item: ActionNavItem;
8+
customClasses?: string;
89
}
910

1011
export const NavItemCTA: React.FC<NavItemCTAProps> = ({
11-
item
12+
item,
13+
customClasses
1214
}): JSX.Element => {
1315
const { isRevealed, show, hide } = useFeedbackModal();
1416
return (
1517
<React.Fragment key={item.id}>
1618
{item.actionId === 'open-google-form' && (
1719
<>
1820
<button
19-
className='usa-nav__link'
21+
className={
22+
customClasses && customClasses != ''
23+
? customClasses
24+
: 'usa-nav__link'
25+
}
2026
type='button'
2127
tabIndex={0}
2228
id={item.id}
2329
onClick={show}
24-
style={{background: 'none', border: 'none', cursor: 'pointer'}}
30+
style={{ background: 'none', border: 'none', cursor: 'pointer' }}
2531
>
2632
{item.title}
2733
</button>

mock/veda.config.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,43 +50,10 @@ let mainNavItems = [
5050
type: 'internalLink'
5151
}
5252
];
53-
let footerPrimaryNavItems = [
54-
{
55-
title: 'Data Catalog',
56-
to: '/data-catalog',
57-
type: 'internalLink'
58-
},
59-
{
60-
title: 'Data Catalog 2',
61-
to: '/data-catalog',
62-
type: 'internalLink'
63-
},
64-
{
65-
title: 'Data Catalog3',
66-
to: '/data-catalog',
67-
type: 'internalLink'
68-
}
69-
];
70-
let footerPrimaryContactItems = [
71-
{
72-
title: 'News and Events',
73-
to: '/data-catalog',
74-
type: 'internalLink'
75-
},
76-
{
77-
title: 'About',
78-
to: '/data-catalog',
79-
type: 'internalLink'
80-
},
81-
{
82-
title: 'Contact Us',
83-
to: '/data-catalog',
84-
type: 'internalLink'
85-
}
86-
];
8753

8854
let footerSettings = {
8955
secondarySection: {
56+
id: 'stories',
9057
title: 'email test',
9158
to: '/data-catalog',
9259
type: 'Email'
@@ -155,11 +122,8 @@ module.exports = {
155122
mainNavItems,
156123
subNavItems
157124
},
158-
footerItems: {
159-
footerSettings,
160-
footerPrimaryContactItems,
161-
footerPrimaryNavItems
162-
},
125+
126+
footerSettings,
163127
cookieConsentForm: {
164128
title: 'Cookie Consent',
165129
copy: 'We use cookies to enhance your browsing experience and to help us understand how our website is used. These cookies allow us to collect data on site usage and improve our services based on your interactions. To learn more about it, see our [Privacy Policy](https://www.nasa.gov/privacy/#cookies)',

parcel-resolver-veda/index.d.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ declare module 'veda' {
293293
}
294294
type NavLinkItem = ExternalNavLink | InternalNavLink;
295295

296+
interface FooterSettings {
297+
secondarySection: {
298+
id: string;
299+
title: string;
300+
href: string;
301+
type: 'Email';
302+
};
303+
returnToTop: boolean;
304+
}
305+
296306
export interface DropdownNavLink {
297307
id: string;
298308
title: string;
@@ -354,13 +364,9 @@ declare module 'veda' {
354364
}
355365
| undefined;
356366

357-
export const getFooterItemsFromVedaConfig: () =>
367+
export const getFooterSettingsFromVedaConfig: () =>
358368
| {
359-
footerSettings: (NavLinkItem | DropdownNavLink)[] | undefined;
360-
footerPrimaryContactItems:
361-
| (NavLinkItem | DropdownNavLink)[]
362-
| undefined;
363-
footerPrimaryNavItems: (NavLinkItem | DropdownNavLink)[] | undefined;
369+
footerSettings: FooterSettings;
364370
}
365371
| undefined;
366372

parcel-resolver-veda/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ module.exports = new Resolver({
229229
banner: ${getBannerContent(result)},
230230
navItems: ${JSON.stringify(result.navItems)},
231231
cookieConsentForm: ${getCookieConsentForm(result)},
232-
footerItems: ${JSON.stringify(result.footerItems)}
233-
232+
footerSettings: ${JSON.stringify(result.footerSettings)}
234233
};
235234
236235
export const theme = ${JSON.stringify(result.theme) || null};
@@ -251,7 +250,7 @@ module.exports = new Resolver({
251250
export const getBannerFromVedaConfig = () => config.banner;
252251
export const getNavItemsFromVedaConfig = () => config.navItems;
253252
export const getCookieConsentFromVedaConfig = () => config.cookieConsentForm;
254-
export const getFooterItemsFromVedaConfig = () => config.footerItems
253+
export const getFooterSettingsFromVedaConfig = () => config.footerSettings;
255254
256255
export const datasets = ${generateMdxDataObject(datasetsImportData)};
257256
export const stories = ${generateMdxDataObject(storiesImportData)};

0 commit comments

Comments
 (0)