Skip to content

Commit 5426c2c

Browse files
committed
Address potential issue
1 parent aae85f3 commit 5426c2c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/editor/src/components/DataImport/helpers/applyAutoDetectedDateParseFormat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const applyAutoDetectedDateParseFormat = (
1313

1414
const xAxisKey = config.xAxis.dataKey
1515

16-
if (!(xAxisKey in importedData[0])) {
16+
const hasXAxisKeyInImportedData = importedData.some(row => row && xAxisKey in row)
17+
18+
if (!hasXAxisKeyInImportedData) {
1719
return config
1820
}
1921

packages/editor/src/components/DataImport/tests/applyAutoDetectedDateParseFormat.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ describe('applyAutoDetectedDateParseFormat', () => {
2828
]
2929

3030
const missingXAxisDateRows = [{ otherDate: '2024/03/15', value: 10 }]
31+
const sparseFirstRowReliableDateRows = [
32+
{ otherDate: 'ignore-me', value: 8 },
33+
{ date: '2024/03/15', value: 10 },
34+
{ date: '2025/11/09', value: 12 }
35+
]
3136

3237
it('auto-fills the chart xAxis date parse format when detection is reliable', () => {
3338
const result: any = applyAutoDetectedDateParseFormat(baseChartConfig, reliableSlashDateRows)
@@ -84,4 +89,10 @@ describe('applyAutoDetectedDateParseFormat', () => {
8489

8590
expect(result).toEqual(baseChartConfig)
8691
})
92+
93+
it('still detects the date parse format when the first row is missing the x-axis key', () => {
94+
const result: any = applyAutoDetectedDateParseFormat(baseChartConfig, sparseFirstRowReliableDateRows)
95+
96+
expect(result.xAxis.dateParseFormat).toBe('%Y/%m/%d')
97+
})
8798
})

0 commit comments

Comments
 (0)