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

Adding onReady and onError callback for standalone footer #3732

Open
wants to merge 3 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions libs/blocks/global-footer/global-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ class Footer {
shouldDecorateLinks: false,
});

if (!this.body) return;
if (!this.body) {
const error = new Error('Could not create global footer. Content not found!');
error.tags = 'global-footer';
error.url = url;
error.errorType = 'error';
lanaLog({ message: error.message, ...error });
const { onFooterError } = getConfig();
onFooterError?.(error);
return;
}

const [region, social] = ['.region-selector', '.social'].map((selector) => this.body.querySelector(selector));
const [regionParent, socialParent] = [region?.parentElement, social?.parentElement];
Expand Down Expand Up @@ -112,8 +121,9 @@ class Footer {

const mepMartech = mep?.martech || '';
this.block.setAttribute('daa-lh', `gnav|${getExperienceName()}|footer${mepMartech}`);

this.block.append(this.elements.footer);
const { onFooterReady } = getConfig();
onFooterReady?.();
}, 'Failed to decorate footer content', 'global-footer', 'error');

loadMenuLogic = async () => {
Expand Down
1 change: 1 addition & 0 deletions libs/navigation/bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default async function bootstrapBlock(initBlock, blockConfig) {
{ key: 'unavComponents', name: 'universal-nav' },
{ key: 'redirect', name: 'adobe-home-redirect' },
{ key: 'mobileGnavV2', name: 'mobile-gnav-v2' },
{ key: 'footerSource', name: 'footer-source' },
];
metaTags.forEach((tag) => {
const { key } = tag;
Expand Down
52 changes: 32 additions & 20 deletions libs/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ export default async function loadBlock(configs, customLib) {
stageDomainsMap: getStageDomainsMap(stageDomainsMap),
origin: `https://main--federal--adobecom.aem.${env === 'prod' ? 'live' : 'page'}`,
allowedOrigins: [...allowedOrigins, `https://main--federal--adobecom.aem.${env === 'prod' ? 'live' : 'page'}`],
onFooterReady: footer?.onReady,
onFooterError: footer?.onError,
...paramConfigs,
};
setConfig(clientConfig);
for await (const block of blockConfig) {
const configBlock = configs[block.key];
const config = getConfig();
const gnavSource = `${config?.locale?.contentRoot}/gnav`;
try {
if (configBlock) {
if (block.key === 'header') {

if (configBlock) {
const config = getConfig();
const gnavSource = `${config?.locale?.contentRoot}/gnav`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for the standalone nav, right? We don't need to consider gnav-source metadata, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Narcis. Just for standalone gnav.

const footerSource = `${config?.locale?.contentRoot}/footer`;
if (block.key === 'header') {
try {
const { default: init } = await import('../blocks/global-navigation/global-navigation.js');
await bootstrapBlock(init, {
...block,
Expand All @@ -146,24 +150,32 @@ export default async function loadBlock(configs, customLib) {
isLocalNav: configBlock.isLocalNav,
mobileGnavV2: configBlock.mobileGnavV2 || 'off',
});
} else if (block.key === 'footer') {
try {
await import('./footer.css');
} catch (e) {
loadStyle(`${miloLibs}/libs/navigation/footer.css`);
}
configBlock.onReady?.();
} catch (e) {
configBlock.onError?.(e);
window.lana.log(`${e.message} | gnav-source: ${gnavSource} | href: ${window.location.href}`, {
clientId: 'feds-milo',
tags: 'standalone-gnav',
errorType: e.errorType,
});
}
}
if (block.key === 'footer') {
import('./footer.css').catch(() => {
loadStyle(`${miloLibs}/libs/navigation/footer.css`);
});
try {
const { default: init } = await import('../blocks/global-footer/global-footer.js');
await bootstrapBlock(init, { ...block });
await bootstrapBlock(init, { ...block, footerSource });
} catch (e) {
configBlock.onError?.(e);
window.lana.log(`${e.message} | footer-source: ${footerSource} | href: ${window.location.href}`, {
clientId: 'feds-milo',
tags: 'standalone-footer',
errorType: e.errorType,
});
}
configBlock.onReady?.();
}
} catch (e) {
configBlock.onError?.(e);
window.lana.log(`${e.message} | gnav-source: ${gnavSource} | href: ${window.location.href}`, {
clientId: 'feds-milo',
tags: 'standalone-gnav',
errorType: e.errorType,
});
}
}
}
Expand Down
Loading