Skip to content

Commit

Permalink
[fix] Empty cells with date time data are filled with Invalid date (#…
Browse files Browse the repository at this point in the history
…2201)

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Xun Li <lixun910@gmail.com>
  • Loading branch information
igorDykhta and lixun910 committed Apr 19, 2023
1 parent 3b73dc0 commit 95fd236
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/src/common/data-table/index.tsx
Expand Up @@ -219,8 +219,11 @@ const getRowCell = (
const {type} = colMeta[column];

let value = dataContainer.valueAt(rowIdx, columns.indexOf(column));
if (value === undefined) value = 'Err';
return formatter ? formatter(value) : parseFieldValue(value, type);
return value === null || value === undefined || value === ''
? ''
: formatter
? formatter(value)
: parseFieldValue(value, type);
};

type StatsControlProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/src/data-utils.ts
Expand Up @@ -454,5 +454,6 @@ export function datetimeFormatter(
.utc(ts)
.tz(timezone)
.format(format)
: format => ts => moment.utc(ts).format(format);
: // return empty string instead of 'Invalid date' if ts is undefined/null
format => ts => (ts ? moment.utc(ts).format(format) : '');
}
24 changes: 24 additions & 0 deletions test/node/utils/data-utils-test.js
Expand Up @@ -192,6 +192,30 @@ test('dataUtils -> getFormatter', t => {
{
input: ['yn'],
assert: [true, 'yes']
},
{
input: ['L LT'],
assert: ['2011-04-10 00:00', '04/10/2011 12:00 AM']
},
{
input: ['L LT'],
assert: [null, '']
},
{
input: ['L LT'],
assert: [undefined, '']
},
{
input: ['L LT'],
assert: ['', '']
},
{
input: ['L'],
assert: ['2011-04-10', '04/10/2011']
},
{
input: ['L'],
assert: [null, '']
}
];

Expand Down

0 comments on commit 95fd236

Please sign in to comment.