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

Mwpw 151518: Adobe Home merch card integration with M@S Studio #2440

Merged
merged 8 commits into from
Jun 6, 2024
Merged
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
5,000 changes: 4,996 additions & 4 deletions libs/deps/commerce.js

Large diffs are not rendered by default.

159 changes: 122 additions & 37 deletions libs/deps/merch-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/features/mas/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<merch-datasource source="odin" path="/content/dam/sandbox/mas/creative-cloud" mep="https://main--milo--adobecom.hlx.live/drafts/ilyas/manifests/ccd.json"></merch-datasource>
</merch-card>
</div>
<!-- test comment -->

<div class="two-merch-cards catalog">
<merch-card variant="catalog">
<merch-datasource source="odin" path="/content/dam/sandbox/mas/creative-cloud"></merch-datasource>
Expand Down
19 changes: 0 additions & 19 deletions libs/features/mas/listener.js

This file was deleted.

12 changes: 7 additions & 5 deletions libs/features/mas/mas.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ if (!customElements.get('sp-button')) {
}

const [localeElement] = document.getElementsByName('wcs-locale');
const locale = localeElement ? localeElement.getAttribute('content') : '';
const locale = localeElement ? localeElement.getAttribute('content') : '/';

window.lana = { log: () => {} };
window.adobeIMS = {
initialized: true,
isSignedInUser: () => false,
};
if (!window.adobeIMS) {
window.adobeIMS = {
initialized: true,
isSignedInUser: () => false,
};
}
const config = setConfig({ codeRoot: '/libs' });
config.locale.prefix = locale;

Expand Down
51 changes: 46 additions & 5 deletions libs/features/mas/merch-datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@

let accessToken;

const cardContent = {
catalog: {
name: 'catalog',
title: {
tag: 'h3',
slot: 'heading-xs',
},
prices: {
tag: 'h3',
slot: 'heading-xs',
},
description: {
tag: 'div',
slot: 'body-xs',
},
ctas: { size: 'l' },
},
ah: {
name: 'ah',
title: {
tag: 'h3',
slot: 'heading-xxs',
},
prices: {
tag: 'h3',
slot: 'heading-xs',
},
description: {
tag: 'div',
slot: 'body-xxs',
},
ctas: { size: 's' },
},
};

let cb = `?cb=${Math.round(Math.random() * 1000000)}`;

const fetchCache = new Map();
Expand All @@ -15,7 +50,7 @@
await res;
return res;
}
const res = fetch(url, options).then((res) => res.json());

Check failure on line 53 in libs/features/mas/merch-datasource.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 'res' is already declared in the upper scope on line 53 column 9. Raw Output: {"ruleId":"no-shadow","severity":2,"message":"'res' is already declared in the upper scope on line 53 column 9.","line":53,"column":41,"nodeType":"Identifier","messageId":"noShadow","endLine":53,"endColumn":44}
fetchCache.set(url, res);
await res;
return res;
Expand All @@ -41,27 +76,33 @@

async function parseMerchCard(cardJson, merchCard) {
const { type = 'catalog' } = cardJson;
const cardType = cardContent[type] || cardContent.catalog;

merchCard.setAttribute('variant', type);
cardJson.icon?.forEach((icon) => {
const merchIcon = createTag('merch-icon', { slot: 'icons', src: icon, alt: '', href: '', size: 'l' });
merchCard.append(merchIcon);
});

if (cardJson.title) {
merchCard.append(createTag('h4', { slot: 'heading-xs' }, cardJson.title));
merchCard.append(createTag(cardType.title.tag, { slot: cardType.title.slot }, cardJson.title));
}

if (cardJson.prices?.html) {
const prices = await parseMerchLinks(cardJson.prices.html);
const headingM = createTag('h3', { slot: 'heading-m' }, prices);
const headingM = createTag(cardType.prices.tag, { slot: cardType.prices.slot }, prices);
merchCard.append(headingM);
}

merchCard.append(createTag('p', { slot: 'body-xxs', id: 'individuals1' }, 'Desktop'));

if (cardJson.description?.html) {
const bodyXS = createTag('div', { slot: 'body-xs' }, cardJson.description.html);
merchCard.append(bodyXS);
const body = createTag(
cardType.description.tag,
{ slot: cardType.description.slot },
cardJson.description.html,
);
merchCard.append(body);
}

if (cardJson.ctas?.html) {
Expand All @@ -70,7 +111,7 @@
cta.style.display = 'none';
const variant = cta.classList.contains('blue') ? 'accent' : 'primary';
const treatment = variant === 'primary' ? 'outline' : '';
const spButton = createTag('sp-button', { variant, treatment });
const spButton = createTag('sp-button', { variant, treatment, size: cardType.ctas.size });
spButton.innerHTML = cta.innerHTML;
spButton.addEventListener('click', (e) => {
e.stopImmediatePropagation();
Expand Down
8 changes: 0 additions & 8 deletions libs/features/spectrum-web-components/dist/action-group.js

This file was deleted.

2 changes: 1 addition & 1 deletion libs/features/spectrum-web-components/dist/base.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading