From 0d90f48f22980c8afbac87bbee16b018ec638579 Mon Sep 17 00:00:00 2001 From: Grace Park Date: Mon, 14 Jun 2021 13:35:03 -0700 Subject: [PATCH] React Sublanding Fixes (#19894) * fixing a couple issue with the sublanding - nulls and page.type * learning track null error fix Co-authored-by: Kevin Heis --- .../context/ProductSubLandingContext.tsx | 10 +++++----- components/sublanding/LearningTrack.tsx | 18 +++++++++--------- components/sublanding/LearningTracks.tsx | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/components/context/ProductSubLandingContext.tsx b/components/context/ProductSubLandingContext.tsx index 0611a9cfd0..d701a9076f 100644 --- a/components/context/ProductSubLandingContext.tsx +++ b/components/context/ProductSubLandingContext.tsx @@ -6,7 +6,7 @@ export type FeaturedTrack = { title: string description: string guides?: Array<{ href: string; page: { type: string }; title: string; intro: string }> -} +} | null export type ArticleGuide = { href: string @@ -45,12 +45,12 @@ export const getProductSubLandingContextFromRequest = (req: any): ProductSubLand return { ...pick(page, ['intro', 'allTopics']), title: req.context.productMap[req.context.currentProduct].name, - featuredTrack: { + featuredTrack: page.featuredTrack ? { ...pick(page.featuredTrack, ['title', 'description', 'trackName', 'guides']), guides: (page.featuredTrack?.guides || []).map((guide: any) => { return pick(guide, ['title', 'intro', 'href', 'page.type']) - }), - }, + }) + } : null, learningTracks: (page.learningTracks || []).map((track: any) => ({ ...pick(track, ['title', 'description', 'trackName', 'guides']), guides: (track.guides || []).map((guide: any) => { @@ -58,7 +58,7 @@ export const getProductSubLandingContextFromRequest = (req: any): ProductSubLand }), })), includeGuides: (page.includeGuides || []).map((guide: any) => { - return pick(guide, ['href', 'title', 'intro', 'type', 'topics']) + return pick(guide, ['href', 'title', 'intro', 'page.type', 'topics']) }), } } diff --git a/components/sublanding/LearningTrack.tsx b/components/sublanding/LearningTrack.tsx index 5341ca0c86..2e55420b1f 100644 --- a/components/sublanding/LearningTrack.tsx +++ b/components/sublanding/LearningTrack.tsx @@ -9,9 +9,9 @@ type Props = { const MAX_VISIBLE_GUIDES = 4 export const LearningTrack = ({ track }: Props) => { - const [visibleGuides, setVisibleGuides] = useState(track.guides?.slice(0, 4)) + const [visibleGuides, setVisibleGuides] = useState(track?.guides?.slice(0, 4)) const showAll = () => { - setVisibleGuides(track.guides) + setVisibleGuides(track?.guides) } const { t } = useTranslation('product_sublanding') @@ -21,16 +21,16 @@ export const LearningTrack = ({ track }: Props) => {
-
{track.title}
+
{track?.title}

- {track.description} + {track?.description}

{t('start')} @@ -42,10 +42,10 @@ export const LearningTrack = ({ track }: Props) => {
- {track.guides && ( + {track?.guides && ( {track.guides?.indexOf(guide) + 1} @@ -56,7 +56,7 @@ export const LearningTrack = ({ track }: Props) => { {t('guide_types')[guide.page.type]}
- {track.guides && track.guides?.indexOf(guide) + 1 === MAX_VISIBLE_GUIDES ? ( + {track?.guides && track?.guides?.indexOf(guide) + 1 === MAX_VISIBLE_GUIDES ? (
- Show {track.guides?.length - MAX_VISIBLE_GUIDES} {t(`more_guides`)} + Show {track?.guides?.length - MAX_VISIBLE_GUIDES} {t(`more_guides`)} ) : ( diff --git a/components/sublanding/LearningTracks.tsx b/components/sublanding/LearningTracks.tsx index dce7f0af00..96b9462066 100644 --- a/components/sublanding/LearningTracks.tsx +++ b/components/sublanding/LearningTracks.tsx @@ -8,7 +8,7 @@ export const LearningTracks = () => {
{(learningTracks || []).map((track) => { - return + return })}