diff --git a/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js b/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js index ad631d2..f5305ca 100644 --- a/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js +++ b/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js @@ -1,8 +1,3 @@ import PartnerCardsWithDateFilter from '../../components/PartnerCardsWithDateFilter.js'; -export default class KnowledgeBaseOverview extends PartnerCardsWithDateFilter { - constructor() { - super(); - this.useStageCaasEndpoint = true; - } -} +export default class KnowledgeBaseOverview extends PartnerCardsWithDateFilter {} diff --git a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js index b8178e7..6a95a5a 100644 --- a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js +++ b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js @@ -1,4 +1,5 @@ -import { getLibs, replaceText, getConfig, populateLocalizedTextFromListItems } from '../../scripts/utils.js'; +import { getCaasUrl, getLibs } from '../../scripts/utils.js'; +import { replaceText, getConfig, populateLocalizedTextFromListItems } from '../utils/utils.js'; import KnowledgeBaseOverview from './KnowledgeBaseOverview.js'; function declareKnowledgeBaseOverview() { @@ -70,14 +71,20 @@ export default async function init(el) { ], }; + const block = { + el, + name: 'knowledge-base-overview', + collectionTag: '"caas:adobe-partners/collections/knowledge-base"', + ietf: config.locale.ietf + } + const blockData = { localizedText, tableData: el.children, dateFilter, cardsPerPage: 12, - ietf: config.locale.ietf, - collectionTags: '"caas:adobe-partners/collections/knowledge-base"', pagination: 'default', + caasUrl: getCaasUrl(block) }; const app = document.createElement('knowledge-base-overview'); diff --git a/eds/blocks/partner-news/partner-news.js b/eds/blocks/partner-news/partner-news.js index 1752ec3..c9a55f7 100644 --- a/eds/blocks/partner-news/partner-news.js +++ b/eds/blocks/partner-news/partner-news.js @@ -1,4 +1,5 @@ -import { getLibs, replaceText, getConfig, populateLocalizedTextFromListItems } from '../../scripts/utils.js'; +import { getCaasUrl, getLibs } from '../../scripts/utils.js'; +import { replaceText, getConfig, populateLocalizedTextFromListItems } from '../utils/utils.js'; import PartnerNews from './PartnerNews.js'; function declarePartnerNews() { @@ -70,14 +71,20 @@ export default async function init(el) { ], }; + const block = { + el, + name: 'partner-news', + collectionTag: '"caas:adobe-partners/collections/news"', + ietf: config.locale.ietf + } + const blockData = { localizedText, tableData: el.children, dateFilter, cardsPerPage: 12, - ietf: config.locale.ietf, - collectionTags: '"caas:adobe-partners/collections/news"', pagination: 'load-more', + caasUrl: getCaasUrl(block) }; const app = document.createElement('partner-news'); diff --git a/eds/blocks/utils/utils.js b/eds/blocks/utils/utils.js new file mode 100644 index 0000000..2c2c0f5 --- /dev/null +++ b/eds/blocks/utils/utils.js @@ -0,0 +1,20 @@ +import { setLibs } from '../../scripts/utils.js'; + +const miloLibs = setLibs('/libs'); + +const { createTag, localizeLink, getConfig } = await import(`${miloLibs}/utils/utils.js`); + +export { createTag, localizeLink, getConfig }; +const { replaceText } = await import(`${miloLibs}/features/placeholders.js`); +export { replaceText }; + +export function populateLocalizedTextFromListItems(el, localizedText) { + const liList = Array.from(el.querySelectorAll('li')); + liList.forEach((liEl) => { + const liInnerText = liEl.innerText; + if (!liInnerText) return; + let liContent = liInnerText.trim().toLowerCase().replace(/ /g, '-'); + if (liContent.endsWith('_default')) liContent = liContent.slice(0, -8); + localizedText[`{{${liContent}}}`] = liContent; + }); +} diff --git a/eds/components/NewsCardStyles.js b/eds/components/NewsCardStyles.js deleted file mode 100644 index 546e93d..0000000 --- a/eds/components/NewsCardStyles.js +++ /dev/null @@ -1,141 +0,0 @@ -import { getLibs } from '../scripts/utils.js'; - -const miloLibs = getLibs(); -const { css } = await import(`${miloLibs}/deps/lit-all.min.js`); - -const borderColor = css`#eaeaea`; - -// eslint-disable-next-line import/prefer-default-export -export const newsCardStyles = css` - .news-card * { - box-sizing: border-box; - } - - .news-card { - display: flex; - flex-direction: column; - background-color: #fff; - border: 1px solid ${borderColor}; - border-radius: 4px; - overflow: hidden; - width: 100%; - height: 400px; - } - - .news-card:hover { - box-shadow: 0 3px 6px 0 rgba(0,0,0,.16); - transition: box-shadow .3s ease-in-out; - } - - .news-card .card-header { - min-height: 192px; - max-height: 192px; - background-color: #323232; - background-repeat: no-repeat; - background-position: 50% 50%; - background-size: cover; - border-top-left-radius: 4px; - border-top-right-radius: 4px; - position: relative; - } - - .news-card:hover .card-header:after { - opacity: 1; - } - - .news-card .card-header:after { - position: absolute; - content: ""; - top: 0; - bottom: 0; - left: 0; - right: 0; - margin: auto; - z-index: 0; - background-color: rgba(0,0,0,.35); - opacity: 0; - transition: opacity .3s ease-in-out; - } - - .news-card .card-content { - display: flex; - flex-direction: column; - justify-content: space-between; - background-color: #fff; - padding: 16px 16px 20px; - height: 100%; - } - - .news-card .card-title { - color: #323232; - font-size: 1.125rem; - font-weight: 700; - line-height: 1.375rem; - word-break: break-word; - max-height: 2.75rem; - margin: 0 0 7px; - display: -webkit-box; - -webkit-box-orient: vertical; - overflow: hidden; - -webkit-line-clamp: 2; - } - - .news-card .card-description { - color: #505050; - font-size: .875rem; - line-height: 1.3125rem; - font-weight: 400; - word-break: break-word; - margin: 0 0 14px; - max-height: 3.9375rem; - display: -webkit-box; - -webkit-box-orient: vertical; - overflow: hidden; - -webkit-line-clamp: 3; - } - - .news-card .card-footer { - display: flex; - justify-content: space-between; - align-items: center; - } - - .news-card .card-btn { - display: flex; - justify-content: center; - align-items: center; - font-size: .875rem; - line-height: 1.063rem; - font-weight: 700; - min-width: 60px; - max-width: 100%; - height: 28px; - max-height: 32px; - margin-left: 16px; - padding-left: 14px; - padding-right: 14px; - text-decoration: none; - color: #222222; - border: 2px solid #222222; - border-radius: 16px; - background-color: #ffffff00; - cursor: pointer; - transition: border-color .3s ease-in-out,background-color .3s ease-in-out; - } - - .news-card .card-btn:hover { - text-decoration: none; - border-color: #222222; - background-color: #222222; - color: #ffffff; - } - - .news-card .card-date { - color: #747474; - font-size: .875rem; - line-height: 1.3125rem; - word-break: break-word; - max-height: 3.9375rem; - padding: 0; - } -`; diff --git a/eds/components/PartnerCards.js b/eds/components/PartnerCards.js index e4f18e1..e0fa40f 100644 --- a/eds/components/PartnerCards.js +++ b/eds/components/PartnerCards.js @@ -1,20 +1,19 @@ import { getLibs, - prodHosts, - getPartnerDataCookieValue, - getCurrentProgramType, } from '../scripts/utils.js'; import { partnerCardsStyles, partnerCardsLoadMoreStyles, partnerCardsPaginationStyles, } from './PartnerCardsStyles.js'; -import './NewsCard.js'; +import './SinglePartnerCard.js'; const miloLibs = getLibs(); const { html, LitElement, css, repeat } = await import(`${miloLibs}/deps/lit-all.min.js`); export default class PartnerCards extends LitElement { + static caasUrl; + static styles = [ partnerCardsStyles, partnerCardsLoadMoreStyles, @@ -35,7 +34,7 @@ export default class PartnerCards extends LitElement { selectedFilters: { type: Object }, urlSearchParams: { type: Object }, mobileView: { type: Boolean }, - useStageCaasEndpoint: { type: Boolean }, + fetchedData: { type: Boolean }, }; constructor() { @@ -50,8 +49,8 @@ export default class PartnerCards extends LitElement { this.selectedSortOrder = {}; this.selectedFilters = {}; this.urlSearchParams = {}; - this.collectionTags = []; - this.hasResponseData = false; + this.hasResponseData = true; + this.fetchedData = false; this.mobileView = window.innerWidth <= 1200; this.updateView = this.updateView.bind(this); } @@ -71,12 +70,8 @@ export default class PartnerCards extends LitElement { default: {}, items: [], }, - language: '', - country: '', }; - this.collectionTags = [this.blockData.collectionTags]; - const blockDataActions = { title: (cols) => { const [titleEl] = cols; @@ -125,13 +120,6 @@ export default class PartnerCards extends LitElement { const cardsPerPageNum = parseInt(cardsPerPageStr, 10); if (cardsPerPageNum) this.blockData.cardsPerPage = cardsPerPageNum; }, - 'collection-tags': (cols) => { - const [collectionTagsEl] = cols; - const collectionTags = Array.from(collectionTagsEl.querySelectorAll('li'), (li) => `"${li.innerText.trim().toLowerCase()}"`); - if (collectionTags.length) { - this.collectionTags = [...this.collectionTags, ...collectionTags]; - } - }, pagination: (cols) => { const [paginationEl] = cols; const paginationType = paginationEl.innerText.trim(); @@ -146,10 +134,6 @@ export default class PartnerCards extends LitElement { const colsContent = cols.slice(1); if (blockDataActions[rowTitle]) blockDataActions[rowTitle](colsContent); }); - - const [language, country] = this.blockData.ietf.split('-'); - this.blockData.language = language; - this.blockData.country = country; } updateView() { @@ -171,14 +155,20 @@ export default class PartnerCards extends LitElement { async fetchData() { try { - const domain = `${(this.useStageCaasEndpoint && !prodHosts.includes(window.location.host)) ? 'https://14257-chimera-stage.adobeioruntime.net/api/v1/web/chimera-0.0.1' : 'https://www.adobe.com/chimera-api'}`; - const api = new URL(`${domain}/collection?originSelection=dx-partners&draft=false&debug=true&flatFile=false&expanded=true`); - const apiWithParams = this.setApiParams(api); - const response = await fetch(apiWithParams); + let apiData; + + setTimeout(() => { + this.hasResponseData = !!apiData?.cards; + this.fetchedData = true; + }, 5); + + const response = await fetch(this.blockData.caasUrl); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } - const apiData = await response.json(); + apiData = await response.json(); + const cardsEvent = new Event('partner-cards-loaded'); + document.dispatchEvent(cardsEvent); if (apiData?.cards) { if (window.location.hostname === 'partners.adobe.com') { apiData.cards = apiData.cards.filter((card) => !card.contentArea.url?.includes('/drafts/')); @@ -195,44 +185,6 @@ export default class PartnerCards extends LitElement { } } - setApiParams(api) { - const complexQueryParams = this.getComplexQueryParams(); - if (complexQueryParams) api.searchParams.set('complexQuery', complexQueryParams); - - const { language, country } = this.blockData; - if (language && country) { - api.searchParams.set('language', language); - api.searchParams.set('country', country); - } - - return api.toString(); - } - - getComplexQueryParams() { - const portal = getCurrentProgramType(); - if (!portal) return; - - const portalCollectionTag = `"caas:adobe-partners/${portal}"`; - if (!this.collectionTags.includes(portalCollectionTag)) { - this.collectionTags = [...this.collectionTags, portalCollectionTag]; - } - - const partnerLevelParams = this.getPartnerLevelParams(portal); - const collectionTagsStr = this.collectionTags.filter((e) => e.length).join('+AND+'); - - let resulStr = `(${collectionTagsStr})`; - if (partnerLevelParams) resulStr += `+AND+${partnerLevelParams}`; - // eslint-disable-next-line consistent-return - return resulStr; - } - - // eslint-disable-next-line class-methods-use-this - getPartnerLevelParams(portal) { - const partnerLevel = getPartnerDataCookieValue(portal, 'level'); - const partnerTagBase = `"caas:adobe-partners/${portal}/partner-level/`; - return partnerLevel ? `(${partnerTagBase}${partnerLevel}"+OR+${partnerTagBase}public")` : `(${partnerTagBase}public")`; - } - initUrlSearchParams() { // eslint-disable-next-line no-restricted-globals const { search } = location || window.location; @@ -264,9 +216,11 @@ export default class PartnerCards extends LitElement { return html`${repeat( this.paginatedCards, (card) => card.id, - (card) => html``, + (card) => html``, )}`; } + + // eslint-disable-next-line getter-return consistent-return return html`
${this.blockData.localizedText['{{no-results-title}}']}

