diff --git a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js index 6a30ee3..0f96cd8 100644 --- a/eds/blocks/knowledge-base-overview/knowledge-base-overview.js +++ b/eds/blocks/knowledge-base-overview/knowledge-base-overview.js @@ -55,7 +55,8 @@ export default async function init(el) { 'localizedText': localizedText, 'tableData' : el.children, 'cardsPerPage': 9, - 'ietf': config.locale.ietf + 'ietf': config.locale.ietf, + 'collectionTags': 'caas:adobe-partners/collections/knowledge-base' } 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 0593e54..de63bbd 100644 --- a/eds/blocks/partner-news/partner-news.js +++ b/eds/blocks/partner-news/partner-news.js @@ -68,7 +68,8 @@ export default async function init(el) { 'tableData' : el.children, 'dateFilter': dateFilter, 'cardsPerPage': 12, - 'ietf': config.locale.ietf + 'ietf': config.locale.ietf, + 'collectionTags': 'caas:adobe-partners/collections/news' } const app = document.createElement('partner-news'); diff --git a/eds/components/PartnerCards.js b/eds/components/PartnerCards.js index dda38d6..abba8e5 100644 --- a/eds/components/PartnerCards.js +++ b/eds/components/PartnerCards.js @@ -89,6 +89,8 @@ export class PartnerCards extends LitElement { this.selectedSortOrder = {}; this.selectedFilters = {}; this.urlSearchParams = {}; + this.collectionTags = []; + this.hasResponseData = false; this.mobileView = window.innerWidth <= 1200; this.updateView = this.updateView.bind(this); } @@ -108,11 +110,12 @@ export class PartnerCards extends LitElement { 'default': {}, items: [] }, - 'collectionTags': '', 'language': '', 'country': '' }; + this.collectionTags = [ this.blockData.collectionTags ]; + const blockDataActions = { 'title': (cols) => { const [titleEl] = cols; @@ -162,8 +165,7 @@ export class PartnerCards extends LitElement { 'collection-tags': (cols) => { const [collectionTagsEl] = cols; const collectionTags = Array.from(collectionTagsEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase()); - const collectionTagsParamStr = collectionTags.filter(e => e.length).join(','); - this.blockData.collectionTags = collectionTagsParamStr; + this.collectionTags = [...this.collectionTags, ...collectionTags]; } } @@ -173,7 +175,7 @@ export class PartnerCards extends LitElement { const rowTitle = cols[0].innerText.trim().toLowerCase().replaceAll(' ', '-'); const colsContent = cols.slice(1); if (blockDataActions[rowTitle]) blockDataActions[rowTitle](colsContent); - }) + }); const ietfArr = this.blockData.ietf.split('-'); this.blockData.language = ietfArr[0]; @@ -196,19 +198,8 @@ export class PartnerCards extends LitElement { async fetchData() { try { const api = new URL('https://14257-chimera.adobeioruntime.net/api/v1/web/chimera-0.0.1/collection?originSelection=dx-partners&draft=false&debug=true&flatFile=false&expanded=true'); - - const { collectionTags, language, country } = this.blockData; - - if (collectionTags) { - api.searchParams.set('collectionTags', collectionTags); - } - - if (language && country) { - api.searchParams.set('language', language); - api.searchParams.set('country', country); - } - - const response = await fetch(api.toString()); + const apiWithParams = this.setApiParams(api); + const response = await fetch(apiWithParams); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } @@ -222,12 +213,68 @@ export class PartnerCards extends LitElement { apiData.cards.forEach((card, index) => card.orderNum = index + 1); this.allCards = this.cards = apiData.cards; this.paginatedCards = this.cards.slice(0, this.cardsPerPage); + this.hasResponseData = true; } } catch (error) { console.error('Error fetching data:', error); } } + setApiParams(api) { + const portal = this.getProgramType(window.location.pathname); + + if (portal) { + const portalCollectionTag = `caas:adobe-partners/${portal}`; + if (!this.collectionTags.length || !this.collectionTags.includes(portalCollectionTag)) { + this.collectionTags = [...this.collectionTags, portalCollectionTag]; + } + + const partnerDataComplexQueryParam = this.getPartnerDataComplexQueryParam(portal); + if (partnerDataComplexQueryParam) api.searchParams.set('complexQuery', partnerDataComplexQueryParam); + } + + if(this.collectionTags.length) { + const collectionTagsStr = this.collectionTags.filter(e => e.length).join(','); + api.searchParams.set('collectionTags', collectionTagsStr); + } + + const { language, country } = this.blockData; + if (language && country) { + api.searchParams.set('language', language); + api.searchParams.set('country', country); + } + + return api.toString(); + } + + getPartnerDataComplexQueryParam (portal) { + try { + const publicTag = `(("caas:adobe-partners/${portal}/partner-level/public"))`; + const cookies = document.cookie.split(';').map(cookie => cookie.trim()); + const partnerDataCookie = cookies.find(cookie => cookie.startsWith('partner_data=')); + if (!partnerDataCookie) return publicTag; + + const cookieValue = JSON.parse(partnerDataCookie.substring(('partner_data=').length).toLowerCase()); + if (cookieValue && cookieValue[portal]) { + const cookieLevel = cookieValue[portal].level; + if (cookieLevel) return `(("caas:adobe-partners/${portal}/partner-level/${cookieLevel}")+OR+("caas:adobe-partners/${portal}/partner-level/public"))`; + } + return publicTag; + } catch(error) { + console.error('Error parsing partner data object:', error); + return ''; + } + } + + getProgramType(path) { + switch(true) { + case /solutionpartners/.test(path): return 'spp'; + case /technologypartners/.test(path): return 'tpp'; + case /channelpartners/.test(path): return 'cpp'; + default: return ''; + } + } + initUrlSearchParams () { const { search } = location || window.location; this.urlSearchParams = new URLSearchParams(search); @@ -686,7 +733,7 @@ export class PartnerCards extends LitElement {