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

DEP Upgrade front-end build stack #1032

Merged
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
18
6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
Copy link
Member Author

@GuySartorelli GuySartorelli Jan 13, 2023

Choose a reason for hiding this comment

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

See silverstripe/silverstripe-asset-admin#1320 (comment) for explanation of this file

"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
110 changes: 109 additions & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion client/src/components/ElementActions/ArchiveAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const ArchiveAction = (MenuComponent) => (props) => {
if (handleArchiveBlock && window.confirm(archiveMessage)) {
handleArchiveBlock(id).then(() => {
const preview = window.jQuery('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
if (preview && typeof preview.entwine === 'function') {
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
}
Comment on lines -33 to +35
Copy link
Member Author

Choose a reason for hiding this comment

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

Required for testing purposes, where we don't actually have jquery with entwine in the DOM.

});
}
};
Expand Down
1 change: 0 additions & 1 deletion client/src/components/ElementActions/SaveAction.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global window */
import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('ArchiveAction', () => {
const mockMutation = jest.fn(() => new Promise((resolve) => { resolve(); }));
const WrappedComponent = (props) => <div>{props.children}</div>;
const ActionComponent = ArchiveAction(WrappedComponent);
const jQuery = jest.fn();
window.jQuery = jQuery;

beforeEach(() => {
wrapper = mount(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */
/* global jest, describe, it, expect, window */

jest.mock('isomorphic-fetch', () =>
() => Promise.resolve({
json: () => ({}),
})
);

Comment on lines +4 to +9
Copy link
Member Author

Choose a reason for hiding this comment

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

Taken from TreeDropdownField-test.js to avoid ReferenceError: TextEncoder is not defined when running jest tests. See this stackoverflow question for more details about this error and its causes.

import React from 'react';
import { Component as PublishAction } from '../PublishAction';
import Enzyme, { mount } from 'enzyme';
Expand Down
6 changes: 6 additions & 0 deletions client/src/components/ElementActions/tests/SaveAction-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */
/* global jest, describe, it, expect */

jest.mock('isomorphic-fetch', () =>
() => Promise.resolve({
json: () => ({}),
})
);

import React from 'react';
import { Component as SaveAction } from '../SaveAction';
import Enzyme, { mount } from 'enzyme';
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/ElementEditor/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Content.propTypes = {
fileUrl: PropTypes.string,
fileTitle: PropTypes.string,
previewExpanded: PropTypes.bool,
SummaryComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
InlineEditFormComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
SummaryComponent: PropTypes.elementType,
InlineEditFormComponent: PropTypes.elementType,
handleLoadingError: PropTypes.func,
broken: PropTypes.bool,
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ElementEditor/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Header.propTypes = {
areaId: PropTypes.number,
activeTab: PropTypes.string,
simple: PropTypes.bool,
ElementActionsComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
ElementActionsComponent: PropTypes.elementType,
previewExpanded: PropTypes.bool,
disableTooltip: PropTypes.bool,
formDirty: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ElementEditor/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Toolbar.defaultProps = {};
Toolbar.propTypes = {
elementTypes: PropTypes.arrayOf(elementTypeType).isRequired,
areaId: PropTypes.number.isRequired,
AddNewButtonComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
AddNewButtonComponent: PropTypes.elementType.isRequired,
connectDropTarget: PropTypes.func.isRequired,
onDragOver: PropTypes.func, // eslint-disable-line react/no-unused-prop-types
onDragDrop: PropTypes.func, // eslint-disable-line react/no-unused-prop-types
Expand Down
20 changes: 14 additions & 6 deletions client/src/legacy/ElementEditor/entwine.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 { createRoot } from 'react-dom/client';
import { loadComponent } from 'lib/Injector';
import { getConfig } from 'state/editor/elementConfig';
import { destroy } from 'redux-form';
Expand Down Expand Up @@ -40,6 +40,8 @@ const resetStores = () => {
*/
jQuery.entwine('ss', ($) => {
$('.js-injector-boot .element-editor__container').entwine({
ReactRoot: null,

onmatch() {
const context = {};
const ElementEditorComponent = loadComponent('ElementEditor', context);
Expand All @@ -53,15 +55,21 @@ jQuery.entwine('ss', ($) => {
elementTypes,
};

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/state/editor/addElementMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';
import { query as readBlocksQuery, config as readBlocksConfig } from './readBlocksForAreaQuery';

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/editor/archiveBlockMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';
import { config as readBlocksConfig, query as readBlocksQuery } from './readBlocksForAreaQuery';

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/editor/duplicateBlockMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';
import { config as readBlocksConfig, query as readBlocksQuery } from './readBlocksForAreaQuery';

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/editor/publishBlockMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';
import { config as readBlocksConfig, query as readBlocksQuery } from './readBlocksForAreaQuery';

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/editor/readBlocksForAreaQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';

// GraphQL query for retrieving the current state of elements for an area. The results of the query
Expand Down
5 changes: 3 additions & 2 deletions client/src/state/editor/sortBlockMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';
import { query as readBlocksQuery, config as readBlocksConfig } from './readBlocksForAreaQuery';

Expand Down Expand Up @@ -26,7 +26,8 @@ const config = {
optimisticResponse: {
sortBlock: {
id: blockId,
liveVersion: false,
isLiveVersion: false,
isPublished: false,
__typename: 'Block',
},
},
Expand Down
2 changes: 1 addition & 1 deletion client/src/state/editor/unpublishBlockMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';
import { config as readBlocksConfig, query as readBlocksQuery } from './readBlocksForAreaQuery';

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/history/readOneBlockQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';

// GraphQL query for retrieving the version history of a specific block. The results of
Expand Down
2 changes: 1 addition & 1 deletion client/src/state/history/revertToBlockVersionMutation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql } from 'react-apollo';
import { graphql } from '@apollo/client/react/hoc';
import gql from 'graphql-tag';

const mutation = gql`
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/elementTypeType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const elementTypeType = PropTypes.shape({
// A font-icon class to be used for the icon of the element
icon: PropTypes.string,
// Whether the element is in-line editable
inlineEditable: PropTypes.boolean,
inlineEditable: PropTypes.bool,
// The top level edit tabs for this element (Usually "Content" and "Settings")
editTabs: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string,
Expand Down
80 changes: 40 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "silverstripe-elemental",
"version": "1.0.0",
"description": "Compose your SilverStripe content of Elements",
"engines": {
"node": "^18.x"
},
"scripts": {
"build": "yarn && yarn lint && yarn test && NODE_ENV=production webpack -p --bail --progress",
"build": "yarn && yarn lint && yarn test && 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 @@ -31,45 +33,55 @@
},
"homepage": "https://github.com/dnadesign/silverstripe-elemental#readme",
"dependencies": {
"apollo-client": "^2.3.1",
"bootstrap": "^4.3.1",
"classnames": "^2.2.5",
"graphql": "^14.0.0",
"graphql-tag": "^2.10.0",
"jquery": "^3.5.0",
"popper.js": "^1.14.7",
"prop-types": "^15.6.2",
"react": "^16.6.1",
"react-apollo": "^2.1.0",
"@apollo/client": "^3.7.1",
"@popperjs/core": "^2.11.6",
"bootstrap": "^4.6.2",
"classnames": "^2.3.2",
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dnd": "^5.0.0",
"react-dnd-html5-backend": "^5.0.1",
"react-dom": "^16.6.1",
"react-redux": "^5.0.7",
"reactstrap": "^6.4.0",
"redux": "^4.0.0",
"redux-form": "^6.8.0"
"react-dom": "^18.2.0",
"react-redux": "^8.0.4",
"reactstrap": "^8.9.0",
"redux": "^4.2.0",
"redux-form": "^8.3.8"
},
"devDependencies": {
"@silverstripe/eslint-config": "^0.1.0",
"@silverstripe/webpack-config": "^1.5.0",
"babel-jest": "^23.6.0",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"jest-cli": "^23.6.0"
"@silverstripe/eslint-config": "^1.0.0-alpha6",
"@silverstripe/webpack-config": "^2.0.0-alpha5",
"babel-jest": "^29.2.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"jest-cli": "^29.2.2",
"jest-environment-jsdom": "^29.3.1",
"react-16": "npm:react@^16.14.0",
"react-dom-16": "npm:react-dom@^16.14.0",
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0"
},
"resolutions": {
"colors": "1.1.2"
"colors": "1.4.0"
},
"browserslist": [
"defaults"
],
"jest": {
"testEnvironment": "jsdom",
"moduleNameMapper": {
"^react-dom/client$": "react-dom-16",
"^react-dom((/.*)?)$": "react-dom-16$1",
"^react((/.*)?)$": "react-16$1"
},
"roots": [
"client/src"
],
"moduleDirectories": [
"client/src",
"node_modules",
"node_modules/@silverstripe/webpack-config/node_modules",
"../../admin/client/src",
"../../admin/node_modules",
"../admin/client/src",
"../admin/node_modules",
"vendor/silverstripe/admin/client/src",
"vendor/silverstripe/admin/node_modules"
],
Expand All @@ -79,17 +91,5 @@
"transform": {
".*": "babel-jest"
}
},
"babel": {
"presets": [
"env",
"react"
],
"plugins": [
"transform-object-rest-spread"
]
},
"engines": {
"node": "^10.x"
}
}
4 changes: 2 additions & 2 deletions src/Extensions/ElementalPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use DNADesign\Elemental\Models\ElementalArea;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\View\Parsers\HTML4Value;
use SilverStripe\View\Parsers\HTMLValue;
use SilverStripe\View\SSViewer;

/**
Expand Down Expand Up @@ -87,7 +87,7 @@ public function MetaTags(&$tags)
$controller = Controller::curr();
$request = $controller->getRequest();
if ($request->getVar('ElementalPreview') !== null) {
$html = HTML4Value::create($tags);
$html = HTMLValue::create($tags);
$xpath = "//meta[@name='x-page-id' or @name='x-cms-edit-link']";
$removeTags = $html->query($xpath);
$body = $html->getBody();
Expand Down
5 changes: 1 addition & 4 deletions tests/Behat/Context/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Models\ElementContent;
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;
use SilverStripe\CMS\Tests\Behaviour\FixtureContext as BaseFixtureContext;
Copy link
Member Author

Choose a reason for hiding this comment

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

Necessary to include the anchor dropdown fixture method - we can't just add the SilverStripe\CMS\Tests\Behaviour\FixtureContext class to the fixtures in behat.yml because it has the same superclass as this one, which causes behat to fail since it doesn't know whether to call methods from this fixture class or the CMS one.
Using the CMS fixture class as the superclass here resolves that problem.

use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Queries\SQLInsert;

if (!class_exists(BaseFixtureContext::class)) {
return;
}
/**
* Context used to create fixtures in the SilverStripe ORM.
*/
Expand Down
Loading