Skip to content

Commit

Permalink
Revert "MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content ch…
Browse files Browse the repository at this point in the history
…anged by Target for analytics and MWPW-152274" (#2627)

Revert "MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by…"

This reverts commit c5fcc8e.
  • Loading branch information
salonijain3 authored Jul 25, 2024
1 parent 543d9a8 commit c0395ae
Show file tree
Hide file tree
Showing 31 changed files with 298 additions and 637 deletions.
19 changes: 15 additions & 4 deletions libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ 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 @@ -73,7 +79,7 @@ export default async function init(a) {
}

const path = new URL(a.href).pathname;
if (mep?.fragments?.[path]) {
if (mep?.fragments?.[path] && mep) {
relHref = mep.handleFragmentCommand(mep?.fragments[path], a);
if (!relHref) return;
}
Expand Down Expand Up @@ -116,10 +122,15 @@ export default async function init(a) {
}

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

if (a.dataset.manifestId) {
if (inline) {
setManifestIdOnChildren(sections, a.dataset.manifestId);
} else {
fragment.dataset.manifestId = a.dataset.manifestId;
}
}

if (inline) {
insertInlineFrag(sections, a, relHref);
} else {
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,
addMepHighlightAndTargetId,
addMepHighlight,
} 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 addMepHighlightAndTargetId(triggerTemplate, item);
return addMepHighlight(triggerTemplate, item);
}
case 'primaryCta':
case 'secondaryCta':
// Remove its 'em' or 'strong' wrapper
item.parentElement.replaceWith(item);

return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
return addMepHighlight(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 addMepHighlightAndTargetId(linkTemplate, item);
return addMepHighlight(linkTemplate, item);
}
case 'text':
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
return addMepHighlight(toFragment`<div class="feds-navItem feds-navItem--centered">
${item.textContent}
</div>`, item);
default:
/* c8 ignore next 3 */
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
return addMepHighlight(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,
addMepHighlightAndTargetId,
addMepHighlight,
} from '../utilities.js';

const decorateHeadline = (elem, index) => {
Expand Down Expand Up @@ -317,7 +317,7 @@ const decorateMenu = (config) => logErrorFor(async () => {
${menuContent}
</div>
</div>`;
addMepHighlightAndTargetId(menuTemplate, content);
addMepHighlight(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,12 +47,13 @@ export const logErrorFor = async (fn, message, tags) => {
}
};

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;
export function addMepHighlight(el, source) {
let { manifestId } = source.dataset;
if (!manifestId) {
const closestManifestId = source?.closest('[data-manifest-id]');
if (closestManifestId) manifestId = closestManifestId.dataset.manifestId;
}
if (manifestId) el.dataset.manifestId = manifestId;
if (targetManifestId) el.dataset.adobeTargetTestid = targetManifestId;
return el;
}

Expand Down Expand Up @@ -309,7 +310,6 @@ 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
Loading

0 comments on commit c0395ae

Please sign in to comment.