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

NEW: CMS 5 upgrade. #102

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
module.exports = require('@silverstripe/eslint-config/.eslintrc');
module.exports = {
extends: '@silverstripe/eslint-config',
// Allows null coalescing and optional chaining operators.
parserOptions: {
ecmaVersion: 2020
},
};
61 changes: 60 additions & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/src/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import registerReducers from 'boot/registerReducers';

window.document.addEventListener('DOMContentLoaded', () => {
registerComponents();

registerReducers();
});
2 changes: 0 additions & 2 deletions client/src/boot/registerComponents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import Injector from 'lib/Injector';
import HistoryViewer from 'components/HistoryViewer/HistoryViewer';
import SnapshotViewerContainer from 'components/HistoryViewer/SnapshotViewerContainer';
Expand Down
2 changes: 0 additions & 2 deletions client/src/boot/registerReducers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import Injector from 'lib/Injector';
import { combineReducers } from 'redux';
import historyViewerReducer from 'state/historyviewer/HistoryViewerReducer';
Expand Down
13 changes: 6 additions & 7 deletions client/src/bundles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
*/

// Expose fields (see webpack config for matching "externals" config)
require('expose-loader?SnapshotsViewer!components/HistoryViewer/HistoryViewer');

require('expose-loader?versionType!types/versionType');
import 'expose-loader?exposes=SnapshotsViewer!components/HistoryViewer/HistoryViewer';
import 'expose-loader?exposes=versionType!types/versionType';

// Legacy CMS
require('../legacy/ArchiveAdmin/ArchiveAdmin');
import '../legacy/ArchiveAdmin/ArchiveAdmin';

// Legacy form fields
// Fields used by core legacy UIs, or available to users
// To do: determine better way of using webpack to pull in optional javascript
require('../legacy/HistoryViewer/HistoryViewerEntwine');
import '../legacy/HistoryViewer/HistoryViewerEntwine';

// Legacy publish/unpublish popup confirmation - copy from versioned-admin
require('../legacy/VersionedEditForm/VersionedEditForm');
import '../legacy/VersionedEditForm/VersionedEditForm';

require('boot');
import 'boot';
3 changes: 1 addition & 2 deletions client/src/components/HistoryViewer/HistoryViewer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
/* global window */

import React, { Component } from 'react';
Expand All @@ -17,7 +16,7 @@ import {
import { versionType } from 'types/versionType';
import { compareType } from 'types/compareType';
import classNames from 'classnames';
import ResizeAware from 'react-resize-aware';
import ResizeAware from 'components/ResizeAware/ResizeAwareHoc';
import * as viewModeActions from 'state/viewMode/ViewModeActions';
import PropTypes from 'prop-types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/HistoryViewer/HistoryViewerHeading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import i18n from 'i18n';
import React, { Component } from 'react';
import { Dropdown, DropdownToggle, DropdownMenu } from 'reactstrap';
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/HistoryViewer/HistoryViewerSnapshot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { inject } from 'lib/Injector';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import { inject } from 'lib/Injector';
import React from 'react';
import { Component as VersionedState } from './HistoryViewerVersionState';
Expand Down
23 changes: 8 additions & 15 deletions client/src/components/HistoryViewer/HistoryViewerToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ import { connect } from 'react-redux';
import i18n from 'i18n';
import { inject } from 'lib/Injector';
import { addMessage, showList } from 'state/historyviewer/HistoryViewerActions';
import { Tooltip } from 'reactstrap';
import { UncontrolledTooltip as Tooltip } from 'reactstrap';
Comment on lines -8 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state control we were doing here was pointless - it was just toggling a boolean in state. No need for us to manage that directly.


class HistoryViewerToolbar extends Component {
constructor(props) {
super(props);

this.handleRevert = this.handleRevert.bind(this);
this.handleToggleRevertTooltip = this.handleToggleRevertTooltip.bind(this);

this.state = {
isReverting: false,
revertTooltipOpen: false,
tooltipTimer: null,
};
}
Expand All @@ -40,12 +38,6 @@ class HistoryViewerToolbar extends Component {
} }).then(() => handler(versionId));
}

