Skip to content

Commit

Permalink
fix: empty date is not working in CellDateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
romainseb committed Dec 12, 2023
1 parent 58a4866 commit ce749a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-yaks-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-components': patch
---

fix: empty date cell renderer
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import getDefaultT from '../../translate';

import styles from './CellDatetime.module.scss';

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';

export function computeValue(cellData, columnData, t) {
const date = new Date(cellData);
Expand Down Expand Up @@ -52,8 +52,10 @@ export function getTooltipLabel(cellData, columnData, t) {
if (typeof columnData.getTooltipLabel === 'function') {
return columnData.getTooltipLabel(cellData);
}
if (columnData.mode === 'ago') {
const date = new Date(cellData);
const date = new Date(cellData);
const isDateValid = isValid(date);

if (columnData.mode === 'ago' && isDateValid) {
let tooltipLabel = '';
if (columnData.timeZone) {
tooltipLabel = dateUtils.formatToTimeZone(date, columnData.pattern || DATE_TIME_FORMAT, {
Expand Down Expand Up @@ -88,6 +90,7 @@ export class CellDatetimeComponent extends Component {

render() {
const { cellData, columnData, t } = this.props;

const computedValue = computeValue(cellData, columnData, t);
const tooltipLabel = getTooltipLabel(cellData, columnData, t);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable react/prop-types */
import { useState } from 'react';
import { action } from '@storybook/addon-actions'; // eslint-disable-line import/no-extraneous-dependencies

import { SortIndicator } from 'react-virtualized';
import { BrowserRouter, Link as RouterLink } from 'react-router-dom';
// eslint-disable-line import/no-extraneous-dependencies
import { SortIndicator } from 'react-virtualized';

import { action } from '@storybook/addon-actions';

import VirtualizedList from '.';

function MyCustomRow(props) {
Expand Down Expand Up @@ -283,7 +285,7 @@ const collection = [
name: 'Title with long long long long long long long long long long long text',
tag: 'test',
created: '2016-09-22',
modified: '2016-09-22',
modified: undefined,
description: 'Row with a super super long text to show the ellipsis',
author:
'Jean-Pierre DUPONT with super super super super super super super super super super super super super super super super super super super super super super super long name, but there was not enough long text',
Expand Down Expand Up @@ -470,7 +472,7 @@ export const ListTable = () => (
<VirtualizedList.Datetime
label="Modified"
dataKey="modified"
columnData={{ mode: 'format' }}
columnData={{ mode: 'ago' }}
/>
</VirtualizedList>
</section>
Expand Down

0 comments on commit ce749a6

Please sign in to comment.