Skip to content

Commit

Permalink
Merge pull request #161 from adobecom/announcments-filter-fix
Browse files Browse the repository at this point in the history
moving announcments filter to announcements from partnerCards
  • Loading branch information
cod17828 authored Dec 11, 2024
2 parents 1c52275 + cf9c116 commit b931b37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCaasUrl } from '../../scripts/utils.js';
import { getConfig } from '../utils/utils.js';
import { filterRestrictedCardsByCurrentSite } from '../../components/PartnerCards.js';
import { filterRestrictedCardsByCurrentSite } from '../announcements/AnnouncementsCards.js';

function formatLinks(link) {
const { hostname, pathname } = new URL(link);
Expand Down
21 changes: 21 additions & 0 deletions edsdme/blocks/announcements/AnnouncementsCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ import PartnerCards from '../../components/PartnerCards.js';
const miloLibs = getLibs();
const { html, repeat } = await import(`${miloLibs}/deps/lit-all.min.js`);

export function filterRestrictedCardsByCurrentSite(cards) {
const currentSite = window.location.pathname.split('/')[1];
return cards.filter((card) => {
const cardUrl = card?.contentArea?.url;
if (!cardUrl) return false;
try {
const cardSite = new URL(cardUrl).pathname.split('/')[1];
return currentSite === cardSite;
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Invalid URL: ${cardUrl}`, error);
return false;
}
});
}

export default class Announcements extends PartnerCards {
static styles = [
PartnerCards.styles,
Expand Down Expand Up @@ -233,4 +249,9 @@ export default class Announcements extends PartnerCards {
});
}
}

onDataFetched(apiData) {
// Filter announcements by current site
this.cards = filterRestrictedCardsByCurrentSite(apiData.cards);
}
}
18 changes: 0 additions & 18 deletions edsdme/components/PartnerCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ import './SinglePartnerCard.js';
const miloLibs = getLibs();
const { html, LitElement, css, repeat } = await import(`${miloLibs}/deps/lit-all.min.js`);

export function filterRestrictedCardsByCurrentSite(cards) {
const currentSite = window.location.pathname.split('/')[1];
return cards.filter((card) => {
const cardUrl = card?.contentArea?.url;
if (!cardUrl) return false;
try {
const cardSite = new URL(cardUrl).pathname.split('/')[1];
return currentSite === cardSite;
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Invalid URL: ${cardUrl}`, error);
return false;
}
});
}

export default class PartnerCards extends LitElement {
static styles = [
partnerCardsStyles,
Expand Down Expand Up @@ -239,8 +223,6 @@ export default class PartnerCards extends LitElement {
if (window.location.hostname === 'partners.adobe.com') {
apiData.cards = apiData.cards.filter((card) => !card.contentArea.url?.includes('/drafts/'));
}
// Filter announcements by current site
apiData.cards = filterRestrictedCardsByCurrentSite(apiData.cards);
// eslint-disable-next-line no-return-assign
apiData.cards.forEach((card, index) => card.orderNum = index + 1);
this.allCards = apiData.cards;
Expand Down

0 comments on commit b931b37

Please sign in to comment.