Skip to content

Commit

Permalink
MWPW-163708-filter-cards-by-site
Browse files Browse the repository at this point in the history
Restrict announcements to current site
eslint fix for search-full in path
  • Loading branch information
cod17828 committed Dec 9, 2024
1 parent 86373a3 commit cf61928
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions edsdme/blocks/announcements-preview/announcements-preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCaasUrl } from '../../scripts/utils.js';
import { getConfig } from '../utils/utils.js';
import { filterRestrictedCardsByCurrentSite } from '../../components/PartnerCards.js';

function addAnnouncement(cardData) {
const linkWrapper = document.createElement('a');
Expand Down Expand Up @@ -62,6 +63,8 @@ async function fetchData(blockData, newestCards) {
apiData = await response.json();

if (apiData?.cards) {
// Filter announcements by current site
apiData.cards = filterRestrictedCardsByCurrentSite(apiData.cards);
apiData.cards.forEach((card) => {
const cardDate = new Date(card.cardDate);
if (newestCards.length < 3) {
Expand Down
2 changes: 1 addition & 1 deletion edsdme/blocks/logos/LogosCards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getLibs } from '../../scripts/utils.js';
import PartnerCards from '../../components/PartnerCards.js';
import { searchCardsStyles } from '../search/SearchCardsStyles.js';
import { searchCardsStyles } from '../search-full/SearchCardsStyles.js';
import '../../components/SearchCard.js';
import { generateRequestForSearchAPI } from '../utils/utils.js';

Expand Down
12 changes: 12 additions & 0 deletions edsdme/components/PartnerCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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;
const cardSite = new URL(cardUrl).pathname.split('/')[1];
return currentSite === cardSite;
});
}

export default class PartnerCards extends LitElement {
static styles = [
partnerCardsStyles,
Expand Down Expand Up @@ -185,6 +195,8 @@ 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 cf61928

Please sign in to comment.