-
Notifications
You must be signed in to change notification settings - Fork 1
[DEV-3015] Add generic filtered grid #1738
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": minor | ||
--- | ||
|
||
Generalise filtered grid component |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,7 +18,7 @@ import { | |||||
} from '@/helpers/structuredData.helpers'; | ||||||
import { UseCase } from '@/lib/types/useCaseData'; | ||||||
import { getUseCaseListPageProps } from '@/lib/api'; | ||||||
import { UseCaseList } from '../../../components/organisms/UseCaseList/UseCaseList'; | ||||||
import { FilteredGridLayout } from '@/components/organisms/FilteredGridLayout/FilteredGridLayout'; | ||||||
|
||||||
export type UseCasesPageProps = { | ||||||
readonly product: Product; | ||||||
|
@@ -69,6 +69,25 @@ const UseCasesPage = async ({ params }: ProductParams) => { | |||||
seo: seo, | ||||||
}); | ||||||
|
||||||
const mappedUseCases = useCases.map((useCase) => { | ||||||
return { | ||||||
tags: useCase.tags || [], | ||||||
title: useCase.title, | ||||||
date: { | ||||||
date: useCase.publishedAt, | ||||||
}, | ||||||
href: { | ||||||
label: 'shared.readUseCase', | ||||||
link: useCase.path, | ||||||
translate: true, | ||||||
}, | ||||||
img: { | ||||||
alt: useCase.coverImage?.alternativeText || '', | ||||||
src: useCase.coverImage?.url || '/images/news.png', | ||||||
}, | ||||||
}; | ||||||
}); | ||||||
|
||||||
return ( | ||||||
<ProductLayout | ||||||
product={product} | ||||||
|
@@ -85,10 +104,11 @@ const UseCasesPage = async ({ params }: ProductParams) => { | |||||
/> | ||||||
)} | ||||||
{useCases && ( | ||||||
<UseCaseList | ||||||
<FilteredGridLayout | ||||||
items={mappedUseCases} | ||||||
tags={product.tags || []} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
useCases={useCases} | ||||||
enableFilters={enableFilters} | ||||||
noItemsMessageKey={'overview.useCases.noUseCaseMessage'} | ||||||
/> | ||||||
)} | ||||||
</ProductLayout> | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,9 @@ | ||||||
'use client'; | ||||||
|
||||||
import { Tag } from '@/lib/types/tag'; | ||||||
import Newsroom from '@/editorialComponents/Newsroom/Newsroom'; | ||||||
import Newsroom, { | ||||||
INewsroomItem, | ||||||
} from '@/editorialComponents/Newsroom/Newsroom'; | ||||||
import { Box, useMediaQuery } from '@mui/material'; | ||||||
import React, { useState } from 'react'; | ||||||
import { useTranslations } from 'next-intl'; | ||||||
|
@@ -12,21 +14,23 @@ import SectionTitle from '@/components/molecules/SectionTitle/SectionTitle'; | |||||
import { UseCase } from '@/lib/types/useCaseData'; | ||||||
import { PRODUCT_HEADER_HEIGHT } from '@/components/atoms/ProductHeader/ProductHeader'; | ||||||
|
||||||
type UseCaseListProps = { | ||||||
readonly useCases: readonly UseCase[]; | ||||||
type FilteredGridLayoutProps = { | ||||||
readonly items: readonly (INewsroomItem & { tags: readonly Tag[] })[]; | ||||||
readonly tags: readonly Tag[]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would put this optional
Suggested change
|
||||||
readonly enableFilters?: boolean; | ||||||
readonly noItemsMessageKey?: string; | ||||||
}; | ||||||
|
||||||
export const UseCaseList = ({ | ||||||
export const FilteredGridLayout = ({ | ||||||
tags, | ||||||
useCases, | ||||||
items, | ||||||
enableFilters, | ||||||
}: UseCaseListProps) => { | ||||||
noItemsMessageKey = '', | ||||||
}: FilteredGridLayoutProps) => { | ||||||
const t = useTranslations(); | ||||||
const updatedTags = [ | ||||||
{ | ||||||
name: t('overview.useCases.all'), | ||||||
name: t('overview.all'), | ||||||
icon: { | ||||||
data: { | ||||||
attributes: { | ||||||
|
@@ -53,17 +57,17 @@ export const UseCaseList = ({ | |||||
); | ||||||
const [selectedTag, setSelectedTag] = useState(tagValue); | ||||||
|
||||||
const filteredUseCases = useCases.filter((useCase) => { | ||||||
const filteredItems = items.filter((item) => { | ||||||
return ( | ||||||
selectedTag === 0 || | ||||||
useCase.tags?.some((tag) => tag.name === updatedTags[selectedTag].name) | ||||||
item.tags?.some((tag) => tag.name === updatedTags[selectedTag].name) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should already handle the null tags scenario |
||||||
); | ||||||
}); | ||||||
// eslint-disable-next-line functional/no-return-void | ||||||
const setSelectedTagFilter = (newTag: number): void => { | ||||||
if (newTag === selectedTag) return; | ||||||
addQueryParam('tag', `${newTag}`); | ||||||
const element = document.getElementById('use-case-list'); | ||||||
const element = document.getElementById('filtered-grid'); | ||||||
if (element) { | ||||||
const y = | ||||||
element.getBoundingClientRect().top + | ||||||
|
@@ -81,8 +85,8 @@ export const UseCaseList = ({ | |||||
}; | ||||||
const isSmallScreen = useMediaQuery('(max-width: 1000px)'); | ||||||
return ( | ||||||
<Box id='use-case-list'> | ||||||
<Box sx={{ paddingBottom: filteredUseCases.length > 0 ? '24px' : 0 }}> | ||||||
<Box id='filtered-grid'> | ||||||
<Box sx={{ paddingBottom: filteredItems.length > 0 ? '24px' : 0 }}> | ||||||
{enableFilters && | ||||||
tags.length > 0 && | ||||||
(isSmallScreen ? ( | ||||||
|
@@ -99,7 +103,7 @@ export const UseCaseList = ({ | |||||
/> | ||||||
))} | ||||||
</Box> | ||||||
{filteredUseCases.length <= 0 ? ( | ||||||
{filteredItems.length <= 0 ? ( | ||||||
<Box | ||||||
pt={8} | ||||||
pb={2} | ||||||
|
@@ -109,24 +113,12 @@ export const UseCaseList = ({ | |||||
alignItems: 'center', | ||||||
}} | ||||||
> | ||||||
<SectionTitle title={t('overview.useCases.noUseCaseMessage')} /> | ||||||
<SectionTitle title={t(noItemsMessageKey)} /> | ||||||
</Box> | ||||||
) : ( | ||||||
<Newsroom | ||||||
items={useCases.map((useCase) => ({ | ||||||
title: useCase.title, | ||||||
date: { | ||||||
date: useCase.publishedAt, | ||||||
}, | ||||||
href: { | ||||||
label: 'shared.readUseCase', | ||||||
link: useCase.path, | ||||||
translate: true, | ||||||
}, | ||||||
img: { | ||||||
alt: useCase.coverImage?.alternativeText || '', | ||||||
src: useCase.coverImage?.url || '/images/news.png', | ||||||
}, | ||||||
items={filteredItems.map((item) => ({ | ||||||
...item, | ||||||
}))} | ||||||
/> | ||||||
)} | ||||||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put a default value for tags on the FilteredGridLayout component itself allowing it to take undefined or falsey tags and handle the case with a fallback to empty array in the component