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-151250: Implemented filtering cards by partner level #14

Merged
merged 15 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion eds/blocks/partner-news/partner-news.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
80 changes: 62 additions & 18 deletions eds/components/PartnerCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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];
}
}

Expand All @@ -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];
Expand All @@ -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}`);
}
Expand All @@ -222,12 +213,65 @@ 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 cookies = document.cookie.split(';').map(cookie => cookie.trim());
const partnerDataCookie = cookies.find(cookie => cookie.startsWith('partner_data='));
if (!partnerDataCookie) return `(("caas:adobe-partners/${portal}/partner-level/public"))`;

const {level} = JSON.parse(partnerDataCookie.substring(('partner_data=').length).toLowerCase());
if (!level) return `(("caas:adobe-partners/${portal}/partner-level/public"))`;

return `(("caas:adobe-partners/${portal}/partner-level/${level}")+OR+("caas:adobe-partners/${portal}/partner-level/public"))`;
} 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);
Expand Down Expand Up @@ -686,7 +730,7 @@ export class PartnerCards extends LitElement {
</div>
</div>
<div class="partner-cards-collection">
${this.allCards.length
${this.hasResponseData
? this.partnerCards
: html`
<div class="progress-circle-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('knowledge-base-overview block', () => {
sinon.stub(PartnerCards.prototype, 'firstUpdated').callsFake(async function() {
this.allCards = this.cards = cards;
this.paginatedCards = this.cards.slice(0, 3);
this.hasResponseData = true;
});

await import('./../../../eds/scripts/scripts.js');
Expand Down
1 change: 1 addition & 0 deletions test/blocks/partner-news/partner-news.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('partner-news block', () => {
sinon.stub(PartnerCards.prototype, 'firstUpdated').callsFake(async function() {
this.allCards = this.cards = cards;
this.paginatedCards = this.cards.slice(0, 3);
this.hasResponseData = true;
});

await import('./../../../eds/scripts/scripts.js');
Expand Down
Loading