Skip to content

Commit

Permalink
Merge branch 'stage' of https://github.com/adobecom/milo into sartxi/…
Browse files Browse the repository at this point in the history
…MWPW-161130-table
  • Loading branch information
Sartxi committed Oct 30, 2024
2 parents c1e148b + 8f0adc1 commit 7d20f24
Show file tree
Hide file tree
Showing 109 changed files with 4,233 additions and 1,747 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ logs/*
**/mas/*/stats.json
test-html-results/
test-results/
test-a11y-results/
1 change: 0 additions & 1 deletion libs/blocks/article-feed/article-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ async function buildFilter(type, tax, block, config) {
applyBtn.classList.add('button', 'small', 'apply');
applyBtn.textContent = await replacePlaceholder('apply');
applyBtn.addEventListener('click', () => {
// sampleRUM('apply-topic-filter');
delete config.selectedProducts;
delete config.selectedIndustries;
closeCurtain();
Expand Down
6 changes: 3 additions & 3 deletions libs/blocks/bulk-publish-v2/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const setUserData = (event) => {

const isPushedDown = async () => {
const callback = () => {
const sidekick = document.querySelector('helix-sidekick');
const sidekick = document.querySelector('aem-sidekick, helix-sidekick');
const pushdown = sidekick?.getAttribute('pushdown');
const bulkPub = document.querySelector('.bulk-publish-v2');
if (pushdown && !bulkPub.classList.contains('pushdown')) {
Expand All @@ -81,13 +81,13 @@ const isPushedDown = async () => {
const authenticate = async (tool = null) => {
isPushedDown();
const setUser = (event) => { tool.user = setUserData(event); };
const openSideKick = document.querySelector('helix-sidekick');
const openSideKick = document.querySelector('aem-sidekick, helix-sidekick');
if (openSideKick) {
openSideKick.addEventListener('statusfetched', setUser);
/* c8 ignore next 6 */
} else {
document.addEventListener('sidekick-ready', () => {
const sidekick = document.querySelector('helix-sidekick');
const sidekick = document.querySelector('aem-sidekick, helix-sidekick');
sidekick.addEventListener('statusfetched', setUser);
}, { once: true });
}
Expand Down
5 changes: 2 additions & 3 deletions libs/blocks/library-config/library-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async function loadList(type, content, list) {
case 'assets':
loadAssets(content, list);
break;
case 'personalization_tags':
case 'MEP_personalization':
loadPersonalization(content, list);
break;
default:
Expand Down Expand Up @@ -153,7 +153,7 @@ async function combineLibraries(base, supplied) {
blocks: base.blocks.data,
templates: base.templates?.data,
icons: base.icons?.data,
personalization_tags: base.personalization?.data,
MEP_personalization: base.personalization?.data,
placeholders: base.placeholders?.data,
};

Expand Down Expand Up @@ -197,7 +197,6 @@ function createList(libraries) {
list.classList.add('inset');
skLibrary.classList.add('allow-back');
loadList(type, libraries[type], list);
window.hlx?.rum.sampleRUM('click', { source: e.target });
});
});

Expand Down
1 change: 0 additions & 1 deletion libs/blocks/library-config/lists/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ export default async function loadBlocks(blocks, list, query, type) {
setTimeout(() => { e.target.classList.remove('copied'); }, 3000);
const blob = new Blob([`${BLOCK_SPACING}${containerHtml}${BLOCK_SPACING}`], { type: 'text/html' });
createCopy(blob);
window.hlx?.rum.sampleRUM('click', { source: e.target });
});
item.append(name, copy);

Expand Down
1 change: 0 additions & 1 deletion libs/blocks/library-config/lists/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default async function iconList(content, list) {
const formatted = `:${key}:`;
const blob = new Blob([formatted], { type: 'text/plain' });
createCopy(blob);
window.hlx?.rum.sampleRUM('click', { source: e.target });
});
title.append(copy);
list.append(title);
Expand Down
33 changes: 20 additions & 13 deletions libs/blocks/library-config/lists/personalization.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { createTag } from '../../../utils/utils.js';
import createCopy from '../library-utils.js';

const fetchTags = async (path) => {
const resp = await fetch(path);
if (!resp.ok) return [];
const json = await resp.json();
return json.data || [];
};

