Skip to content

Commit 31ffade

Browse files
authored
fix: show full geo name behavior on county maps (#2706)
1 parent d625ca6 commit 31ffade

File tree

5 files changed

+172
-21
lines changed

5 files changed

+172
-21
lines changed

packages/core/components/DataTable/DataTable.tsx

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import './data-table.css'
2727
import _ from 'lodash'
2828
import { getDataSeriesColumns } from './helpers/getDataSeriesColumns'
2929
import { getMapDataTableColumnKeys } from './helpers/getMapDataTableColumnKeys'
30+
import { addOptionalFullGeoNameColumn } from './helpers/addOptionalFullGeoNameColumn'
3031

3132
export type DataTableProps = {
3233
colorScale?: Function
@@ -327,27 +328,12 @@ const DataTable = (props: DataTableProps) => {
327328
return newRow
328329
})
329330

330-
// only use fullGeoName on County maps and no other
331-
if (config.general?.geoType === 'us-county' || config.table.showFullGeoNameInCSV) {
332-
// Add column for full Geo name along with State
333-
return csvDataUpdated.map((row, index) => {
334-
const originalRow = csvData[index]
335-
if (!originalRow) {
336-
console.warn('Data mismatch: originalRow missing.', {
337-
index,
338-
csvDataLength: csvData.length,
339-
csvDataUpdatedLength: csvDataUpdated.length
340-
})
341-
return row
342-
}
343-
return {
344-
FullGeoName: formatLegendLocation(originalRow[config.columns.geo.name]),
345-
...row
346-
}
347-
})
348-
} else {
349-
return csvDataUpdated
350-
}
331+
return addOptionalFullGeoNameColumn({
332+
config,
333+
csvData,
334+
csvDataUpdated,
335+
formatLegendLocation
336+
})
351337
}
352338

353339
const getMediaControlsClasses = (belowTable, hasDownloadLink) => {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
type AddOptionalFullGeoNameColumnArgs = {
2+
config: any
3+
csvData: Record<string, any>[]
4+
csvDataUpdated: Record<string, any>[]
5+
formatLegendLocation?: (key: string) => string
6+
}
7+
8+
export const addOptionalFullGeoNameColumn = ({
9+
config,
10+
csvData,
11+
csvDataUpdated,
12+
formatLegendLocation
13+
}: AddOptionalFullGeoNameColumnArgs) => {
14+
if (!config?.table?.showFullGeoNameInCSV || typeof formatLegendLocation !== 'function') {
15+
return csvDataUpdated
16+
}
17+
18+
return csvDataUpdated.map((row, index) => {
19+
const originalRow = csvData[index]
20+
if (!originalRow) {
21+
console.warn('Data mismatch: originalRow missing.', {
22+
index,
23+
csvDataLength: csvData.length,
24+
csvDataUpdatedLength: csvDataUpdated.length
25+
})
26+
return row
27+
}
28+
29+
return {
30+
FullGeoName: formatLegendLocation(originalRow[config.columns.geo.name]),
31+
...row
32+
}
33+
})
34+
}
35+
36+
export default addOptionalFullGeoNameColumn
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, expect, it, vi } from 'vitest'
2+
import { addOptionalFullGeoNameColumn } from '../addOptionalFullGeoNameColumn'
3+
4+
describe('addOptionalFullGeoNameColumn', () => {
5+
const csvData = [{ geo: '01001', value: 1 }]
6+
const csvDataUpdated = [{ Geo: '01001', Value: 1 }]
7+
const formatLegendLocation = vi.fn((key: string) => `AL, ${key}`)
8+
9+
it('does not add FullGeoName for county maps when the toggle is off', () => {
10+
const result = addOptionalFullGeoNameColumn({
11+
config: {
12+
general: { geoType: 'us-county' },
13+
table: { showFullGeoNameInCSV: false },
14+
columns: { geo: { name: 'geo' } }
15+
},
16+
csvData,
17+
csvDataUpdated,
18+
formatLegendLocation
19+
})
20+
21+
expect(result).toEqual(csvDataUpdated)
22+
expect(result[0]).not.toHaveProperty('FullGeoName')
23+
})
24+
25+
it('adds FullGeoName for county maps when the toggle is on', () => {
26+
const result = addOptionalFullGeoNameColumn({
27+
config: {
28+
general: { geoType: 'us-county' },
29+
table: { showFullGeoNameInCSV: true },
30+
columns: { geo: { name: 'geo' } }
31+
},
32+
csvData,
33+
csvDataUpdated,
34+
formatLegendLocation
35+
})
36+
37+
expect(result).toEqual([{ FullGeoName: 'AL, 01001', Geo: '01001', Value: 1 }])
38+
})
39+
40+
it('does not add FullGeoName for non-county maps when the toggle is off', () => {
41+
const result = addOptionalFullGeoNameColumn({
42+
config: {
43+
general: { geoType: 'us' },
44+
table: { showFullGeoNameInCSV: false },
45+
columns: { geo: { name: 'geo' } }
46+
},
47+
csvData,
48+
csvDataUpdated,
49+
formatLegendLocation
50+
})
51+
52+
expect(result).toEqual(csvDataUpdated)
53+
})
54+
55+
it('adds FullGeoName for non-county maps when the toggle is on', () => {
56+
const result = addOptionalFullGeoNameColumn({
57+
config: {
58+
general: { geoType: 'us' },
59+
table: { showFullGeoNameInCSV: true },
60+
columns: { geo: { name: 'geo' } }
61+
},
62+
csvData,
63+
csvDataUpdated,
64+
formatLegendLocation
65+
})
66+
67+
expect(result).toEqual([{ FullGeoName: 'AL, 01001', Geo: '01001', Value: 1 }])
68+
})
69+
})

