Skip to content

Commit 772f686

Browse files
authored
filter article card categories using includedCategories (#58465)
1 parent 55b7bb0 commit 772f686

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/landings/components/shared/LandingArticleGridWithFilter.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ export const ArticleGrid = ({ tocItems, includedCategories, landingType }: Artic
235235
{/* Results Grid */}
236236
<div className={styles.articleGrid} data-testid="article-grid">
237237
{paginatedResults.map((article, index) => (
238-
<ArticleCard key={startIndex + index} article={article} />
238+
<ArticleCard
239+
key={startIndex + index}
240+
article={article}
241+
includedCategories={includedCategories}
242+
/>
239243
))}
240244
{filteredResults.length === 0 && (
241245
<div className={styles.noArticlesContainer} data-testid="no-articles-message">
@@ -269,9 +273,18 @@ export const ArticleGrid = ({ tocItems, includedCategories, landingType }: Artic
269273

270274
type ArticleCardProps = {
271275
article: ChildTocItem
276+
includedCategories?: string[]
272277
}
273278

274-
const ArticleCard = ({ article }: ArticleCardProps) => {
279+
const ArticleCard = ({ article, includedCategories }: ArticleCardProps) => {
280+
// Filter categories to only show those in includedCategories (if provided and not empty)
281+
const displayCategories =
282+
includedCategories && includedCategories.length > 0 && article.category
283+
? article.category.filter((cat) =>
284+
includedCategories.some((included) => included.toLowerCase() === cat.toLowerCase()),
285+
)
286+
: article.category
287+
275288
return (
276289
<Link
277290
href={article.fullPath}
@@ -285,8 +298,8 @@ const ArticleCard = ({ article }: ArticleCardProps) => {
285298
data-testid="article-card"
286299
>
287300
<div className={styles.tagsContainer}>
288-
{article.category &&
289-
article.category.map((cat) => <Token key={cat} text={cat} className="mr-1 mb-2" />)}
301+
{displayCategories &&
302+
displayCategories.map((cat) => <Token key={cat} text={cat} className="mr-1 mb-2" />)}
290303
</div>
291304

292305
<h3 className={styles.cardTitle}>

0 commit comments

Comments
 (0)