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

[Release] Stage to Main #2617

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 12 additions & 18 deletions libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ const updateFragMap = (fragment, a, href) => {
}
};

const setManifestIdOnChildren = (sections, manifestId) => {
[...sections[0].children].forEach(
(child) => (child.dataset.manifestId = manifestId),
);
};

const insertInlineFrag = (sections, a, relHref) => {
// Inline fragments only support one section, other sections are ignored
const fragChildren = [...sections[0].children];
Expand Down Expand Up @@ -79,7 +73,7 @@ export default async function init(a) {
}

const path = new URL(a.href).pathname;
if (mep?.fragments?.[path] && mep) {
if (mep?.fragments?.[path]) {
relHref = mep.handleFragmentCommand(mep?.fragments[path], a);
if (!relHref) return;
}
Expand All @@ -90,11 +84,16 @@ export default async function init(a) {
}

const { customFetch } = await import('../../utils/helpers.js');
const resp = await customFetch({ resource: `${a.href}.plain.html`, withCacheRules: true })
let resourcePath = a.href;
if (a.href.includes('/federal/')) {
const { getFederatedUrl } = await import('../../utils/federated.js');
resourcePath = getFederatedUrl(a.href);
}
const resp = await customFetch({ resource: `${resourcePath}.plain.html`, withCacheRules: true })
.catch(() => ({}));

if (!resp?.ok) {
window.lana?.log(`Could not get fragment: ${a.href}.plain.html`);
window.lana?.log(`Could not get fragment: ${resourcePath}.plain.html`);
return;
}

Expand All @@ -106,7 +105,7 @@ export default async function init(a) {
const sections = doc.querySelectorAll('body > div');

if (!sections.length) {
window.lana?.log(`Could not make fragment: ${a.href}.plain.html`);
window.lana?.log(`Could not make fragment: ${resourcePath}.plain.html`);
return;
}

Expand All @@ -117,15 +116,10 @@ export default async function init(a) {
}

updateFragMap(fragment, a, relHref);

if (a.dataset.manifestId) {
if (inline) {
setManifestIdOnChildren(sections, a.dataset.manifestId);
} else {
fragment.dataset.manifestId = a.dataset.manifestId;
}
if (a.dataset.manifestId || a.dataset.adobeTargetTestid) {
const { updateFragDataProps } = await import('../../features/personalization/personalization.js');
updateFragDataProps(a, inline, sections, fragment);
}

if (inline) {
insertInlineFrag(sections, a, relHref);
} else {
Expand Down
2 changes: 2 additions & 0 deletions libs/blocks/global-footer/global-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getMetadata,
getConfig,
loadBlock,
localizeLink,
} from '../../utils/utils.js';

import {
Expand Down Expand Up @@ -258,6 +259,7 @@ class Footer {
} else {
// No hash -> region selector expands a dropdown
regionPickerElem.href = '#'; // reset href value to not get treated as a fragment
regionSelector.href = localizeLink(regionSelector.href);
decorateAutoBlock(regionSelector); // add fragment-specific class(es)
this.elements.regionPicker.append(regionSelector); // add fragment after regionPickerElem
await loadBlock(regionSelector); // load fragment and replace original link
Expand Down
12 changes: 6 additions & 6 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
toFragment,
trigger,
yieldToMain,
addMepHighlight,
addMepHighlightAndTargetId,
} from './utilities/utilities.js';

import { replaceKey, replaceKeyArray } from '../../features/placeholders.js';
Expand Down Expand Up @@ -919,14 +919,14 @@ class Gnav {
observer.observe(dropdownTrigger, { attributeFilter: ['aria-expanded'] });

delayDropdownDecoration({ template: triggerTemplate });
return addMepHighlight(triggerTemplate, item);
return addMepHighlightAndTargetId(triggerTemplate, item);
}
case 'primaryCta':
case 'secondaryCta':
// Remove its 'em' or 'strong' wrapper
item.parentElement.replaceWith(item);

return addMepHighlight(toFragment`<div class="feds-navItem feds-navItem--centered">
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
${decorateCta({ elem: item, type: itemType, index: index + 1 })}
</div>`, item);
case 'link': {
Expand All @@ -945,15 +945,15 @@ class Gnav {
<div class="feds-navItem${activeModifier}">
${linkElem}
</div>`;
return addMepHighlight(linkTemplate, item);
return addMepHighlightAndTargetId(linkTemplate, item);
}
case 'text':
return addMepHighlight(toFragment`<div class="feds-navItem feds-navItem--centered">
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
${item.textContent}
</div>`, item);
default:
/* c8 ignore next 3 */
return addMepHighlight(toFragment`<div class="feds-navItem feds-navItem--centered">
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
${item}
</div>`, item);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/blocks/global-navigation/utilities/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
toFragment,
trigger,
yieldToMain,
addMepHighlight,
addMepHighlightAndTargetId,
} from '../utilities.js';

const decorateHeadline = (elem, index) => {
Expand Down Expand Up @@ -317,7 +317,7 @@ const decorateMenu = (config) => logErrorFor(async () => {
${menuContent}
</div>
</div>`;
addMepHighlight(menuTemplate, content);
addMepHighlightAndTargetId(menuTemplate, content);

decorateCrossCloudMenu(menuTemplate);

Expand Down
12 changes: 6 additions & 6 deletions libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ export const logErrorFor = async (fn, message, tags) => {
}
};

export function addMepHighlight(el, source) {
let { manifestId } = source.dataset;
if (!manifestId) {
const closestManifestId = source?.closest('[data-manifest-id]');
if (closestManifestId) manifestId = closestManifestId.dataset.manifestId;
}
export function addMepHighlightAndTargetId(el, source) {
let { manifestId, targetManifestId } = source.dataset;
manifestId ??= source?.closest('[data-manifest-id]')?.dataset?.manifestId;
targetManifestId ??= source?.closest('[data-adobe-target-testid]')?.dataset?.adobeTargetTestid;
if (manifestId) el.dataset.manifestId = manifestId;
if (targetManifestId) el.dataset.adobeTargetTestid = targetManifestId;
return el;
}

Expand Down Expand Up @@ -310,6 +309,7 @@ export async function fetchAndProcessPlainHtml({ url, shouldDecorateLinks = true
const text = await res.text();
const { body } = new DOMParser().parseFromString(text, 'text/html');
if (mepFragment?.manifestId) body.dataset.manifestId = mepFragment.manifestId;
if (mepFragment?.targetManifestId) body.dataset.adobeTargetTestid = mepFragment.targetManifestId;
const commands = mepGnav?.commands;
if (commands?.length) {
const { handleCommands, deleteMarkedEls } = await import('../../../features/personalization/personalization.js');
Expand Down
7 changes: 6 additions & 1 deletion libs/blocks/locale-nav/locale-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ const decorateLocales = (current) => {
delete locales[currLocale];
return Object.keys(locales).map((key) => {
const prefix = key === '' ? key : `/${key}`;
const localePath = currLocale === ''
let localePath = currLocale === ''
? `/${key}${current.pathname}`
: current.pathname.replace(current.locale.prefix, prefix);
if (localePath.startsWith('/langstore/')) {
// eslint-disable-next-line no-param-reassign
key = 'langstore/en';
localePath = localePath.replace('/langstore/', `/${key}/`);
}
const li = createTag('li', { class: 'detail' }, `<span>${key || 'us'}</span>`);
getStatus(li, localePath);
return li;
Expand Down
Loading
Loading