packages/core/helpers/ver/4.26.4.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ const applyMarkupVariableSourceTypes = config => {
6161
})
6262
}
6363

64+
const enableFullGeoNameCsvOnLegacyCountyMaps = config => {
65+
if (config.type === 'map' && config.general?.geoType === 'us-county') {
66+
config.table = config.table || {}
67+
config.table.showFullGeoNameInCSV = true
68+
}
69+
}
70+
6471
const run_4_26_4_migrations = config => {
6572
disableExtraChartVisualSettings(config)
6673
addMarkupIncludeStyle(config)
6774
applyWaffleValueDescriptorDefaults(config)
6875
applyMarkupVariableSourceTypes(config)
76+
enableFullGeoNameCsvOnLegacyCountyMaps(config)
6977

7078
if (config.type === 'dashboard' && config.visualizations) {
7179
Object.values((config as DashboardConfig).visualizations).forEach(visualization => {

packages/core/helpers/ver/tests/4.26.4.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,56 @@ describe('update_4_26_4', () => {
377377
expect(result.visualizations.nestedChart.markupVariables[0].sourceType).toBe('column')
378378
expect(result.visualizations.nestedChart.markupVariables[1].sourceType).toBe('metadata')
379379
})
380+
381+
it('enables full geo name CSV export for legacy county maps', () => {
382+
const config: any = {
383+
type: 'map',
384+
version: '4.26.3',
385+
general: { geoType: 'us-county' },
386+
table: { showFullGeoNameInCSV: false }
387+
}
388+
389+
const result = update_4_26_4(config)
390+
391+
expect(result.table.showFullGeoNameInCSV).toBe(true)
392+
expect(result.version).toBe('4.26.4')
393+
expect(config.table.showFullGeoNameInCSV).toBe(false)
394+
})
395+
396+
it('does not change non-county map CSV full geo name settings', () => {
397+
const config: any = {
398+
type: 'map',
399+
version: '4.26.3',
400+
general: { geoType: 'us' },
401+
table: { showFullGeoNameInCSV: false }
402+
}
403+
404+
const result = update_4_26_4(config)
405+
406+
expect(result.table.showFullGeoNameInCSV).toBe(false)
407+
})
408+
409+
it('enables full geo name CSV export for county maps inside dashboards', () => {
410+
const config: any = {
411+
type: 'dashboard',
412+
version: '4.26.3',
413+
visualizations: {
414+
countyMap: {
415+
type: 'map',
416+
general: { geoType: 'us-county' },
417+
table: { showFullGeoNameInCSV: false }
418+
},
419+
usMap: {
420+
type: 'map',
421+
general: { geoType: 'us' },
422+
table: { showFullGeoNameInCSV: false }
423+
}
424+
}
425+
}
426+
427+
const result = update_4_26_4(config)
428+
429+
expect(result.visualizations.countyMap.table.showFullGeoNameInCSV).toBe(true)
430+
expect(result.visualizations.usMap.table.showFullGeoNameInCSV).toBe(false)
431+
})
380432
})

0 commit comments

Comments
 (0)