From c21ed83b10cc2b1e2156c16545115fdae1b9a0fb Mon Sep 17 00:00:00 2001 From: jmfrancois Date: Mon, 26 Dec 2022 17:37:54 +0100 Subject: [PATCH] chore: continue migration --- .../DateTimePickers/Date/date-extraction.test.js | 4 ++-- .../DateRange/Manager/Manager.component.js | 2 +- .../DateTimeRange/Manager/Manager.component.js | 4 ++-- .../InputDatePicker/DatePicker.stories.js | 4 ++-- .../DateTime/Manager/Manager.component.js | 2 +- .../pickers/DatePicker/DatePicker.test.js | 9 +++++---- .../pickers/DatePicker/DatePicker.test.js | 9 +++++---- .../ResourceList/Resource/Resource.component.js | 4 ++-- .../src/ResourceList/Resource/Resource.test.js | 4 ++-- .../CellDatetime/CellDatetime.component.js | 6 +++--- .../CellDatetime/CellDatetime.test.js | 14 ++++++++------ 11 files changed, 33 insertions(+), 29 deletions(-) diff --git a/packages/components/src/DateTimePickers/Date/date-extraction.test.js b/packages/components/src/DateTimePickers/Date/date-extraction.test.js index e0126163778..96c09b9f3d1 100644 --- a/packages/components/src/DateTimePickers/Date/date-extraction.test.js +++ b/packages/components/src/DateTimePickers/Date/date-extraction.test.js @@ -1,5 +1,5 @@ -import isAfter from 'date-fns/is_after'; -import subHours from 'date-fns/sub_hours'; +import isAfter from 'date-fns/isAfter'; +import subHours from 'date-fns/subHours'; import { checkSupportedDateFormat, checkSupportedTimezone, diff --git a/packages/components/src/DateTimePickers/DateRange/Manager/Manager.component.js b/packages/components/src/DateTimePickers/DateRange/Manager/Manager.component.js index c88056f72e0..2a0fcb14a98 100644 --- a/packages/components/src/DateTimePickers/DateRange/Manager/Manager.component.js +++ b/packages/components/src/DateTimePickers/DateRange/Manager/Manager.component.js @@ -1,6 +1,6 @@ import { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; -import isBefore from 'date-fns/is_before'; +import isBefore from 'date-fns/isBefore'; import { DateRangeContext } from '../Context'; import getErrorMessage from '../../shared/error-messages'; diff --git a/packages/components/src/DateTimePickers/DateTimeRange/Manager/Manager.component.js b/packages/components/src/DateTimePickers/DateTimeRange/Manager/Manager.component.js index d1314f18fcc..fe88b8b3f27 100644 --- a/packages/components/src/DateTimePickers/DateTimeRange/Manager/Manager.component.js +++ b/packages/components/src/DateTimePickers/DateTimeRange/Manager/Manager.component.js @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; -import isBefore from 'date-fns/is_before'; -import isEqual from 'date-fns/is_equal'; +import isBefore from 'date-fns/isBefore'; +import isEqual from 'date-fns/isEqual'; import { DateTimeRangeContext } from '../Context'; import getErrorMessage from '../../shared/error-messages'; diff --git a/packages/components/src/DateTimePickers/InputDatePicker/DatePicker.stories.js b/packages/components/src/DateTimePickers/InputDatePicker/DatePicker.stories.js index 8443b8dc96f..ce67bbcc2e9 100644 --- a/packages/components/src/DateTimePickers/InputDatePicker/DatePicker.stories.js +++ b/packages/components/src/DateTimePickers/InputDatePicker/DatePicker.stories.js @@ -1,6 +1,6 @@ import { action } from '@storybook/addon-actions'; -import isBefore from 'date-fns/is_before'; -import startOfDay from 'date-fns/start_of_day'; +import isBefore from 'date-fns/isBefore'; +import startOfDay from 'date-fns/startOfDay'; import InputDatePicker from './InputDatePicker.component'; diff --git a/packages/components/src/DateTimePickers/LegacyDateTimePickers/DateTime/Manager/Manager.component.js b/packages/components/src/DateTimePickers/LegacyDateTimePickers/DateTime/Manager/Manager.component.js index a502ed595c8..20bcdddd69f 100644 --- a/packages/components/src/DateTimePickers/LegacyDateTimePickers/DateTime/Manager/Manager.component.js +++ b/packages/components/src/DateTimePickers/LegacyDateTimePickers/DateTime/Manager/Manager.component.js @@ -1,6 +1,6 @@ import { Component } from 'react'; import PropTypes from 'prop-types'; -import isSameSecond from 'date-fns/is_same_second'; +import isSameSecond from 'date-fns/isSameSecond'; import { DateTimeContext } from '../Context'; import { diff --git a/packages/components/src/DateTimePickers/LegacyDateTimePickers/pickers/DatePicker/DatePicker.test.js b/packages/components/src/DateTimePickers/LegacyDateTimePickers/pickers/DatePicker/DatePicker.test.js index 9c7366bfaa6..08734a60514 100644 --- a/packages/components/src/DateTimePickers/LegacyDateTimePickers/pickers/DatePicker/DatePicker.test.js +++ b/packages/components/src/DateTimePickers/LegacyDateTimePickers/pickers/DatePicker/DatePicker.test.js @@ -1,10 +1,11 @@ -import { screen, render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import isSameDay from 'date-fns/is_same_day'; -import isToday from 'date-fns/is_today'; +import isSameDay from 'date-fns/isSameDay'; +import isToday from 'date-fns/isToday'; + import DatePicker from './DatePicker.component'; -jest.mock('date-fns/is_today'); +jest.mock('date-fns/isToday'); function mockIsTodayWith(newToday) { isToday.mockImplementation(date => isSameDay(date, newToday)); diff --git a/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js b/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js index ade8911d98a..6c48e719150 100644 --- a/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js +++ b/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js @@ -1,10 +1,11 @@ -import { screen, render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import isSameDay from 'date-fns/is_same_day'; -import isToday from 'date-fns/is_today'; +import isSameDay from 'date-fns/isSameDay'; +import isToday from 'date-fns/isToday'; + import DatePicker from './DatePicker.component'; -jest.mock('date-fns/is_today'); +jest.mock('date-fns/isToday'); function mockIsTodayWith(newToday) { isToday.mockImplementation(date => isSameDay(date, newToday)); diff --git a/packages/components/src/ResourceList/Resource/Resource.component.js b/packages/components/src/ResourceList/Resource/Resource.component.js index 7ed7143a156..77bbc5ac5b2 100644 --- a/packages/components/src/ResourceList/Resource/Resource.component.js +++ b/packages/components/src/ResourceList/Resource/Resource.component.js @@ -1,7 +1,7 @@ import { Fragment } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; +import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import { withTranslation } from 'react-i18next'; import { getRowData } from '../../VirtualizedList/utils/gridrow'; import I18N_DOMAIN_COMPONENTS from '../../constants'; @@ -17,7 +17,7 @@ const FLAGS = { }; function getDateLabel(t, date) { - return distanceInWordsToNow(date, { + return formatDistanceToNow(date, { addSuffix: true, locale: getLocale(t), }); diff --git a/packages/components/src/ResourceList/Resource/Resource.test.js b/packages/components/src/ResourceList/Resource/Resource.test.js index 60ed2289a6d..b56e4fea36f 100644 --- a/packages/components/src/ResourceList/Resource/Resource.test.js +++ b/packages/components/src/ResourceList/Resource/Resource.test.js @@ -1,11 +1,11 @@ import { render } from '@testing-library/react'; import Resource from './Resource.component'; -jest.mock('date-fns/distance_in_words_to_now', () => () => 'over 2 years ago'); +jest.mock('date-fns/formatDistanceToNow', () => () => 'over 2 years ago'); describe('Resource component snaps', () => { afterAll(() => { - jest.unmock('date-fns/distance_in_words_to_now'); + jest.unmock('date-fns/formatDistanceToNow'); }); describe('renderers', () => { diff --git a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js index f05458b6bbf..c042228aa11 100644 --- a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js +++ b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js @@ -3,9 +3,9 @@ import { Component } from 'react'; import classnames from 'classnames'; import isEqual from 'lodash/isEqual'; import pick from 'lodash/pick'; -import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; +import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import format from 'date-fns/format'; -import isValid from 'date-fns/is_valid'; +import isValid from 'date-fns/isValid'; import parse from 'date-fns/parse'; import { withTranslation } from 'react-i18next'; import { date as dateUtils } from '@talend/utils'; @@ -23,7 +23,7 @@ export function computeValue(cellData, columnData, t) { if (isDateValid) { if (cellData && columnData.mode === 'ago') { - return distanceInWordsToNow(cellData, { + return formatDistanceToNow(cellData, { addSuffix: true, locale: getLocale(t), }); diff --git a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js index 43581196f68..3e87e8aa46f 100644 --- a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js +++ b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js @@ -1,17 +1,19 @@ /* eslint-disable react/prop-types */ + /* eslint-disable react/display-name */ import { render, screen } from '@testing-library/react'; -import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'; import format from 'date-fns/format'; +import distanceInWordsToNow from 'date-fns/formatDistanceToNow'; + import { date as dateUtils } from '@talend/utils'; -import { computeValue, CellDatetimeComponent } from './CellDatetime.component'; -import getDefaultT from '../../translate'; import getLocale from '../../i18n/DateFnsLocale/locale'; +import getDefaultT from '../../translate'; +import { CellDatetimeComponent, computeValue } from './CellDatetime.component'; jest.mock('../../i18n/DateFnsLocale/locale'); -jest.mock('date-fns/distance_in_words_to_now', () => ({ +jest.mock('date-fns/formatDistanceToNow', () => ({ __esModule: true, default: jest.fn(() => 'about 1 month ago'), })); @@ -49,7 +51,7 @@ describe('CellDatetime', () => { afterAll(() => { jest.unmock('../../i18n/DateFnsLocale/locale'); - jest.unmock('date-fns/distance_in_words_to_now'); + jest.unmock('date-fns/formatDistanceToNow'); jest.unmock('date-fns/format'); }); @@ -125,7 +127,7 @@ describe('CellDatetime', () => { const cellData = 1474495200000 + 3600 * 11 * 1000; const timezoneOffset = new Date(cellData).getTimezoneOffset(); const cellDataWithOffset = cellData + timezoneOffset * 60 * 1000; - const hours = 11 + timezoneOffset / 60; + const expectedStrDate = '2016-09-22 09:00:00'; const computedStrOffset = computeValue(cellDataWithOffset, columnData, t); // then