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

fix: null dates in table chart #17974

Merged
merged 1 commit into from
Jan 10, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getNumberFormatter,
} from '@superset-ui/core';
import { DataColumnMeta } from '../types';
import DateWithFormatter from './DateWithFormatter';

const xss = new FilterXSS({
whiteList: {
Expand Down Expand Up @@ -62,7 +63,12 @@ function formatValue(
return [false, ''];
}
// render null as `N/A`
if (value === null) {
if (
value === null ||
// null values in temporal columns are wrapped in a Date object, so make sure we
// handle them here too
(value instanceof DateWithFormatter && value.input === null)
) {
return [false, 'N/A'];
}
if (formatter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('plugin-chart-table', () => {
);
tree = wrap.render(); // returns a CheerioWrapper with jQuery-like API
const cells = tree.find('td');
expect(cells).toHaveLength(8);
expect(cells).toHaveLength(12);
expect(cells.eq(0).text()).toEqual('2020-01-01 12:34:56');
expect(cells.eq(1).text()).toEqual('Michael');
// number is not in `metrics` list, so it should output raw value
Expand All @@ -85,6 +85,7 @@ describe('plugin-chart-table', () => {
// should not render column with `.` in name as `undefined`
expect(cells.eq(3).text()).toEqual('foo');
expect(cells.eq(6).text()).toEqual('2467');
expect(cells.eq(8).text()).toEqual('N/A');
});

it('render advanced data', () => {
Expand Down
7 changes: 7 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ const basic: TableChartProps = {
'%pct_nice': 0.00001,
'abc.com': 'bar',
},
{
__timestamp: null,
name: 'Maria',
sum__num: 12342,
'%pct_nice': 0.341,
'abc.com': 'baz',
},
],
},
],
Expand Down