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

Look ma, no momentjs! #2910

Merged
merged 40 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
51e380c
WIP
sneridagh Dec 11, 2021
a03b6b7
More developments
sneridagh Dec 13, 2021
6da0570
Merge remote-tracking branch 'origin/master' into byebyemomentjs
tiberiuichim Jan 2, 2022
77b237b
Enable the format prop; add FormattedI18nDate story
tiberiuichim Jan 2, 2022
d4bdd74
WIP on adding relative formatted date
tiberiuichim Jan 3, 2022
d8f0198
Rename to FormattedDate, move date utils to helpers/Utils/Date
tiberiuichim Jan 4, 2022
1f4912e
Add impl and test for formatRelativeDate
tiberiuichim Jan 4, 2022
5f92913
Add support for the style
tiberiuichim Jan 4, 2022
a42bd59
Rename to FormattedRelativeDate
tiberiuichim Jan 4, 2022
9126cb1
Upgrade jest
tiberiuichim Jan 4, 2022
99997c4
Merge remote-tracking branch 'origin/upgrade_jest' into byebyemomentjs
tiberiuichim Jan 4, 2022
7b7f3f2
Update History snapshot as it is now more correct
tiberiuichim Jan 4, 2022
bcc95d6
Add support for classNames; update snapshots; no need to mock momentjs
tiberiuichim Jan 4, 2022
2318e5a
Allow passing the locale to date formatting utils
tiberiuichim Jan 4, 2022
5256945
Try to fix problem on CI
tiberiuichim Jan 4, 2022
ad33064
Remove intl hack
tiberiuichim Jan 5, 2022
349d3dc
Remove intl hack
tiberiuichim Jan 5, 2022
3288b63
Avoid platform differences
tiberiuichim Jan 5, 2022
521decb
Add full-icu
tiberiuichim Jan 5, 2022
3079cb8
Avoid platform differences
tiberiuichim Jan 5, 2022
a3f42cf
WIP Add support for formatToParts
tiberiuichim Jan 5, 2022
0cb2229
Add Splitparts story
tiberiuichim Jan 5, 2022
def48cd
Add FormattedRelativeDate story
tiberiuichim Jan 5, 2022
7758b85
Add relative to date story
tiberiuichim Jan 5, 2022
207db93
Add live refresh to relative date
tiberiuichim Jan 5, 2022
051fddc
Merge remote-tracking branch 'origin/master' into byebyemomentjs
tiberiuichim Jan 16, 2022
a56279a
Fix display of relative date in ContentsUploadModal
tiberiuichim Jan 16, 2022
4ffa4d3
Fix display of relative date in ModerateComments
tiberiuichim Jan 16, 2022
6da84d5
Add some test for parseDateTime
tiberiuichim Jan 16, 2022
a8b9a0a
Lazyload momentjs in dates display
tiberiuichim Jan 16, 2022
cf9aa70
Use lazyload moment in RecurrenceWidget and Occurences
tiberiuichim Jan 16, 2022
d3b50b0
More lazyload momentjs
tiberiuichim Jan 16, 2022
33357ac
More lazyload momentjs
tiberiuichim Jan 16, 2022
08c8f90
Update changelog
tiberiuichim Jan 16, 2022
add7e2f
Fix use of moment lib
tiberiuichim Jan 16, 2022
1d4fe1e
Merge remote-tracking branch 'origin/master' into byebyemomentjs
tiberiuichim Jan 22, 2022
e0f9de7
Update yarn.lock
tiberiuichim Jan 22, 2022
7adf084
Merge remote-tracking branch 'origin/master' into byebyemomentjs
tiberiuichim Jan 28, 2022
867d7ba
Testing CI build, remove full-icu from test command
tiberiuichim Jan 28, 2022
5cc27bb
Bring back full-icu env option to make it build for node v12
tiberiuichim Jan 28, 2022
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

### Feature

- Add `<FormattedDate>` and `<FormattedRelativeDate>` components. Check their Storybook stories for details. This is part of ongoing work to minimize the use of 'deprecated' momentjs. @sneridagh @tiberiuichim

### Bugfix

### Internal

- Upgrade jest to latest release, 27 major. @tiberiuichim
- Lazyload momentjs. `parseDateTime` helper now requires passing the momentjs library @tiberiuichim

- Lazyload react-beautiful-dnd @tiberiuichim
## 14.6.0 (2022-01-27)

