Skip to content

Commit 8700a0b

Browse files
authored
fix(table chart): render bigint value in a raw mode (apache#34556)
1 parent d843fef commit 8700a0b

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ export default function TableChart<D extends DataRecord = DataRecord>(
323323

324324
const getValueRange = useCallback(
325325
function getValueRange(key: string, alignPositiveNegative: boolean) {
326-
if (typeof data?.[0]?.[key] === 'number') {
327-
const nums = data.map(row => row[key]) as number[];
326+
const nums = data
327+
?.map(row => row?.[key])
328+
.filter(value => typeof value === 'number') as number[];
329+
if (data && nums.length === data.length) {
328330
return (
329331
alignPositiveNegative
330332
? [0, d3Max(nums.map(Math.abs))]

superset-frontend/plugins/plugin-chart-table/test/TableChart.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,27 @@ describe('plugin-chart-table', () => {
324324
expect(cells[4]).toHaveTextContent('$ 2.47k');
325325
});
326326

327+
it('render data with a bigint value in a raw record mode', () => {
328+
render(
329+
ProviderWrapper({
330+
children: (
331+
<TableChart
332+
{...transformProps(testData.bigint)}
333+
sticky={false}
334+
isRawRecords
335+
/>
336+
),
337+
}),
338+
);
339+
const cells = document.querySelectorAll('td');
340+
expect(document.querySelectorAll('th')[0]).toHaveTextContent('name');
341+
expect(document.querySelectorAll('th')[1]).toHaveTextContent('id');
342+
expect(cells[0]).toHaveTextContent('Michael');
343+
expect(cells[1]).toHaveTextContent('4312');
344+
expect(cells[2]).toHaveTextContent('John');
345+
expect(cells[3]).toHaveTextContent('1234567890123456789');
346+
});
347+
327348
it('render raw data', () => {
328349
const props = transformProps({
329350
...testData.raw,

superset-frontend/plugins/plugin-chart-table/test/testData.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,27 @@ const empty = {
349349
],
350350
};
351351

352+
const bigint = {
353+
...advanced,
354+
queriesData: [
355+
{
356+
...basicQueryResult,
357+
colnames: ['name', 'id'],
358+
coltypes: [GenericDataType.String, GenericDataType.Numeric],
359+
data: [
360+
{
361+
name: 'Michael',
362+
id: 4312,
363+
},
364+
{
365+
name: 'John',
366+
id: 1234567890123456789n,
367+
},
368+
],
369+
},
370+
],
371+
};
372+
352373
export default {
353374
basic,
354375
advanced,
@@ -357,4 +378,5 @@ export default {
357378
comparisonWithConfig,
358379
empty,
359380
raw,
381+
bigint,
360382
};

0 commit comments

Comments
 (0)