const categorize = (tagData) => tagData
const categorize = (tagData, category) => tagData
.reduce((tags, tag) => {
tags[tag.category] ??= [];
tags[tag.category].push({
const tagCategory = tag.category || category;
tags[tagCategory] ??= [];
tags[tagCategory].push({
tagname: tag.tagname,
description: tag.description,
});
return tags;
}, {});

const fetchTags = async (path, category) => {
const resp = await fetch(path);
if (!resp.ok) return [];
const json = await resp.json();
return categorize(json.data, category);
};

const getCopyBtn = (tagName) => {
const copy = createTag('button', { class: 'copy' });
copy.id = `${tagName}-tag-copy`;
Expand All @@ -26,14 +27,20 @@ const getCopyBtn = (tagName) => {
setTimeout(() => { e.target.classList.remove('copied'); }, 3000);
const blob = new Blob([tagName], { type: 'text/plain' });
createCopy(blob);
window.hlx?.rum.sampleRUM('click', { source: e.target });
});
return copy;
};

export default async function loadPersonalization(content, list) {
const tagData = await fetchTags(content[0].path);
const tagsObj = categorize(tagData);
let tagsObj = {};
for (const item of content) {
const { category, path } = item;
tagsObj = {
...tagsObj,
...await fetchTags(path, category),
};
}

list.textContent = '';

Object.entries(tagsObj).forEach(([category, tags]) => {
Expand Down
1 change: 0 additions & 1 deletion libs/blocks/library-config/lists/placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default async function placeholderList(content, list) {
const formatted = `{{${placeholder.key}}}`;
const blob = new Blob([formatted], { type: 'text/plain' });
createCopy(blob);
window.hlx?.rum.sampleRUM('click', { source: e.target });
});
title.append(copy);
list.append(title);
Expand Down
60 changes: 46 additions & 14 deletions libs/blocks/marketo/marketo.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const FORM_MAP = {
'co-partner-names': 'program.copartnernames',
'sfdc-campaign-id': 'program.campaignids.sfdc',
};
export const FORM_PARAM = 'form';

export const formValidate = (formEl) => {
formEl.classList.remove('hide-errors');
Expand Down Expand Up @@ -69,7 +70,7 @@ export const decorateURL = (destination, baseURL = window.location) => {
return destinationUrl.href;
} catch (e) {
/* c8 ignore next 4 */
window.lana?.log(`Error with Marketo destination URL: ${destination} ${e.message}`);
window.lana?.log(`Error with Marketo destination URL: ${destination} ${e.message}`, { tags: 'error,marketo' });
}

return null;
Expand All @@ -91,6 +92,38 @@ export const setPreferences = (formData) => {
Object.entries(formData).forEach(([key, value]) => setPreference(key, value));
};

const showSuccessSection = (formData, scroll = true) => {
const show = (el) => {
el.classList.remove('hide-block');
if (scroll) el.scrollIntoView({ behavior: 'smooth' });
};
const successClass = formData[SUCCESS_SECTION]?.toLowerCase().replaceAll(' ', '-');
if (!successClass) {
window.lana?.log('Error showing Marketo success section', { tags: 'warn,marketo' });
return;
}
const section = document.querySelector(`.section.${successClass}`);
if (section) {
show(section);
return;
}
// For Marquee use case
const maxIntervals = 6;
let count = 0;
const interval = setInterval(() => {
const el = document.querySelector(`.section.${successClass}`);
if (el) {
clearInterval(interval);
show(el);
}
count += 1;
if (count > maxIntervals) {
clearInterval(interval);
window.lana?.log('Error showing Marketo success section', { tags: 'warn,marketo' });
}
}, 500);
};

export const formSuccess = (formEl, formData) => {
const el = formEl.closest('.marketo');
const parentModal = formEl?.closest('.dialog-modal');
Expand All @@ -108,18 +141,8 @@ export const formSuccess = (formEl, formData) => {
}

if (formData?.[SUCCESS_TYPE] !== 'section') return true;

try {
const section = formData[SUCCESS_SECTION].toLowerCase().replaceAll(' ', '-');
const success = document.querySelector(`.section.${section}`);
success.classList.remove('hide-block');
success.scrollIntoView({ behavior: 'smooth' });
setPreference(SUCCESS_TYPE, 'message');
} catch (e) {
/* c8 ignore next 2 */
window.lana?.log('Error showing Marketo success section', { tags: 'errorType=warn,module=marketo' });
}

showSuccessSection(formData);
setPreference(SUCCESS_TYPE, 'message');
return false;
};

Expand Down Expand Up @@ -161,7 +184,7 @@ export const loadMarketo = (el, formData) => {
.catch(() => {
/* c8 ignore next 2 */
el.style.display = 'none';
window.lana?.log(`Error loading Marketo form for ${munchkinID}_${formID}`, { tags: 'errorType=error,module=marketo' });
window.lana?.log(`Error loading Marketo form for ${munchkinID}_${formID}`, { tags: 'error,marketo' });
});
};

Expand Down Expand Up @@ -198,6 +221,15 @@ export default function init(el) {
return;
}

const searchParams = new URLSearchParams(window.location.search);
const ungated = searchParams.get(FORM_PARAM) === 'off';

if (formData[SUCCESS_TYPE] === 'section' && ungated) {
el.classList.add('hide-block');
showSuccessSection(formData, false);
return;
}

formData[SUCCESS_TYPE] = formData[SUCCESS_TYPE] || 'redirect';

if (formData[SUCCESS_TYPE] === 'redirect') {
Expand Down
7 changes: 4 additions & 3 deletions libs/blocks/media/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ div[class*="-up"] .media .foreground > .media-row {
}

.media.qr-code .qr-button-container {
display: inline;
margin-right: var(--spacing-s);
display: inline-block;
margin: 0;
}

.media.qr-code .google-play,
Expand All @@ -179,7 +179,8 @@ div[class*="-up"] .media .foreground > .media-row {
justify-content: center;
padding: 0;
display: inline-flex;
margin: var(--spacing-xs) var(--spacing-s) 0 0;
margin-top: var(--spacing-xs);
margin-inline-end: var(--spacing-s);
}

.media.qr-code .google-play {
Expand Down
5 changes: 5 additions & 0 deletions libs/blocks/media/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ function decorateQr(el) {
const googlePlay = text.children[(text.children.length - 2)]?.querySelector('a');
const qrImage = text.children[(text.children.length - 3)];
if (!qrImage || !appStore || !googlePlay) return;
[appStore, googlePlay].forEach(({ parentElement }) => {
parentElement.classList.add('qr-button-container');
});
qrImage.classList.add('qr-code-img');
appStore.classList.add('app-store');
appStore.textContent = '';
appStore.setAttribute('aria-label', 'Apple App Store');
googlePlay.classList.add('google-play');
googlePlay.textContent = '';
googlePlay.setAttribute('aria-label', 'Google Play Store');
}

export default async function init(el) {
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ export default async function init(el) {
merchCard.append(
createTag(
'div',
{ slot: 'action-menu-content' },
{ slot: 'action-menu-content', tabindex: '0' },
actionMenuContent.innerHTML,
),
);
Expand Down
17 changes: 17 additions & 0 deletions libs/blocks/merch/merch.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,23 @@ export async function initService(force = false, attributes = {}) {
fetchCheckoutLinkConfigs.promise = undefined;
}
const { commerce, env: miloEnv, locale: miloLocale } = getConfig();

const extraAttrs = [
'checkout-workflow-step',
'force-tax-exclusive',
'checkout-client-id',
'allow-override',
];

extraAttrs.forEach((attr) => {
const camelCaseAttr = attr.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
// eslint-disable-next-line no-prototype-builtins
if (commerce?.hasOwnProperty(camelCaseAttr)) {
const value = commerce[camelCaseAttr];
delete commerce[camelCaseAttr];
commerce[attr] = value;
}
});
initService.promise = initService.promise ?? polyfills().then(async () => {
await import('../../deps/mas/commerce.js');
const { language, locale } = getMiloLocaleSettings(miloLocale);
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/preflight/panels/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function setContent() {
};

getStatuses();
const sk = document.querySelector('helix-sidekick');
const sk = document.querySelector('aem-sidekick, helix-sidekick');
sk?.addEventListener('statusfetched', async () => {
getStatuses();
});
Expand Down
Loading

0 comments on commit 7d20f24

Please sign in to comment.