Skip to content

Commit f475a54

Browse files
Copilotjkachel
andcommitted
Fix hasOwnProperty, unknown cast, and React key in HowYoullLearnSection
Agent-Logs-Url: https://github.com/mitodl/mit-learn/sessions/ed6a7a47-f467-48eb-be2a-464691b2fe77 Co-authored-by: jkachel <945611+jkachel@users.noreply.github.com>
1 parent 9289cc4 commit f475a54

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

frontends/main/src/app-pages/ProductPages/HowYoullLearnSection.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,24 @@ const HowYoullLearnDescription = styled.p(({ theme }) => ({
7474
},
7575
}))
7676

77+
// These fields come from the CMS page types. Once @mitodl/mitxonline-api-axios
78+
// is published with these fields, this can be replaced with:
79+
// Extract<keyof CoursePageItem & keyof ProgramPageItem, `hyl_choice_${string}`>
80+
type HylChoiceKey =
81+
| "hyl_choice_realworld_learning"
82+
| "hyl_choice_learn_by_doing"
83+
| "hyl_choice_learn_from_others"
84+
| "hyl_choice_learn_on_demand"
85+
| "hyl_choice_ai_enabled_support"
86+
| "hyl_choice_stackable_credentials"
87+
7788
type HowYoullLearnItemData = {
7889
icon: typeof IconComputerBulb
7990
title: string
8091
text: string
8192
}
8293
type HowYoullLearnOption = {
83-
name: string
94+
name: HylChoiceKey
8495
data: HowYoullLearnItemData
8596
}
8697

@@ -139,29 +150,28 @@ const HowYoullLearnSection: React.FC<{
139150
page: CoursePageItem | ProgramPageItem
140151
}> = ({ page }) => {
141152
const filteredOptions = HOW_YOULL_LEARN_OPTIONS.filter(
142-
(option) =>
143-
page.hasOwnProperty(option.name) &&
144-
(page as unknown as Record<string, boolean>)[option.name],
153+
(option) => (page as Record<HylChoiceKey, boolean>)[option.name],
145154
)
146-
const items = filteredOptions.map((option) => option.data)
147-
return items.length > 0 ? (
155+
return filteredOptions.length > 0 ? (
148156
<HowYoullLearnRoot aria-labelledby={HeadingIds.How}>
149157
<Typography variant="h4" component="h2" id={HeadingIds.How}>
150158
How you'll learn
151159
</Typography>
152160
<HowYoullLearnGrid>
153-
{items.map((item, index) => (
154-
<HowYoullLearnItem key={index}>
161+
{filteredOptions.map((option) => (
162+
<HowYoullLearnItem key={option.name}>
155163
<HowYoullLearnHeader>
156164
<HowYoullLearnIcon
157-
src={item.icon}
165+
src={option.data.icon}
158166
width={80}
159167
height={50}
160168
alt=""
161169
/>
162-
<HowYoullLearnTitle>{item.title}</HowYoullLearnTitle>
170+
<HowYoullLearnTitle>{option.data.title}</HowYoullLearnTitle>
163171
</HowYoullLearnHeader>
164-
<HowYoullLearnDescription>{item.text}</HowYoullLearnDescription>
172+
<HowYoullLearnDescription>
173+
{option.data.text}
174+
</HowYoullLearnDescription>
165175
</HowYoullLearnItem>
166176
))}
167177
</HowYoullLearnGrid>

0 commit comments

Comments
 (0)