${this.blockData.localizedText['{{no-results-description}}']}

@@ -558,6 +512,7 @@ export default class PartnerCards extends LitElement { } // eslint-disable-next-line consistent-return return selectedFiltersKeys.every((key) => cardArbitraryArr.some((arbitraryTag) => { + if (!arbitraryTag.value || !arbitraryTag.key) return false; const arbitraryTagKeyStr = arbitraryTag.key.trim().toLowerCase().replaceAll(' ', '-'); const arbitraryTagValueStr = arbitraryTag.value.trim().toLowerCase().replaceAll(' ', '-'); if (key === arbitraryTagKeyStr) { @@ -719,6 +674,8 @@ export default class PartnerCards extends LitElement { /* eslint-disable indent */ render() { return html` + ${this.fetchedData + ? html`
@@ -798,9 +755,9 @@ export default class PartnerCards extends LitElement { : '' }
-
+
` : ''} - ${this.mobileView + ${this.mobileView && this.fetchedData ? html`
diff --git a/eds/components/PartnerCardsStyles.js b/eds/components/PartnerCardsStyles.js index c63f2d5..aa1e5d8 100644 --- a/eds/components/PartnerCardsStyles.js +++ b/eds/components/PartnerCardsStyles.js @@ -557,7 +557,7 @@ export const partnerCardsStyles = css` @media screen and (max-width: 1200px) { .all-filters-wrapper-mobile.open { position: fixed; - z-index: 10; + z-index: 10000000; display: flex; flex-direction: column; width: 100%; @@ -974,3 +974,137 @@ export const partnerCardsDateFilterStyles = css` height: 12px; } `; + +export const singlePartnerCardStyles = css` + .single-partner-card * { + box-sizing: border-box; + } + + .single-partner-card { + display: flex; + flex-direction: column; + background-color: #fff; + border: 1px solid ${borderColor}; + border-radius: 4px; + overflow: hidden; + width: 100%; + height: 400px; + } + + .single-partner-card:hover { + box-shadow: 0 3px 6px 0 rgba(0,0,0,.16); + transition: box-shadow .3s ease-in-out; + } + + .single-partner-card .card-header { + min-height: 192px; + max-height: 192px; + background-color: #323232; + background-repeat: no-repeat; + background-position: 50% 50%; + background-size: cover; + border-top-left-radius: 4px; + border-top-right-radius: 4px; + position: relative; + } + + .single-partner-card:hover .card-header:after { + opacity: 1; + } + + .single-partner-card .card-header:after { + position: absolute; + content: ""; + top: 0; + bottom: 0; + left: 0; + right: 0; + margin: auto; + z-index: 0; + background-color: rgba(0,0,0,.35); + opacity: 0; + transition: opacity .3s ease-in-out; + } + + .single-partner-card .card-content { + display: flex; + flex-direction: column; + justify-content: space-between; + background-color: #fff; + padding: 16px 16px 20px; + height: 100%; + } + + .single-partner-card .card-title { + color: #323232; + font-size: 1.125rem; + font-weight: 700; + line-height: 1.375rem; + word-break: break-word; + max-height: 2.75rem; + margin: 0 0 7px; + display: -webkit-box; + -webkit-box-orient: vertical; + overflow: hidden; + -webkit-line-clamp: 2; + } + + .single-partner-card .card-description { + color: #505050; + font-size: .875rem; + line-height: 1.3125rem; + font-weight: 400; + word-break: break-word; + margin: 0 0 14px; + max-height: 3.9375rem; + display: -webkit-box; + -webkit-box-orient: vertical; + overflow: hidden; + -webkit-line-clamp: 3; + } + + .single-partner-card .card-footer { + display: flex; + justify-content: space-between; + align-items: center; + } + + .single-partner-card .card-btn { + display: flex; + justify-content: center; + align-items: center; + font-size: .875rem; + line-height: 1.063rem; + font-weight: 700; + min-width: 60px; + max-width: 100%; + height: 28px; + max-height: 32px; + margin-left: 16px; + padding-left: 14px; + padding-right: 14px; + text-decoration: none; + color: #222222; + border: 2px solid #222222; + border-radius: 16px; + background-color: #ffffff00; + cursor: pointer; + transition: border-color .3s ease-in-out,background-color .3s ease-in-out; + } + + .single-partner-card .card-btn:hover { + text-decoration: none; + border-color: #222222; + background-color: #222222; + color: #ffffff; + } + + .single-partner-card .card-date { + color: #747474; + font-size: .875rem; + line-height: 1.3125rem; + word-break: break-word; + max-height: 3.9375rem; + padding: 0; + } +`; diff --git a/eds/components/NewsCard.js b/eds/components/SinglePartnerCard.js similarity index 74% rename from eds/components/NewsCard.js rename to eds/components/SinglePartnerCard.js index 289bc82..2b84690 100644 --- a/eds/components/NewsCard.js +++ b/eds/components/SinglePartnerCard.js @@ -1,15 +1,16 @@ -import { newsCardStyles } from './NewsCardStyles.js'; +import { singlePartnerCardStyles } from './PartnerCardsStyles.js'; import { formatDate, getLibs, prodHosts } from '../scripts/utils.js'; const miloLibs = getLibs(); const { html, LitElement } = await import(`${miloLibs}/deps/lit-all.min.js`); const DEFAULT_BACKGROUND_IMAGE_PATH = '/content/dam/solution/en/images/card-collection/sample_default.png'; +const KB_TAG = 'caas:adobe-partners/collections/knowledge-base'; -class NewsCard extends LitElement { +class SinglePartnerCard extends LitElement { static properties = { data: { type: Object } }; - static styles = newsCardStyles; + static styles = singlePartnerCardStyles; // eslint-disable-next-line class-methods-use-this transformCardUrl(url) { @@ -26,8 +27,13 @@ class NewsCard extends LitElement { return newUrl; } + get imageUrl() { + const isKB = this.data?.tags.some((tag) => tag.id === KB_TAG); + return isKB ? this.data.styles?.backgroundImage : `${new URL(this.data.styles?.backgroundImage).pathname}?width=400&format=webp&optimize=small`; + } + checkBackgroundImage(element) { - const url = this.data.styles?.backgroundImage; + const url = this.imageUrl; const img = new Image(); const isProd = prodHosts.includes(window.location.host); @@ -47,8 +53,8 @@ class NewsCard extends LitElement { render() { return html` -
-
+
+

${this.data.contentArea?.title !== 'card-metadata' ? this.data.contentArea?.title : ''}

@@ -63,4 +69,4 @@ class NewsCard extends LitElement { `; } } -customElements.define('news-card', NewsCard); +customElements.define('single-partner-card', SinglePartnerCard); diff --git a/eds/scripts/scripts.js b/eds/scripts/scripts.js index 873d207..390ef7f 100644 --- a/eds/scripts/scripts.js +++ b/eds/scripts/scripts.js @@ -10,7 +10,8 @@ * governing permissions and limitations under the License. */ -import {prodHosts, setLibs} from './utils.js'; +import { prodHosts, setLibs, preloadResources } from './utils.js'; +// import PartnerNews from '../blocks/partner-news/PartnerNews.js'; // Add project-wide style path here. const STYLES = ''; @@ -18,8 +19,6 @@ const STYLES = ''; // Use 'https://milo.adobe.com/libs' if you cannot map '/libs' to milo's origin. const LIBS = '/libs'; - - const imsClientId = prodHosts.includes(window.location.host) ? 'MILO_PARTNERS_PROD' : 'MILO_PARTNERS_STAGE'; // Add any config options. @@ -68,6 +67,8 @@ const miloLibs = setLibs(LIBS); }()); (async function loadPage() { + await preloadResources(CONFIG.locales, miloLibs); + const { loadArea, setConfig } = await import(`${miloLibs}/utils/utils.js`); setConfig({ ...CONFIG, miloLibs }); diff --git a/eds/scripts/utils.js b/eds/scripts/utils.js index 29a4f77..941e232 100644 --- a/eds/scripts/utils.js +++ b/eds/scripts/utils.js @@ -44,18 +44,6 @@ export const prodHosts = [ * ------------------------------------------------------------ */ -export async function useMiloSample() { - const { createTag } = await import(`${getLibs()}/utils/utils.js`); -} - -const miloLibs = setLibs('/libs'); - -const { createTag, localizeLink, getConfig } = await import(`${miloLibs}/utils/utils.js`); -export { createTag, localizeLink, getConfig }; - -const { replaceText } = await import(`${miloLibs}/features/placeholders.js`); -export { replaceText }; - export function populateLocalizedTextFromListItems(el, localizedText) { const liList = Array.from(el.querySelectorAll('li')); liList.forEach((liEl) => { @@ -82,6 +70,75 @@ export function formatDate(cardDate) { return formattedDate; } +export function getLocale(locales, pathname = window.location.pathname) { + if (!locales) { + return { ietf: 'en-US', tk: 'hah7vzn.css', prefix: '' }; + } + const LANGSTORE = 'langstore'; + const split = pathname.split('/'); + const localeString = split[1]; + const locale = locales[localeString] || locales['']; + if (localeString === LANGSTORE) { + locale.prefix = `/${localeString}/${split[2]}`; + if ( + Object.values(locales) + .find((loc) => loc.ietf?.startsWith(split[2]))?.dir === 'rtl' + ) locale.dir = 'rtl'; + return locale; + } + const isUS = locale.ietf === 'en-US'; + locale.prefix = isUS ? '' : `/${localeString}`; + locale.region = isUS ? 'us' : localeString.split('_')[0]; + return locale; +} + +function preload(url) { + const preloadLink = document.createElement('link'); + preloadLink.rel = 'preload'; + preloadLink.as = 'fetch'; + preloadLink.crossOrigin = true; + preloadLink.href = url; + document.head.appendChild(preloadLink); +} + +function preloadPlaceholders(locale) { + const placeholderUrl = `${locale.prefix}/eds/partners-shared/placeholders.json`; + preload(placeholderUrl); +} + +function preloadLit(miloLibs) { + const preloadLink = document.createElement('link'); + preloadLink.rel = 'modulepreload'; + preloadLink.crossOrigin = true; + preloadLink.href = `${miloLibs}/deps/lit-all.min.js`; + document.head.appendChild(preloadLink); +} + +export async function preloadResources(locales, miloLibs) { + const locale = getLocale(locales); + const cardBlocks = { + 'partner-news': '"caas:adobe-partners/collections/news"', + 'knowledge-base-overview': '"caas:adobe-partners/collections/knowledge-base"', + }; + + Object.entries(cardBlocks).forEach(async ([key, value]) => { + const el = document.querySelector(`.${key}`); + if (!el) return; + + preloadPlaceholders(locale); + preloadLit(miloLibs); + + const block = { + el, + name: key, + collectionTag: value, + ietf: locale.ietf, + }; + const caasUrl = getCaasUrl(block); + preload(caasUrl); + }); +} + export function getProgramType(path) { switch (true) { case /solutionpartners/.test(path): return 'spp'; @@ -113,3 +170,65 @@ export function getPartnerDataCookieValue(programType, key) { return ''; } } + +export function getCaasUrl(block) { + const useStageCaasEndpoint = block.name === 'knowledge-base-overview'; + const domain = `${(useStageCaasEndpoint && !prodHosts.includes(window.location.host)) ? 'https://14257-chimera-stage.adobeioruntime.net/api/v1/web/chimera-0.0.1' : 'https://www.adobe.com/chimera-api'}`; + const api = new URL(`${domain}/collection?originSelection=dx-partners&draft=false&debug=true&flatFile=false&expanded=true`); + return setApiParams(api, block); +} + +function setApiParams(api, block) { + const { el, collectionTag } = block; + const complexQueryParams = getComplexQueryParams(el, collectionTag); + if (complexQueryParams) api.searchParams.set('complexQuery', complexQueryParams); + + const [language, country] = block.ietf.split('-'); + if (language && country) { + api.searchParams.set('language', language); + api.searchParams.set('country', country); + } + + return api.toString(); +} + +function extractTableCollectionTags(el) { + let tableCollectionTags = []; + Array.from(el.children).forEach((row) => { + const cols = Array.from(row.children); + const rowTitle = cols[0].innerText.trim().toLowerCase().replace(/ /g, '-'); + const colsContent = cols.slice(1); + if (rowTitle === 'collection-tags') { + const [collectionTagsEl] = colsContent; + const collectionTags = Array.from(collectionTagsEl.querySelectorAll('li'), (li) => `"${li.innerText.trim().toLowerCase()}"`); + tableCollectionTags = [...tableCollectionTags, ...collectionTags]; + } + }); + + return tableCollectionTags; +} + +function getComplexQueryParams(el, collectionTag) { + const portal = getCurrentProgramType(); + if (!portal) return; + + const portalCollectionTag = `"caas:adobe-partners/${portal}"`; + const tableTags = extractTableCollectionTags(el); + const collectionTags = [collectionTag, portalCollectionTag, ...tableTags]; + + const partnerLevelParams = getPartnerLevelParams(portal); + + if (!collectionTags.length) return; + + const collectionTagsStr = collectionTags.filter((e) => e.length).join('+AND+'); + let resulStr = `(${collectionTagsStr})`; + if (partnerLevelParams) resulStr += `+AND+${partnerLevelParams}`; + // eslint-disable-next-line consistent-return + return resulStr; +} + +function getPartnerLevelParams(portal) { + const partnerLevel = getPartnerDataCookieValue(portal, 'level'); + const partnerTagBase = `"caas:adobe-partners/${portal}/partner-level/`; + return partnerLevel ? `(${partnerTagBase}${partnerLevel}"+OR+${partnerTagBase}public")` : `(${partnerTagBase}public")`; +} diff --git a/test/blocks/knowledge-base-overview/knowledge-base-overview.test.js b/test/blocks/knowledge-base-overview/knowledge-base-overview.test.js index d1d8055..008195c 100644 --- a/test/blocks/knowledge-base-overview/knowledge-base-overview.test.js +++ b/test/blocks/knowledge-base-overview/knowledge-base-overview.test.js @@ -16,6 +16,7 @@ describe('knowledge-base-overview block', () => { this.cards = cards; this.paginatedCards = this.cards.slice(0, 3); this.hasResponseData = true; + this.fetchedData = true; }); await import('../../../eds/scripts/scripts.js'); @@ -40,7 +41,7 @@ describe('knowledge-base-overview block', () => { expect(knowledgeBaseWrapper.shadowRoot).to.exist; const partnerCardsCollection = knowledgeBaseWrapper.shadowRoot.querySelector('.partner-cards-collection'); expect(partnerCardsCollection).to.exist; - expect(partnerCardsCollection.innerHTML).to.include('news-card'); + expect(partnerCardsCollection.innerHTML).to.include('single-partner-card'); const firstCard = partnerCardsCollection.querySelector('.card-wrapper'); expect(firstCard.shadowRoot).to.exist; const searchBarWrapper = knowledgeBaseWrapper.shadowRoot.querySelector('.partner-cards-sidebar .search-wrapper'); diff --git a/test/blocks/partner-news/partner-news.test.js b/test/blocks/partner-news/partner-news.test.js index 875484b..820ab61 100644 --- a/test/blocks/partner-news/partner-news.test.js +++ b/test/blocks/partner-news/partner-news.test.js @@ -16,6 +16,7 @@ describe('partner-news block', () => { this.cards = cards; this.paginatedCards = this.cards.slice(0, 3); this.hasResponseData = true; + this.fetchedData = true; }); await import('../../../eds/scripts/scripts.js'); @@ -40,7 +41,7 @@ describe('partner-news block', () => { expect(partnerNewsWrapper.shadowRoot).to.exist; const partnerCardsCollection = partnerNewsWrapper.shadowRoot.querySelector('.partner-cards-collection'); expect(partnerCardsCollection).to.exist; - expect(partnerCardsCollection.innerHTML).to.include('news-card'); + expect(partnerCardsCollection.innerHTML).to.include('single-partner-card'); const firstCard = partnerCardsCollection.querySelector('.card-wrapper'); expect(firstCard.shadowRoot).to.exist; const searchBarWrapper = partnerNewsWrapper.shadowRoot.querySelector('.partner-cards-sidebar .search-wrapper');