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: empty date is not working in CellDateTime #5057

Merged
merged 2 commits into from
Dec 12, 2023
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
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
Expand Up @@ -90,7 +90,7 @@ describe('CellDatetime', () => {
render(<CellDatetimeComponent columnData={columnData} />);
// then
expect(distanceInWordsToNow).not.toHaveBeenCalled();
expect(format).toHaveBeenCalled();
expect(format).not.toHaveBeenCalled();
expect(document.querySelector('.cell-datetime-container')).toBeEmptyDOMElement();
});

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
Loading