handleToggleRevertTooltip() {
this.setState(state => ({
revertTooltipOpen: !state.revertTooltipOpen,
}));
}

render() {
const {
FormActionComponent,
Expand All @@ -57,11 +49,14 @@ class HistoryViewerToolbar extends Component {
rollbackMessage,
typeName,
} = this.props;
const { isReverting, revertTooltipOpen } = this.state;
const { isReverting } = this.state;

const revertButtonTitle = isReverting
? i18n._t('HistoryViewerToolbar.REVERT_IN_PROGRESS', 'Revert in progress...')
: i18n._t('HistoryViewerToolbar.REVERT_UNAVAILABLE', 'Unavailable for the current version');
let revertButtonTitle = '';
if (isReverting) {
revertButtonTitle = i18n._t('HistoryViewerToolbar.REVERT_IN_PROGRESS', 'Revert in progress...');
} else if (isLatestVersion) {
revertButtonTitle = i18n._t('HistoryViewerToolbar.REVERT_UNAVAILABLE', 'Unavailable for the current version');
}
Comment on lines -60 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, we end up with two tooltips when hovering over the revert button for the history details of a related child record.


return (
<RollbackMutation typeName={typeName}>
Expand All @@ -87,8 +82,6 @@ class HistoryViewerToolbar extends Component {
<Tooltip
trigger="click hover focus"
placement="top"
isOpen={revertTooltipOpen}
toggle={this.handleToggleRevertTooltip}
target="HistoryRevertButton"
>
{rollbackMessage}
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/HistoryViewer/HistoryViewerVersion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { compose } from 'redux';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import classnames from 'classnames';
import i18n from 'i18n';
Expand Down
4 changes: 1 addition & 3 deletions client/src/components/HistoryViewer/RollbackMutation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { useMemo } from 'react';
import { Mutation } from 'react-apollo';
import { Mutation } from '@apollo/client/react/components';
import createRollbackMutation from '../../graphql/createRollbackMutation';

const RollbackMutation = ({ typeName, children }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable import/no-unresolved */

import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { Query } from 'react-apollo';
import { Query } from '@apollo/client/react/components';
import { inject } from 'lib/Injector';
import createSnapshotsQuery from '../../graphql/createSnapshotsQuery';

Expand Down
19 changes: 19 additions & 0 deletions client/src/components/ResizeAware/ResizeAwareHoc.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use hooks in a class component, so we need this little HOC to handle the hook for us.
We can't use the old version of the resize aware library because that doesn't support the new react dependency constraint.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useEffect } from 'react';
import useResizeAware from 'react-resize-aware';

const ResizeAwareHoc = ({ children, className, onResize }) => {
const [resizeListener, sizes] = useResizeAware();

useEffect(() => {
onResize({ width: sizes?.width, height: sizes?.height });
}, [sizes?.width, sizes?.height]);

return (
<div className={className}>
{resizeListener}
{children}
</div>
);
};

export default ResizeAwareHoc;
2 changes: 0 additions & 2 deletions client/src/containers/HistoryViewer/HistoryViewerConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import React from 'react';
import Config from 'lib/Config';
import { inject } from 'lib/Injector';
Expand Down
2 changes: 0 additions & 2 deletions client/src/helpers/getDateFromVersion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import i18n from 'i18n';
import moment from 'moment';

Expand Down
20 changes: 14 additions & 6 deletions client/src/legacy/HistoryViewer/HistoryViewerEntwine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jQuery from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import { loadComponent } from 'lib/Injector';

/**
Expand All @@ -11,6 +11,8 @@ import { loadComponent } from 'lib/Injector';
*/
jQuery.entwine('ss', ($) => {
$('.js-injector-boot .snapshot-history-viewer__container').entwine({
ReactRoot: null,

onmatch() {
const cmsContent = this.closest('.cms-content').attr('id');
const context = (cmsContent)
Expand All @@ -25,14 +27,20 @@ jQuery.entwine('ss', ($) => {
isInGridField: schemaData.data.isInGridField || !this.hasClass('history-viewer--standalone'),
};

ReactDOM.render(
<HistoryViewerComponent {...props} />,
this[0]
);
let root = this.getReactRoot();
if (!root) {
root = ReactDOM.createRoot(this[0]);
}
root.render(<HistoryViewerComponent {...props} />);
this.setReactRoot(root);
},

onunmatch() {
ReactDOM.unmountComponentAtNode(this[0]);
const root = this.getReactRoot();
if (root) {
root.unmount();
this.setReactRoot(null);
}
}
});

Expand Down
2 changes: 0 additions & 2 deletions client/src/legacy/VersionedEditForm/VersionedEditForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import i18n from 'i18n';
import jQuery from 'jquery';

Expand Down
4 changes: 1 addition & 3 deletions client/src/state/historyviewer/HistoryViewerActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable import/no-unresolved */

import uuidv1 from 'uuid/v1';
import { v1 as uuidv1 } from 'uuid';
import HISTORY_VIEWER from './HistoryViewerActionTypes';

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"node": "^18.x"
},
"scripts": {
"build": "NODE_ENV=development yarn && yarn lint && yarn test && NODE_ENV=production webpack --mode production --bail --progress",
"build": "yarn && yarn lint && rm -rf client/dist/* && NODE_ENV=production webpack --mode production --bail --progress",
"dev": "NODE_ENV=development webpack --progress",
"watch": "NODE_ENV=development webpack --watch --progress",
"css": "WEBPACK_CHILD=css npm run build",
Expand Down Expand Up @@ -70,7 +70,7 @@
"classnames": "^2.3.2",
"graphql": "^16.6.0",
"graphql-fragments": "^0.1.0",
"graphql-tag": "^2.10.0",
"graphql-tag": "^2.12.6",
"griddle-react": "^1.13.1",
"jquery": "^3.5.0",
"moment": "^2.21.0",
Expand All @@ -79,7 +79,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"react-resize-aware": "^3.1.2",
"react-resize-aware": "^4.0.0",
"react-router": "^6.7",
"react-router-redux": "^4.0.5",
"reactstrap": "^8.9.0",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4297,7 +4297,7 @@ graphql-fragments@^0.1.0:
dependencies:
graphql-anywhere "^0.2.4"

graphql-tag@^2.10.0, graphql-tag@^2.12.6:
graphql-tag@^2.12.6:
version "2.12.6"
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.12.6.tgz#d441a569c1d2537ef10ca3d1633b48725329b5f1"
integrity sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==
Expand Down Expand Up @@ -7077,10 +7077,10 @@ react-redux@^8.0.5:
react-is "^18.0.0"
use-sync-external-store "^1.0.0"

react-resize-aware@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/react-resize-aware/-/react-resize-aware-3.1.2.tgz#a5e6fe4691a3ac8d3b0fadd37008339db2294c4f"
integrity sha512-sBtMIEy/9oI+Xf2o7IdWdkTokpZSPo9TWn60gqWKPG3BXg44Rg3FCIMiIjmgvRUF4eQptw6pqYTUhYwkeVSxXA==
react-resize-aware@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/react-resize-aware/-/react-resize-aware-4.0.0.tgz#9a2e002c0a3d15285ccd81c2d3d17aff64e8a597"
integrity sha512-42aoj3uGcqhsMQE7yssxuy0+YYNp38CSzoGxRXUV80WUm6uYJKhAwBlOSBltxTbdZSkJXZwgq43iyywjVI9ZgA==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to update to 4.x because of FezVrasta/react-resize-aware#58


react-router-redux@^4.0.5:
version "4.0.8"
Expand Down
Loading