Skip to content

Commit fff30f6

Browse files
[DEV-3581] Hide empty overview subsections (#1997)
* Add variant background to StartInfo * Add alternate bg color for overview's subsections * Add changeset
1 parent 9269763 commit fff30f6

File tree

6 files changed

+68
-25
lines changed

6 files changed

+68
-25
lines changed

.changeset/sixty-shrimps-show.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nextjs-website": minor
3+
---
4+
5+
Hide empty overview's subsections and add logic to alternate background colors of overview's subsections

apps/nextjs-website/src/app/[locale]/[productSlug]/overview/page.tsx

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ const OverviewPage = async (props: ProductParams) => {
139139
product,
140140
} = await getOverview(params.productSlug);
141141

142+
// Calculate which sections will be shown to determine alternating backgrounds
143+
const sectionsToShow = [
144+
startInfo ? 'startInfo' : null,
145+
product?.hasTutorialListPage && tutorials ? 'tutorials' : null,
146+
product?.hasUseCaseListPage && useCases ? 'useCases' : null,
147+
whatsNew ? 'whatsNew' : null,
148+
product?.hasGuideListPage && postIntegration ? 'postIntegration' : null,
149+
relatedLinks ? 'relatedLinks' : null,
150+
].filter(Boolean) as string[];
151+
152+
// Create a map of section name to background variant, alternating starting with 'lightGrey'
153+
const backgroundVariants = Object.fromEntries(
154+
sectionsToShow.map((section, index) => [
155+
section,
156+
index % 2 === 0 ? 'lightGrey' : 'white',
157+
])
158+
) as Record<string, 'white' | 'lightGrey'>;
159+
142160
const tutorialsListToShow = tutorials?.list
143161
?.filter((tutorial) => tutorial.showInOverview)
144162
.slice(0, MAX_NUM_TUTORIALS_IN_OVERVIEW);
@@ -197,27 +215,30 @@ const OverviewPage = async (props: ProductParams) => {
197215
title={startInfo.title}
198216
cta={startInfo.cta}
199217
cards={startInfo.cards}
218+
backgroundVariant={backgroundVariants['startInfo']}
200219
/>
201220
)}
202221
{product?.hasTutorialListPage &&
203-
tutorials &&
204-
!tutorials.showCardsLayout ? (
205-
<OverviewItemList
206-
title={tutorials.title}
207-
ctaLabelKey={'overview.tutorial.ctaLabel'}
208-
subtitle={tutorials.subtitle}
209-
itemPath={{
210-
path: `/${params.locale}/${product.slug}/tutorials`,
211-
name: 'tutorials',
212-
}}
213-
items={[...(mappedTutorials || [])]}
214-
/>
215-
) : (
216-
<TutorialsSectionPreviewCardsLayout
217-
title={tutorials?.title || ''}
218-
tutorials={tutorials?.list || []}
219-
/>
220-
)}
222+
tutorials &&
223+
(!tutorials.showCardsLayout ? (
224+
<OverviewItemList
225+
title={tutorials.title}
226+
ctaLabelKey={'overview.tutorial.ctaLabel'}
227+
subtitle={tutorials.subtitle}
228+
itemPath={{
229+
path: `/${params.locale}/${product.slug}/tutorials`,
230+
name: 'tutorials',
231+
}}
232+
items={[...(mappedTutorials || [])]}
233+
backgroundVariant={backgroundVariants['tutorials']}
234+
/>
235+
) : (
236+
<TutorialsSectionPreviewCardsLayout
237+
title={tutorials?.title || ''}
238+
tutorials={tutorials?.list || []}
239+
backgroundVariant={backgroundVariants['tutorials']}
240+
/>
241+
))}
221242
{product?.hasUseCaseListPage && useCases && (
222243
<OverviewItemList
223244
title={useCases.title}
@@ -228,16 +249,17 @@ const OverviewPage = async (props: ProductParams) => {
228249
name: 'useCases',
229250
}}
230251
items={[...(mappedUseCases || [])]}
252+
backgroundVariant={backgroundVariants['useCases']}
231253
/>
232254
)}
233255
{whatsNew && (
234256
<NewsShowcase
235-
marginTop={15}
236257
title={whatsNew.title}
237258
subtitle={whatsNew.subtitle}
238259
link={whatsNew.link}
239260
items={[...whatsNew.items]}
240-
backgroundVariant='lightGrey'
261+
paddingTop={14}
262+
backgroundVariant={backgroundVariants['whatsNew']}
241263
/>
242264
)}
243265
{product?.hasGuideListPage && postIntegration && (
@@ -255,14 +277,14 @@ const OverviewPage = async (props: ProductParams) => {
255277
postIntegration.serviceModels && [...postIntegration.serviceModels]
256278
}
257279
guides={postIntegration.guides}
258-
backgroundVariant={whatsNew ? 'white' : 'lightGrey'}
280+
backgroundVariant={backgroundVariants['postIntegration']}
259281
/>
260282
)}
261283
{relatedLinks && (
262284
<RelatedLinks
263285
title={relatedLinks.title}
264286
links={relatedLinks.links}
265-
backgroundVariant={whatsNew ? 'lightGrey' : 'white'}
287+
backgroundVariant={backgroundVariants['relatedLinks']}
266288
/>
267289
)}
268290
</ProductLayout>