### Feature
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build": "razzle build",
"build-spa": "razzle build --type=spa",
"test": "razzle test --env=jest-environment-jsdom-sixteen --maxWorkers=50%",
"test:ci": "CI=true razzle test --env=jest-environment-jsdom-sixteen",
"test:ci": "CI=true NODE_ICU_DATA=node_modules/full-icu razzle test --env=jest-environment-jsdom-sixteen",
"test:husky": "CI=true yarn test --bail --findRelatedTests",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand",
"start:prod": "NODE_ENV=production node build/server.js",
Expand Down Expand Up @@ -414,7 +414,9 @@
"@storybook/react": "^6.3.0",
"babel-loader": "^8.1.0",
"crypto-random-string": "3.2.0",
"full-icu": "1.4.0",
"identity-obj-proxy": "3.0.0",
"jest": "27.4.5",
"jest-environment-jsdom-sixteen": "1.0.3",
"react-is": "^16.13.1",
"tmp": "0.2.1",
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,7 @@ export ToCSettingsSchema from '@plone/volto/components/manage/Blocks/ToC/Schema'

export MaybeWrap from '@plone/volto/components/manage/MaybeWrap/MaybeWrap';
export ContentMetadataTags from '@plone/volto/components/theme/ContentMetadataTags/ContentMetadataTags';
export FormattedDate from '@plone/volto/components/theme/FormattedDate/FormattedDate';
export FormattedRelativeDate from '@plone/volto/components/theme/FormattedDate/FormattedRelativeDate';

export App from '@plone/volto/components/theme/App/App';
7 changes: 0 additions & 7 deletions src/components/manage/Contents/Contents.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ jest.mock('./ContentsUploadModal', () =>
jest.fn(() => <div className="UploadModal" />),
);

jest.mock('moment', () =>
jest.fn(() => ({
format: jest.fn(() => 'Sunday, April 23, 2017 3:38 AM'),
fromNow: jest.fn(() => 'a few seconds ago'),
})),
);

