Skip to content

Commit

Permalink
Bugfix: Function called on empty dataset (#3673)
Browse files Browse the repository at this point in the history
fixes #3672
  • Loading branch information
benhammondmusic committed Sep 17, 2024
1 parent b711482 commit f6bcfd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 1 addition & 4 deletions frontend/src/cards/SimpleBarChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import type { ElementHashIdHiddenOnScreenshot } from '../utils/hooks/useDownload
import { GUN_VIOLENCE_DATATYPES } from '../data/providers/GunViolenceProvider'
import LawEnforcementAlert from './ui/LawEnforcementAlert'
import { isPctType } from '../data/config/MetricConfigUtils'
import {
addComparisonAllsRowToIntersectionalData,
specialAllGroup,
} from '../charts/simpleBarHelperFunctions'
import { addComparisonAllsRowToIntersectionalData } from '../charts/simpleBarHelperFunctions'

/* minimize layout shift */
const PRELOAD_HEIGHT = 668
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/charts/simpleBarHelperFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function addComparisonAllsRowToIntersectionalData(
rateQueryResponseRateAlls: MetricQueryResponse,
) {
// rename intersectional 'All' group
const dataWithAllsRow = data.map((row) => {
const adjustedData = data.map((row) => {
const renameRow = { ...row }
if (row[demographicType] === specialAllGroup) {
renameRow[demographicType] = rateComparisonConfig?.shortLabel
Expand All @@ -317,7 +317,12 @@ export function addComparisonAllsRowToIntersectionalData(
})

// add the comparison ALLs row to the intersectional data
const originalAllsRow = rateQueryResponseRateAlls.data[0]
const originalAllsRow = rateQueryResponseRateAlls?.data?.[0]

if (!originalAllsRow) {
return adjustedData
}

const { fips, fips_name } = originalAllsRow

const allsRow = {
Expand All @@ -327,7 +332,7 @@ export function addComparisonAllsRowToIntersectionalData(
[rateConfig.metricId]:
originalAllsRow[rateConfig?.rateComparisonMetricForAlls?.metricId ?? ''],
}
dataWithAllsRow.unshift(allsRow)
adjustedData.unshift(allsRow)

return dataWithAllsRow
return adjustedData
}

0 comments on commit f6bcfd3

Please sign in to comment.