apps/nextjs-website/src/components/organisms/NewsShowcase/NewsShowcase.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type NewsShowcaseProps = {
3232
readonly marginTop?: number;
3333
readonly newsMarginTop?: number;
3434
readonly items: readonly NewsShowcaseItemProps[];
35+
readonly paddingTop?: number;
3536
readonly backgroundVariant?: 'white' | 'lightGrey';
3637
};
3738

@@ -43,6 +44,7 @@ const NewsShowcase = ({
4344
items,
4445
newsMarginTop = 2,
4546
backgroundVariant = 'white',
47+
paddingTop,
4648
}: NewsShowcaseProps) => {
4749
const theme = useTheme();
4850
const t = useTranslations();
@@ -67,6 +69,7 @@ const NewsShowcase = ({
6769
<Box
6870
sx={{
6971
marginTop: marginTop,
72+
paddingTop: paddingTop,
7073
backgroundColor: backgroundColor[backgroundVariant],
7174
}}
7275
>

apps/nextjs-website/src/components/organisms/OverviewItemList/OverviewItemList.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type OverviewItemListProps = {
1414
ctaLabelKey: string;
1515
itemPath: Path;
1616
items: NewsShowcaseItemProps[];
17+
backgroundVariant?: 'white' | 'lightGrey';
1718
};
1819

1920
const OverviewItemList = ({
@@ -23,6 +24,7 @@ const OverviewItemList = ({
2324
ctaLabelKey,
2425
items,
2526
itemPath,
27+
backgroundVariant,
2628
}: OverviewItemListProps) => {
2729
const t = useTranslations();
2830

@@ -42,6 +44,7 @@ const OverviewItemList = ({
4244
text: t(item.link.text),
4345
},
4446
}))}
47+
backgroundVariant={backgroundVariant}
4548
/>
4649
);
4750
};

apps/nextjs-website/src/components/organisms/StartInfo/StartInfo.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@ type StartInfoProps = {
2525
href: string;
2626
iconName?: string;
2727
};
28+
backgroundVariant?: 'white' | 'lightGrey';
2829
};
2930

3031
const StartInfo = ({
3132
title,
3233
cards,
3334
cta,
3435
cardVariant = 'contained',
36+
backgroundVariant = 'white',
3537
}: StartInfoProps) => {
3638
const { palette } = useTheme();
3739
const t = useTranslations();
40+
const backgroundColor =
41+
backgroundVariant === 'white' ? palette.background.paper : palette.grey[50];
3842

3943
return (
4044
<>
41-
<Box pt={10} pb={6} sx={{ backgroundColor: palette.grey[50] }}>
45+
<Box pt={10} pb={6} sx={{ backgroundColor: backgroundColor }}>
4246
<Box mb={2}>
4347
<SectionTitle
4448
title={title || t('overview.startInfo.title')}
@@ -67,7 +71,7 @@ const StartInfo = ({
6771
/>
6872
</Box>
6973
{cta && (
70-
<Box py={2} sx={{ backgroundColor: palette.grey[50] }}>
74+
<Box py={2} sx={{ backgroundColor: backgroundColor }}>
7175
<Stack
7276
spacing={2}
7377
direction={{ md: 'row', xs: 'column' }}

apps/nextjs-website/src/components/organisms/TutorialsSectionPreviewCardsLayout/TutorialsSectionPreviewCardsLayout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ import { useTranslations } from 'next-intl';
99
type TutorialsSectionPreviewCardsLayoutProps = {
1010
title: string;
1111
tutorials: readonly Tutorial[];
12+
backgroundVariant?: 'white' | 'lightGrey';
1213
};
1314

1415
const TutorialsSectionPreviewCardsLayout = ({
1516
title,
1617
tutorials,
18+
backgroundVariant = 'white',
1719
}: TutorialsSectionPreviewCardsLayoutProps) => {
1820
const t = useTranslations();
1921
const theme = useTheme();
22+
const backgroundColor =
23+
backgroundVariant === 'white'
24+
? theme.palette.background.paper
25+
: theme.palette.grey[50];
2026
return (
2127
<Box
2228
sx={{
23-
backgroundColor: theme.palette.grey[50],
29+
backgroundColor: backgroundColor,
2430
}}
2531
>
2632
<Box sx={{ paddingTop: '80px', paddingBottom: '48px' }}>

0 commit comments

Comments
 (0)