From 7eb00481de72dcbe9153616fc3775fc0e8b0bcb5 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Tue, 14 Jul 2020 19:12:06 +0300 Subject: [PATCH] fix: leave null timestamp unformatted in view results table (#10313) --- .../spec/javascripts/utils/common_spec.jsx | 12 ++++++++---- superset-frontend/src/utils/common.js | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/superset-frontend/spec/javascripts/utils/common_spec.jsx b/superset-frontend/spec/javascripts/utils/common_spec.jsx index 08c009772..b47f423f2 100644 --- a/superset-frontend/spec/javascripts/utils/common_spec.jsx +++ b/superset-frontend/spec/javascripts/utils/common_spec.jsx @@ -72,12 +72,16 @@ describe('utils/common', () => { }); it('changes formatting of temporal column', () => { const originalData = [ - { __timestamp: 1594285437771, column1: 'lorem' }, - { __timestamp: 1594285441675, column1: 'ipsum' }, + { __timestamp: null, column1: 'lorem' }, + { __timestamp: 0, column1: 'ipsum' }, + { __timestamp: 1594285437771, column1: 'dolor' }, + { __timestamp: 1594285441675, column1: 'sit' }, ]; const expectedData = [ - { __timestamp: '2020-07-09 09:03:57', column1: 'lorem' }, - { __timestamp: '2020-07-09 09:04:01', column1: 'ipsum' }, + { __timestamp: null, column1: 'lorem' }, + { __timestamp: '1970-01-01 00:00:00', column1: 'ipsum' }, + { __timestamp: '2020-07-09 09:03:57', column1: 'dolor' }, + { __timestamp: '2020-07-09 09:04:01', column1: 'sit' }, ]; expect(applyFormattingToTabularData(originalData)).toEqual(expectedData); }); diff --git a/superset-frontend/src/utils/common.js b/superset-frontend/src/utils/common.js index 81b820e60..521ad9064 100644 --- a/superset-frontend/src/utils/common.js +++ b/superset-frontend/src/utils/common.js @@ -128,7 +128,11 @@ export function applyFormattingToTabularData(data) { } return data.map(row => ({ ...row, - // eslint-disable-next-line no-underscore-dangle - __timestamp: DATETIME_FORMATTER(new Date(row.__timestamp)), + /* eslint-disable no-underscore-dangle */ + __timestamp: + row.__timestamp === 0 || row.__timestamp + ? DATETIME_FORMATTER(new Date(row.__timestamp)) + : row.__timestamp, + /* eslint-enable no-underscore-dangle */ })); }