diff --git a/.eslintrc.js b/.eslintrc.cjs
similarity index 100%
rename from .eslintrc.js
rename to .eslintrc.cjs
diff --git a/.github/workflows/run-nala.yml b/.github/workflows/run-nala.yml
index 03dcbb7..960fc1e 100644
--- a/.github/workflows/run-nala.yml
+++ b/.github/workflows/run-nala.yml
@@ -24,3 +24,4 @@ jobs:
prRepo: ${{ github.event.pull_request.head.repo.name }}
prBranch: ${{ github.event.pull_request.head.ref }}
prBaseBranch: ${{ github.event.pull_request.base.ref }}
+ HLX_API_KEY: ${{ secrets.HLX_API_KEY }}
diff --git a/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js b/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js
index ec82dfa..f5305ca 100644
--- a/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js
+++ b/eds/blocks/knowledge-base-overview/KnowledgeBaseOverview.js
@@ -1,93 +1,3 @@
-import { getLibs } from '../../scripts/utils.js';
-import { numericPaginationStyles } from '../../components/PartnerCardsStyles.js';
import PartnerCardsWithDateFilter from '../../components/PartnerCardsWithDateFilter.js';
-const miloLibs = getLibs();
-const { html, css, repeat } = await import(`${miloLibs}/deps/lit-all.min.js`);
-
-export default class KnowledgeBaseOverview extends PartnerCardsWithDateFilter {
- static properties = {
- ...PartnerCardsWithDateFilter.properties,
- totalPages: { type: Number },
- };
-
- constructor() {
- super();
- this.totalPages = 0;
- this.useStageCaasEndpoint = true;
- }
-
- static styles = [
- PartnerCardsWithDateFilter.styles,
- css`${numericPaginationStyles}`,
- ];
-
- get paginationList() {
- if (!this.cards.length) return;
-
- const min = 1;
- this.totalPages = Math.ceil(this.cards.length / this.cardsPerPage);
-
- const pagesNumArray = Array.from({ length: this.totalPages }, (_, i) => i + min);
- return html`${repeat(
- pagesNumArray,
- (pageNum) => pageNum,
- (pageNum) => html``,
- )}`;
- }
-
- get pagination() {
- return html`
-
- `;
- }
-
- get cardsCounter() {
- const lastElOrderNum = super.cardsCounter;
- const { orderNum: firstElOrderNum } = this.paginatedCards[0];
- return `${firstElOrderNum} - ${lastElOrderNum}`;
- }
-
- handleActions() {
- super.handleActions();
- this.updatePaginatedCards();
- }
-
- updatePaginatedCards() {
- const startIndex = (this.paginationCounter - 1) * this.cardsPerPage;
- const endIndex = this.paginationCounter * this.cardsPerPage;
- this.paginatedCards = this.cards.slice(startIndex, endIndex);
- }
-
- handlePageNum(pageNum) {
- if (this.paginationCounter !== pageNum) {
- this.paginationCounter = pageNum;
- this.handleActions();
- }
- }
-
- handlePrevPage() {
- if (this.paginationCounter > 1) {
- this.paginationCounter -= 1;
- this.handleActions();
- }
- }
-
- handleNextPage() {
- if (this.paginationCounter < this.totalPages) {
- this.paginationCounter += 1;
- this.handleActions();
- }
- }
-}
+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 240bd68..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() {
@@ -33,6 +34,7 @@ export default async function init(el) {
'{{last-6-months}}': 'Last 6 months',
'{{next}}': 'Next',
'{{next-page}}': 'Next Page',
+ '{{load-more}}': 'Load more',
'{{no-results-description}}': 'Try checking your spelling or broadening your search.',
'{{no-results-title}}': 'No Results Found',
'{{of}}': 'Of',
@@ -69,13 +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/PartnerNews.js b/eds/blocks/partner-news/PartnerNews.js
index e2a11e5..e9fb6d0 100644
--- a/eds/blocks/partner-news/PartnerNews.js
+++ b/eds/blocks/partner-news/PartnerNews.js
@@ -1,35 +1,3 @@
-import { getLibs } from '../../scripts/utils.js';
-import { loadMorePaginationStyles } from '../../components/PartnerCardsStyles.js';
import PartnerCardsWithDateFilter from '../../components/PartnerCardsWithDateFilter.js';
-const miloLibs = getLibs();
-const { html, css } = await import(`${miloLibs}/deps/lit-all.min.js`);
-
-export default class PartnerNews extends PartnerCardsWithDateFilter {
- static styles = [
- PartnerCardsWithDateFilter.styles,
- css`${loadMorePaginationStyles}`,
- ];
-
- get pagination() {
- if (this.cards.length === this.paginatedCards.length) {
- return '';
- }
- return html``;
- }
-
- handleActions() {
- super.handleActions();
- this.updatePaginatedCards();
- }
-
- updatePaginatedCards() {
- const countPages = this.paginationCounter * this.cardsPerPage;
- this.paginatedCards = this.cards.slice(0, countPages);
- }
-
- handleLoadMore() {
- this.paginationCounter += 1;
- this.handleActions();
- }
-}
+export default class PartnerNews extends PartnerCardsWithDateFilter {}
diff --git a/eds/blocks/partner-news/partner-news.js b/eds/blocks/partner-news/partner-news.js
index 05e2f61..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() {
@@ -32,10 +33,15 @@ export default async function init(el) {
'{{filters}}': 'Filters',
'{{last-90-days}}': 'Last 90 days',
'{{load-more}}': 'Load more',
+ '{{next}}': 'Next',
+ '{{next-page}}': 'Next Page',
'{{no-results-description}}': 'Try checking your spelling or broadening your search.',
'{{no-results-title}}': 'No Results Found',
'{{of}}': 'Of',
+ '{{page}}': 'Page',
+ '{{prev}}': 'Prev',
'{{previous-month}}': 'Previous month',
+ '{{previous-page}}': 'Previous Page',
'{{results}}': 'Results',
'{{search}}': 'Search',
'{{show-all}}': 'Show all',
@@ -65,13 +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/NewsCard.js b/eds/components/NewsCard.js
deleted file mode 100644
index 362fe88..0000000
--- a/eds/components/NewsCard.js
+++ /dev/null
@@ -1,44 +0,0 @@
-import { newsCardStyles } from './PartnerCardsStyles.js';
-import { formatDate, getLibs } from '../scripts/utils.js';
-
-const miloLibs = getLibs();
-const { html, LitElement } = await import(`${miloLibs}/deps/lit-all.min.js`);
-
-class NewsCard extends LitElement {
- static properties = { data: { type: Object } };
-
- static styles = newsCardStyles;
-
- transformCardUrl(url) {
- if (!url) {
- console.error('URL is null or undefined');
- return '';
- }
- if (window.location.host === 'partners.adobe.com') {
- return url;
- }
- const newUrl = new URL(url);
- newUrl.protocol = window.location.protocol;
- newUrl.host = window.location.host;
- return newUrl;
- }
-
- render() {
- return html`
-
-
-
-
-
${this.data.contentArea?.title !== 'card-metadata' ? this.data.contentArea?.title : ''}
-
${this.data.contentArea?.description}
-
-
-
-
- `;
- }
-}
-customElements.define('news-card', NewsCard);
diff --git a/eds/components/PartnerCards.js b/eds/components/PartnerCards.js
index 0488c8f..a7c3c69 100644
--- a/eds/components/PartnerCards.js
+++ b/eds/components/PartnerCards.js
@@ -1,17 +1,27 @@
-import { getLibs, prodHosts } from '../scripts/utils.js';
-import { partnerCardsStyles } from './PartnerCardsStyles.js';
-import './NewsCard.js';
+import {
+ getLibs,
+} from '../scripts/utils.js';
+import {
+ partnerCardsStyles,
+ partnerCardsLoadMoreStyles,
+ partnerCardsPaginationStyles,
+} from './PartnerCardsStyles.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 styles = css`
- ${partnerCardsStyles}
- #search {
+ static caasUrl;
+
+ static styles = [
+ partnerCardsStyles,
+ partnerCardsLoadMoreStyles,
+ partnerCardsPaginationStyles,
+ css`#search {
width: 100%;
- }
- `;
+ }`,
+ ];
static properties = {
blockData: { type: Object },
@@ -19,11 +29,12 @@ export default class PartnerCards extends LitElement {
paginatedCards: { type: Array },
searchTerm: { type: String },
paginationCounter: { type: Number },
+ totalPages: { type: Number },
selectedSortOrder: { type: Object },
selectedFilters: { type: Object },
urlSearchParams: { type: Object },
mobileView: { type: Boolean },
- useStageCaasEndpoint: { type: Boolean },
+ fetchedData: { type: Boolean },
};
constructor() {
@@ -33,12 +44,13 @@ export default class PartnerCards extends LitElement {
this.paginatedCards = [];
this.searchTerm = '';
this.paginationCounter = 1;
+ this.totalPages = 0;
this.cardsPerPage = 12;
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);
}
@@ -58,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;
@@ -72,7 +80,12 @@ export default class PartnerCards extends LitElement {
filter: (cols) => {
const [filterKeyEl, filterTagsKeysEl] = cols;
const filterKey = filterKeyEl.innerText.trim().toLowerCase().replace(/ /g, '-');
- const filterTagsKeys = Array.from(filterTagsKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase().replace(/ /g, '-'));
+
+ const filterTagsKeys = [];
+ filterTagsKeysEl.querySelectorAll('li').forEach((li) => {
+ const key = li.innerText.trim().toLowerCase().replace(/ /g, '-');
+ if (key !== '') filterTagsKeys.push(key);
+ });
if (!filterKey || !filterTagsKeys.length) return;
@@ -90,7 +103,14 @@ export default class PartnerCards extends LitElement {
},
sort: (cols) => {
const [sortKeysEl] = cols;
- const sortKeys = Array.from(sortKeysEl.querySelectorAll('li'), (li) => li.innerText.trim().toLowerCase().replace(/ /g, '-'));
+
+ const sortKeys = [];
+ sortKeysEl.querySelectorAll('li').forEach((li) => {
+ const key = li.innerText.trim().toLowerCase().replace(/ /g, '-');
+ if (key !== '') sortKeys.push(key);
+ });
+
+ if (!sortKeys.length) return;
const sortItems = sortKeys.map((sortKey) => {
const key = sortKey.endsWith('_default') ? sortKey.slice(0, -8) : sortKey;
@@ -98,9 +118,11 @@ export default class PartnerCards extends LitElement {
return { key, value };
});
- const defaultKey = sortKeys.find((key) => key.endsWith('_default')).slice(0, -8) || sortKeys[0];
- const defaultValue = sortItems.find((e) => e.key === defaultKey).value;
- this.blockData.sort = { items: sortItems, default: { key: defaultKey, value: defaultValue } };
+ const defaultKey = sortKeys.find((key) => key.endsWith('_default'));
+ const finalDefaultKey = defaultKey ? defaultKey.slice(0, -8) : sortKeys[0];
+ const defaultValue = sortItems.find((e) => e.key === finalDefaultKey).value;
+ // eslint-disable-next-line max-len
+ this.blockData.sort = { items: sortItems, default: { key: finalDefaultKey, value: defaultValue } };
},
'cards-per-page': (cols) => {
const [cardsPerPageEl] = cols;
@@ -108,10 +130,10 @@ 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()}"`);
- this.collectionTags = [...this.collectionTags, ...collectionTags];
+ pagination: (cols) => {
+ const [paginationEl] = cols;
+ const paginationType = paginationEl.innerText.trim();
+ if (paginationType) this.blockData.pagination = paginationType.toLowerCase().replace(/ /g, '-');
},
};
@@ -122,10 +144,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() {
@@ -142,22 +160,30 @@ export default class PartnerCards extends LitElement {
this.handleActions();
}
+ // eslint-disable-next-line class-methods-use-this
additionalFirstUpdated() {}
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/'));
}
+ // eslint-disable-next-line no-return-assign
apiData.cards.forEach((card, index) => card.orderNum = index + 1);
this.allCards = apiData.cards;
this.cards = apiData.cards;
@@ -169,67 +195,8 @@ 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 = this.getProgramType(window.location.pathname);
- let partnerLevelParams;
-
- if (portal) {
- const portalCollectionTag = `"caas:adobe-partners/${portal}"`;
- if (!this.collectionTags.length || !this.collectionTags.includes(portalCollectionTag)) {
- this.collectionTags = [...this.collectionTags, portalCollectionTag];
- }
-
- partnerLevelParams = this.getPartnerLevelParams(portal);
- }
-
- if (!this.collectionTags.length) return;
-
- const collectionTagsStr = this.collectionTags.filter((e) => e.length).join('+AND+');
- return partnerLevelParams ? `((${collectionTagsStr}))+AND+${partnerLevelParams}` : `((${collectionTagsStr}))`;
- }
-
- getPartnerLevelParams(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(decodeURIComponent(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() {
+ // eslint-disable-next-line no-restricted-globals
const { search } = location || window.location;
this.urlSearchParams = new URLSearchParams(search);
@@ -259,9 +226,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}}']}
@@ -271,6 +240,7 @@ export default class PartnerCards extends LitElement {
get sortItems() {
if (!this.blockData.sort.items.length) return;
+ // eslint-disable-next-line consistent-return
return html`${repeat(
this.blockData.sort.items,
(item) => item.key,
@@ -283,21 +253,65 @@ export default class PartnerCards extends LitElement {
)}`;
}
- get pagination() {}
+ // eslint-disable-next-line class-methods-use-this,no-empty-function,getter-return
+ get pagination() {
+ if (this.blockData.pagination === 'load-more') return this.loadMorePagination;
+ return this.defaultPagination;
+ }
+
+ get loadMorePagination() {
+ if (this.cards.length === this.paginatedCards.length) return '';
+ return html`
`;
+ }
+
+ get defaultPagination() {
+ return html`
+
+ `;
+ }
+
+ get paginationList() {
+ if (!this.cards.length) return;
+
+ const min = 1;
+ this.totalPages = Math.ceil(this.cards.length / this.cardsPerPage);
+
+ const pagesNumArray = Array.from({ length: this.totalPages }, (_, i) => i + min);
+ // eslint-disable-next-line consistent-return
+ return html`${repeat(
+ pagesNumArray,
+ (pageNum) => pageNum,
+ (pageNum) => html``,
+ )}`;
+ }
get cardsCounter() {
- if (!this.paginatedCards.length) {
- return 0;
- }
+ const { length } = this.paginatedCards;
+ if (!length) return 0;
- const lastIndex = this.paginatedCards.length - 1;
- const { orderNum: lastElOrderNum } = this.paginatedCards[lastIndex];
- return lastElOrderNum;
+ const { orderNum: lastElOrderNum } = this.paginatedCards[length - 1];
+
+ if (this.blockData.pagination === 'load-more') return lastElOrderNum;
+
+ const { orderNum: firstElOrderNum } = this.paginatedCards[0];
+ return `${firstElOrderNum} - ${lastElOrderNum}`;
}
get filters() {
if (!this.blockData.filters.length) return;
+ // eslint-disable-next-line consistent-return
return html`${repeat(
this.blockData.filters,
(filter) => filter.key,
@@ -309,7 +323,7 @@ export default class PartnerCards extends LitElement {