Skip to content
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

Refactor: Use unique keys instead of index in map functions #3688

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions frontend/src/charts/AgeAdjustedTableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ export function AgeAdjustedTableChart(props: AgeAdjustedTableChartProps) {
<Table {...getTableProps()}>
<TableHead>
{headerGroups.map((group, index) => (
<TableHeaderRow group={group} key={index} />
<TableHeaderRow
group={group}
key={group.id || `group-${index}`}
/>
))}
</TableHead>
<TableBody {...getTableBodyProps()}>
{rows.map((row: ReactTableRowType<any>, index) => (
<TableDataRow row={row} key={index} />
<TableDataRow row={row} key={row.id || `row-${index}`} />
))}
</TableBody>
<TableFooter>
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/charts/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,15 @@ export function TableChart(props: TableChartProps) {
<Table {...getTableProps()}>
<TableHead>
{headerGroups.map((group, index) => (
<TableHeaderRow group={group} key={index} />
<TableHeaderRow
group={group}
key={group.id || `group-${index}`}
/>
))}
</TableHead>
</TableHead>{' '}
<TableBody {...getTableBodyProps()}>
{page.map((row: ReactTableRowType<any>, index) => (
<TableDataRow row={row} key={index} />
<TableDataRow row={row} key={row.id || `row-${index}`} />
))}
</TableBody>
{/* If the number of rows is less than the smallest page size, we can hide pagination */}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/DataCatalog/DataCatalogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default function DataCatalogPage() {
return (
<>
{filteredDatasets.map((sourceId, index) => (
<li key={index}>
<li key={sourceId}>
<DataSourceListing
key={dataSourceMetadataMap[sourceId].id}
source_metadata={dataSourceMetadataMap[sourceId]}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/ExploreData/DefaultHelperBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export default function DefaultHelperBox() {
{reportMappings.map((report, index) => (
<li
className='my-4 xs:my-2 mx-0 flex flex-col bg-white rounded-md hover:shadow-raised group border border-solid border-altGreen transition-all duration-300 ease-in-out w-full'
key={index}
role='listitem'
key={report.title}
>
<article
className='text-left p-4 text-altGreen grid gap-4 md:items-start place-items-center md:grid-cols-[40%_60%] w-full'
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/ExploreData/MadLibUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ export default function MadLibUI(props: MadLibUIProps) {
)

return (
<React.Fragment key={index}>
<React.Fragment
key={
typeof phraseSegment === 'string'
? phraseSegment
: `phrase-${index}`
}
>
{typeof phraseSegment === 'string' ? (
// NON_INTERACTIVE MADLIB WORDS
<span className='text-altBlack'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({
<TableHead>
<TableRow>
{rowData.map((cell, index) => (
<TableCell className='flex content-baseline' key={index}>
<TableCell
className='flex content-baseline'
key={
typeof cell.content === 'string'
? cell.content
: `cell-${index}`
}
>
<pre className='mx-auto my-0 border-none bg-opacity-0'>
{cell.content}
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export default function FormulaFormat(props: FormulaFormatProps) {
</div>
<div className='px-2 py-1'>{' = '}</div>

{props.rightSide.map((item, index) => (
<div className='p-2' key={index}>
{props.rightSide.map((item) => (
<div
className='p-2'
key={
typeof item === 'string'
? item
: `${item.numerator}-${item.denominator}`
}
>
{typeof item === 'string' ? (
item
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export default function GlossaryTerm(props: GlossaryTermProps) {

return (
<>
{sortedDefinitionItems.map(([itemKey, itemVal], index) => {
{sortedDefinitionItems.map(([itemKey, itemVal]) => {
const glossaryDefinition = itemVal.definitions.find(
(def) => def.key === 'Measurement Definition',
)?.description

return (
<div key={index} className='mx-auto my-4'>
<div key={itemKey} className='mx-auto my-4'>
<h4 className='mx-auto mb-0 mt-1 font-sansTitle text-text font-medium text-altGreen '>
{itemKey}
</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function BehavioralHealthLink() {
rows={behavioralHealthDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ChronicDiseaseLink = () => {
rows={chronicDiseaseDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const CommunitySafetyLink = () => {
rows={communitySafetyDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export default function Covid19Link() {
rows={covidDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ const HivLink = () => {
rows={hivDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default function MedicareMedicationLink() {
rows={medicareMedicationDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ const PdohLink = () => {
rows={pdohDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function SdohLink() {
rows={sdohDataSources.map((source, index) => ({
source: (
<a
key={index}
key={source.data_source_name}
href={`${DATA_CATALOG_PAGE_LINK}?${DATA_SOURCE_PRE_FILTERS}=${source.id}`}
>
{source.data_source_name}
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/pages/Policy/policySections/CrisisOverviewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ export default function CrisisOverviewTab() {
{rocketFoundationFacts.map((rocketFoundationFact, index) => {
const isMobileShadow = !isMdAndUp && index % 2 === 0
const isDesktopShadow = isMdAndUp && index % 2 !== 0

const uniqueKey = `fact-${index}`

return (
<div
key={index}
key={uniqueKey}
className={`fade-in-up-blur rounded-md p-8 ${isMobileShadow || isDesktopShadow ? 'shadow-raised-tighter' : ''}`}
style={{ animationDelay: `${index * 0.1}s` }}
>
<FactCard
key={index}
key={uniqueKey}
content={rocketFoundationFact.content}
/>
</div>
Expand All @@ -80,9 +81,11 @@ export default function CrisisOverviewTab() {

<ul className='list-none pl-0 grid gap-4 md:grid-cols-2 grid-cols-1 pt-2 pb-4 my-0'>
{gvaFacts.map((gvaFact, index) => {
const uniqueKey = `fact-${index}`

return (
<li
key={index}
key={uniqueKey}
className={`fade-in-up-blur ${index % 2 === 0 ? 'shadow-raised-tighter' : null}`}
style={{ animationDelay: `${index * 0.1}s` }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function HowToUseTheDataTab() {
</section>
{dataVisuals.map((dataVisual, index) => (
<section
key={index}
key={dataVisual.sectionId}
id={dataVisual.sectionId}
className='max-w-svw w-auto mx-0 px-0'
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export default function ReformOpportunitiesTab() {

return (
<div
key={index}
key={effortsAndInsight.title}
className={`fade-in-up-blur rounded-md p-8 ${
isMobileShadow || isDesktopShadow ? 'shadow-raised' : ''
}`}
style={{ animationDelay: `${index * 0.04}s` }}
>
<CardLeftIcon
key={index}
key={effortsAndInsight.title}
icon={effortsAndInsight.icon}
title={effortsAndInsight.title}
description={effortsAndInsight.description}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/WhatIsHealthEquity/EquityTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ export default function EquityTab() {
) : (
<>
<div className='grid md:grid-cols-2 gap-6 xs:grid-cols-1'>
{NEWS_ARTICLES.slice(0, 2).map((article, index) => (
{NEWS_ARTICLES.slice(0, 2).map((article) => (
<EquityTabNewsCard
key={index}
key={article.title}
href={article.href}
ariaLabel={article.ariaLabel}
imgSrc={article.imgSrc}
Expand All @@ -221,9 +221,9 @@ export default function EquityTab() {
))}
</div>
<div className='grid md:grid-cols-3 gap-6 xs:grid-cols-1 mt-6'>
{NEWS_ARTICLES.slice(2).map((article, index) => (
{NEWS_ARTICLES.slice(2).map((article) => (
<EquityTabNewsCard
key={index}
key={article.title}
href={article.href}
ariaLabel={article.ariaLabel}
imgSrc={article.imgSrc}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/styles/HetComponents/HetTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ interface HetTagsProps {
export const HetTags: React.FC<HetTagsProps> = ({ tags }) => {
return (
<div className='md:flex md:flex-wrap mt-2 hidden'>
{tags.map((name, index) => (
{tags.map((name) => (
<span
aria-label={name}
key={index}
key={name}
className='text-tinyTag uppercase text-altBlack font-sansTitle font-bold bg-ashgray30 rounded-sm py-1 px-2 mr-2 mt-1'
>
{name}
Expand Down
Loading