describe('Contents', () => {
it('renders a folder contents view component', () => {
const store = mockStore({
Expand Down
23 changes: 9 additions & 14 deletions src/components/manage/Contents/ContentsItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { Button, Dropdown, Table } from 'semantic-ui-react';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import { map } from 'lodash';
import moment from 'moment';
import { useIntl, defineMessages, FormattedMessage } from 'react-intl';
import { Icon, Circle } from '@plone/volto/components';
import { Circle, FormattedDate, Icon } from '@plone/volto/components';
import { getContentIcon } from '@plone/volto/helpers';
import moreSVG from '@plone/volto/icons/more.svg';
import checkboxUncheckedSVG from '@plone/volto/icons/checkbox-unchecked.svg';
Expand Down Expand Up @@ -48,6 +47,10 @@ const messages = defineMessages({
id: 'no workflow state',
defaultMessage: 'No workflow state',
},
none: {
id: 'None',
defaultMessage: 'None',
},
});

function getColor(string) {
Expand Down Expand Up @@ -187,21 +190,13 @@ export const ContentsItemComponent = ({
</div>
)}
{index.type === 'date' && (
<span
title={
item[index.id] !== 'None' ? (
moment(item[index.id]).format('LLLL')
) : (
<FormattedMessage id="None" defaultMessage="None" />
)
}
>
<>
{item[index.id] !== 'None' ? (
moment(item[index.id]).format('L')
<FormattedDate date={item[index.id]} />
) : (
<FormattedMessage id="None" defaultMessage="None" />
intl.formatMessage(messages.none)
)}
</span>
</>
)}
{index.type === 'array' && (
<span>{item[index.id]?.join(', ')}</span>
Expand Down
6 changes: 2 additions & 4 deletions src/components/manage/Contents/ContentsUploadModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import {
} from 'semantic-ui-react';
import loadable from '@loadable/component';
import { concat, filter, map } from 'lodash';
import moment from 'moment';
import filesize from 'filesize';
import { readAsDataURL } from 'promise-file-reader';
import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
import { FormattedRelativeDate } from '@plone/volto/components';
import { createContent } from '@plone/volto/actions';

const Dropzone = loadable(() => import('react-dropzone'));
Expand Down Expand Up @@ -180,8 +180,6 @@ class ContentsUploadModal extends Component {
* @returns {string} Markup for the component.
*/
render() {
moment.locale(this.props.intl.locale);

return (
this.props.open && (
<Modal open={this.props.open}>
Expand Down Expand Up @@ -269,7 +267,7 @@ class ContentsUploadModal extends Component {
<Table.Row className="upload-row" key={file.name}>
<Table.Cell>{file.name}</Table.Cell>
<Table.Cell>
{moment(file.lastModifiedDate).fromNow()}
<FormattedRelativeDate date={file.lastModifiedDate} />
</Table.Cell>
<Table.Cell>
{filesize(file.size, { round: 0 })}
Expand Down
12 changes: 7 additions & 5 deletions src/components/manage/Controlpanels/ModerateComments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import { Link } from 'react-router-dom';
import { getParentUrl, Helmet } from '@plone/volto/helpers';
import { Portal } from 'react-portal';
import { Container, Button, Table } from 'semantic-ui-react';
import moment from 'moment';
import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';

import { deleteComment, searchContent } from '@plone/volto/actions';
import { CommentEditModal, Icon, Toolbar } from '@plone/volto/components';
import {
CommentEditModal,
FormattedRelativeDate,
Icon,
Toolbar,
} from '@plone/volto/components';

import backSVG from '@plone/volto/icons/back.svg';

Expand Down Expand Up @@ -230,9 +234,7 @@ class ModerateComments extends Component {
<Table.Row key={item['@id']}>
<Table.Cell>{item.author_name}</Table.Cell>
<Table.Cell>
<span title={moment(item.creation_date).format('LLLL')}>
{moment(item.creation_date).fromNow()}
</span>
<FormattedRelativeDate date={item.creation_date} />
</Table.Cell>
<Table.Cell>{item.text.data}</Table.Cell>
<Table.Cell>
Expand Down
18 changes: 13 additions & 5 deletions src/components/manage/Diff/Diff.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { filter, isEqual, map } from 'lodash';
import { Container, Button, Dropdown, Grid, Table } from 'semantic-ui-react';
import { Link, withRouter } from 'react-router-dom';
import { Portal } from 'react-portal';
import moment from 'moment';
import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
import qs from 'query-string';

Expand All @@ -23,7 +22,12 @@ import {
getBlocksLayoutFieldname,
hasBlocksData,
} from '@plone/volto/helpers';
import { DiffField, Icon, Toolbar } from '@plone/volto/components';
import {
DiffField,
FormattedDate,
Icon,
Toolbar,
} from '@plone/volto/components';

import backSVG from '@plone/volto/icons/back.svg';

Expand Down Expand Up @@ -189,9 +193,13 @@ class Diff extends Component {
const versions = map(
filter(this.props.historyEntries, (entry) => 'version' in entry),
(entry, index) => ({
text: `${index === 0 ? 'Current' : entry.version} (${moment(
entry.time,
).format('LLLL')}, ${entry.actor.fullname})`,
text: (
<>
{index === 0 ? 'Current' : entry.version}&nbsp;(
<FormattedDate date={entry.time} long className="text" />, &nbsp;
{entry.actor.fullname})
</>
),
value: `${entry.version}`,
key: `${entry.version}`,
}),
Expand Down
6 changes: 0 additions & 6 deletions src/components/manage/Diff/Diff.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
// import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-intl-redux';
import { MemoryRouter } from 'react-router-dom';
Expand All @@ -12,11 +11,6 @@ const mockStore = configureStore();
jest.mock('react-portal', () => ({
Portal: jest.fn(() => <div id="Portal" />),
}));
jest.mock('moment', () =>
jest.fn(() => ({
format: jest.fn(() => 'Sunday, April 23, 2017 3:38 AM'),
})),
);

jest.mock('@plone/volto/helpers/Loadable/Loadable');
beforeAll(
Expand Down
15 changes: 12 additions & 3 deletions src/components/manage/Diff/DiffField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import React from 'react';
import { join, map } from 'lodash';
import PropTypes from 'prop-types';
import { Table } from 'semantic-ui-react';
import moment from 'moment';
import ReactDOMServer from 'react-dom/server';
import { Provider } from 'react-intl-redux';
import { createBrowserHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
import { useSelector } from 'react-redux';

import { Api } from '@plone/volto/helpers';
import configureStore from '@plone/volto/store';
Expand Down Expand Up @@ -44,6 +44,11 @@ const DiffField = ({
schema,
diffLib,
}) => {
const language = useSelector((state) => state.intl.locale);
const readable_date_format = {
dateStyle: 'full',
timeStyle: 'short',
};
const diffWords = (oneStr, twoStr) => {
return diffLib.diffWords(String(oneStr), String(twoStr));
};
Expand All @@ -56,8 +61,12 @@ const DiffField = ({
break;
case 'datetime':
parts = diffWords(
moment(one).format('LLLL'),
moment(two).format('LLLL'),
new Intl.DateTimeFormat(language, readable_date_format).format(
new Date(one),
),
new Intl.DateTimeFormat(language, readable_date_format).format(
new Date(two),
),
);
break;
case 'json':
Expand Down
6 changes: 0 additions & 6 deletions src/components/manage/Diff/DiffField.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { waitFor, render, screen } from '@testing-library/react';

import DiffField from './DiffField';

jest.mock('moment', () =>
jest.fn(() => ({
format: jest.fn(() => 'Sunday, April 23, 2017 3:38 AM'),
})),
);

jest.mock('@plone/volto/helpers/Loadable/Loadable');
beforeAll(
async () =>
Expand Down
Loading