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

moving announcments filter to announcements from partnerCards #161

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -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
Loading