diff --git a/packages/strapi-admin/admin/src/app.js b/packages/strapi-admin/admin/src/app.js index f6a6012b49..137b33181c 100644 --- a/packages/strapi-admin/admin/src/app.js +++ b/packages/strapi-admin/admin/src/app.js @@ -19,6 +19,8 @@ import { pluginLoaded, unfreezeApp, updatePlugin, + getAppPluginsSucceeded, + // unsetHasUserPlugin, } from './containers/App/actions'; import { showNotification } from './containers/NotificationProvider/actions'; import injectReducer from './utils/injectReducer'; @@ -41,6 +43,10 @@ const store = configureStore(initialState, history); const { dispatch } = store; const MOUNT_NODE = document.getElementById('app'); +// TODO remove temporary to access the admin + +dispatch(getAppPluginsSucceeded([])); + // TODO const remoteURL = (() => { if (window.location.port === '4000') { @@ -156,5 +162,10 @@ if (!window.Intl) { render(translationMessages); } -// cc/ @Pierre Burgy exporting dispatch for the notifications +// @Pierre Burgy exporting dispatch for the notifications... export { dispatch }; + +// TODO remove this for the new Cypress tests +if (window.Cypress) { + window.__store__ = Object.assign(window.__store__ || {}, { store }); +} diff --git a/packages/strapi-admin/admin/src/appDev.js b/packages/strapi-admin/admin/src/appDev.js deleted file mode 100644 index 35fef0636e..0000000000 --- a/packages/strapi-admin/admin/src/appDev.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * appDev.js - * - * This is then entry file for the application in development - * - */ - -import { findIndex } from 'lodash'; -import 'babel-polyfill'; -import 'sanitize.css/sanitize.css'; -import { - getAppPluginsSucceeded, - unsetHasUserPlugin, -} from './containers/App/actions'; -import { store } from './createStore'; -import render from './renderApp'; -import './intlPolyfill'; -import './strapi'; - -const dispatch = store.dispatch; -const plugins = (() => { - try { - return require('./config/plugins.json'); - } catch (e) { - return []; - } -})(); - -dispatch(getAppPluginsSucceeded(plugins)); - -// Hot reloadable translation json files -if (module.hot) { - // modules.hot.accept does not accept dynamic dependencies, - // have to be constants at compile-time - module.hot.accept('./i18n', () => { - render(translationMessages); - }); -} - -if (findIndex(plugins, ['id', 'users-permissions']) === -1) { - dispatch(unsetHasUserPlugin()); -} - -export { dispatch }; diff --git a/packages/strapi-admin/admin/src/components/ListPlugins/index.js b/packages/strapi-admin/admin/src/components/ListPlugins/index.js index f7d8e6e5d3..71b85f456f 100644 --- a/packages/strapi-admin/admin/src/components/ListPlugins/index.js +++ b/packages/strapi-admin/admin/src/components/ListPlugins/index.js @@ -1,9 +1,9 @@ /* -* -* -* ListPlugins -* -*/ + * + * + * ListPlugins + * + */ import React from 'react'; import PropTypes from 'prop-types'; @@ -16,7 +16,7 @@ import Row from '../Row'; import styles from './styles.scss'; -class ListPlugins extends React.PureComponent { +class ListPlugins extends React.Component { render() { const listSize = size(this.props.plugins); let titleType = listSize === 1 ? 'singular' : 'plural'; @@ -29,14 +29,17 @@ class ListPlugins extends React.PureComponent {
- +
diff --git a/packages/strapi-admin/admin/src/containers/Admin/index.js b/packages/strapi-admin/admin/src/containers/Admin/index.js index 7bbfb51168..9016fadba4 100644 --- a/packages/strapi-admin/admin/src/containers/Admin/index.js +++ b/packages/strapi-admin/admin/src/containers/Admin/index.js @@ -12,13 +12,6 @@ import { createStructuredSelector } from 'reselect'; import { bindActionCreators, compose } from 'redux'; import { Switch, Route } from 'react-router-dom'; -// Actions from strapi-helper-plugin -// Actions required for disabling and enabling the OverlayBlocker -import { - disableGlobalOverlayBlocker, - enableGlobalOverlayBlocker, -} from 'actions/overlayBlocker'; - // Components from strapi-helper-plugin import LoadingIndicatorPage from 'components/LoadingIndicatorPage'; import OverlayBlocker from 'components/OverlayBlocker'; @@ -38,7 +31,11 @@ import NotFoundPage from '../NotFoundPage/Loadable'; import Onboarding from '../Onboarding'; import PluginDispatcher from '../PluginDispatcher'; -import { updatePlugin } from '../App/actions'; +import { + disableGlobalOverlayBlocker, + enableGlobalOverlayBlocker, + updatePlugin, +} from '../App/actions'; import makeSelecApp from '../App/selectors'; import injectSaga from '../../utils/injectSaga'; diff --git a/packages/strapi-admin/admin/src/containers/App/actions.js b/packages/strapi-admin/admin/src/containers/App/actions.js index 550e1bb624..fe8118ed39 100644 --- a/packages/strapi-admin/admin/src/containers/App/actions.js +++ b/packages/strapi-admin/admin/src/containers/App/actions.js @@ -5,6 +5,8 @@ */ import { + DISABLE_GLOBAL_OVERLAY_BLOCKER, + ENABLE_GLOBAL_OVERLAY_BLOCKER, FREEZE_APP, GET_APP_PLUGINS_SUCCEEDED, LOAD_PLUGIN, @@ -15,6 +17,18 @@ import { UPDATE_PLUGIN, } from './constants'; +export function disableGlobalOverlayBlocker() { + return { + type: DISABLE_GLOBAL_OVERLAY_BLOCKER, + }; +} + +export function enableGlobalOverlayBlocker() { + return { + type: ENABLE_GLOBAL_OVERLAY_BLOCKER, + }; +} + export function freezeApp(data) { return { type: FREEZE_APP, diff --git a/packages/strapi-admin/admin/src/containers/App/constants.js b/packages/strapi-admin/admin/src/containers/App/constants.js index 10ce89cdb0..7c08436273 100644 --- a/packages/strapi-admin/admin/src/containers/App/constants.js +++ b/packages/strapi-admin/admin/src/containers/App/constants.js @@ -12,3 +12,7 @@ export const PLUGIN_DELETED = 'app/App/PLUGIN_DELETED'; export const UNFREEZE_APP = 'app/App/UNFREEZE_APP'; export const UNSET_HAS_USERS_PLUGIN = 'app/App/UNSET_HAS_USERS_PLUGIN'; export const UPDATE_PLUGIN = 'app/App/UPDATE_PLUGIN'; +export const DISABLE_GLOBAL_OVERLAY_BLOCKER = + 'app/App/OverlayBlocker/DISABLE_GLOBAL_OVERLAY_BLOCKER'; +export const ENABLE_GLOBAL_OVERLAY_BLOCKER = + 'app/App/OverlayBlocker/ENABLE_GLOBAL_OVERLAY_BLOCKER'; diff --git a/packages/strapi-admin/admin/src/containers/App/reducer.js b/packages/strapi-admin/admin/src/containers/App/reducer.js index e62ab77c0f..78d1b07ff2 100644 --- a/packages/strapi-admin/admin/src/containers/App/reducer.js +++ b/packages/strapi-admin/admin/src/containers/App/reducer.js @@ -1,12 +1,9 @@ // Shared constants -import { - DISABLE_GLOBAL_OVERLAY_BLOCKER, - ENABLE_GLOBAL_OVERLAY_BLOCKER, -} from 'constants/overlayBlocker'; - import { fromJS, List } from 'immutable'; import { + DISABLE_GLOBAL_OVERLAY_BLOCKER, + ENABLE_GLOBAL_OVERLAY_BLOCKER, FREEZE_APP, GET_APP_PLUGINS_SUCCEEDED, PLUGIN_DELETED, diff --git a/packages/strapi-admin/admin/src/createStore.js b/packages/strapi-admin/admin/src/createStore.js deleted file mode 100644 index 611d0587e6..0000000000 --- a/packages/strapi-admin/admin/src/createStore.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Common configuration for the app in both dev an prod mode - */ - -import { createBrowserHistory } from 'history'; - -import './public-path'; -import configureStore from './configureStore'; - -const basename = strapi.remoteURL.replace(window.location.origin, ''); -const history = createBrowserHistory({ - basename, -}); -const store = configureStore({}, history); - -if (window.Cypress) { - window.__store__ = Object.assign(window.__store__ || {}, { store }); -} - -export { basename, history, store }; diff --git a/packages/strapi-admin/admin/src/intlPolyfill.js b/packages/strapi-admin/admin/src/intlPolyfill.js deleted file mode 100644 index 9fb314c013..0000000000 --- a/packages/strapi-admin/admin/src/intlPolyfill.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Common configuration for the app in both dev an prod mode - */ -import { translationMessages } from './i18n'; -import './public-path'; -import render from './renderApp'; - -// Chunked polyfill for browsers without Intl support -window.onload = function onLoad() { - if (!window.Intl) { - Promise.all([ - System.import('intl'), - System.import('intl/locale-data/jsonp/en.js'), - System.import('intl/locale-data/jsonp/fr.js'), - ]).then(() => render(translationMessages)); - } else { - render(translationMessages); - } -}; \ No newline at end of file diff --git a/packages/strapi-admin/admin/src/store.js b/packages/strapi-admin/admin/src/store.js deleted file mode 100644 index 9e98513d44..0000000000 --- a/packages/strapi-admin/admin/src/store.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Create the store with dynamic reducers - */ - -import { createStore, applyMiddleware, compose } from 'redux'; -import { fromJS } from 'immutable'; -import { routerMiddleware } from 'react-router-redux'; -import createSagaMiddleware from 'redux-saga'; -import createReducer from './reducers'; - -const sagaMiddleware = createSagaMiddleware(); - -export default function configureStore(initialState = {}, history) { - // Create the store with two middlewares - // 1. sagaMiddleware: Makes redux-sagas work - // 2. routerMiddleware: Syncs the location/URL path to the state - const middlewares = [ - sagaMiddleware, - routerMiddleware(history), - ]; - - const enhancers = [ - applyMiddleware(...middlewares), - ]; - - // If Redux DevTools Extension is installed use it, otherwise use Redux compose - /* eslint-disable no-underscore-dangle */ - const composeEnhancers = - process.env.NODE_ENV !== 'production' && - typeof window === 'object' && - window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ - ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ - // TODO Try to remove when `react-router-redux` is out of beta, LOCATION_CHANGE should not be fired more than once after hot reloading - // Prevent recomputing reducers for `replaceReducer` - shouldHotReload: false, - name: `Strapi - Dashboard`, - }) - : compose; - /* eslint-enable */ - - const store = createStore( - createReducer(), - fromJS(initialState), - composeEnhancers(...enhancers) - ); - - // Extensions - store.runSaga = sagaMiddleware.run; - store.injectedReducers = {}; // Reducer registry - store.injectedSagas = {}; // Saga registry - - // Make reducers hot reloadable, see http://mxs.is/googmo - /* istanbul ignore next */ - if (module.hot) { - module.hot.accept('./reducers', () => { - store.replaceReducer(createReducer(store.injectedReducers)); - }); - } - - return store; -} diff --git a/packages/strapi-admin/admin/src/strapi.js b/packages/strapi-admin/admin/src/strapi.js deleted file mode 100644 index 2bbc2825e5..0000000000 --- a/packages/strapi-admin/admin/src/strapi.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Common configuration for the app in both dev an prod mode - */ - -import { merge } from 'lodash'; -import { - freezeApp, - pluginLoaded, - unfreezeApp, - updatePlugin, -} from './containers/App/actions'; -import { showNotification } from './containers/NotificationProvider/actions'; -import injectReducer from './utils/injectReducer'; -import injectSaga from './utils/injectSaga'; -// import { history, store } from './createStore'; -import { translationMessages, languages } from './i18n'; -// import './public-path'; - -/** - * Register a plugin - * - * @param params - */ -const registerPlugin = plugin => { - // Merge admin translation messages - merge(translationMessages, plugin.translationMessages); - - plugin.leftMenuSections = plugin.leftMenuSections || []; - - store.dispatch(pluginLoaded(plugin)); -}; -const displayNotification = (message, status) => { - store.dispatch(showNotification(message, status)); -}; -const lockApp = data => { - store.dispatch(freezeApp(data)); -}; -const unlockApp = () => { - store.dispatch(unfreezeApp()); -}; - -window.strapi = Object.assign(window.strapi || {}, { - node: process.env.MODE || 'host', - registerPlugin, - notification: { - success: message => { - displayNotification(message, 'success'); - }, - warning: message => { - displayNotification(message, 'warning'); - }, - error: message => { - displayNotification(message, 'error'); - }, - info: message => { - displayNotification(message, 'info'); - }, - }, - refresh: pluginId => ({ - translationMessages: translationMessagesUpdated => { - render(merge({}, translationMessages, translationMessagesUpdated)); - }, - leftMenuSections: leftMenuSectionsUpdated => { - store.dispatch( - updatePlugin(pluginId, 'leftMenuSections', leftMenuSectionsUpdated), - ); - }, - }), - router: history, - languages, - currentLanguage: - window.localStorage.getItem('strapi-admin-language') || - window.navigator.language || - window.navigator.userLanguage || - 'en', - lockApp, - unlockApp, - injectReducer, - injectSaga, - store, -}); diff --git a/packages/strapi-admin/package.json b/packages/strapi-admin/package.json index 573c453441..d2f399413b 100644 --- a/packages/strapi-admin/package.json +++ b/packages/strapi-admin/package.json @@ -30,10 +30,26 @@ "@babel/polyfill": "^7.4.3", "crypto": "^1.0.1", "friendly-errors-webpack-plugin": "^1.7.0", + "history": "^4.9.0", "html-webpack-plugin": "^3.2.0", + "immutable": "^3.8.2", "intl": "^1.2.5", + "prop-types": "^15.7.2", + "react": "^16.8.6", + "react-copy-to-clipboard": "^5.0.1", + "react-dnd": "^7.4.5", + "react-dnd-html5-backend": "^7.4.4", + "react-dom": "^16.8.6", "react-ga": "^2.4.1", + "react-helmet": "^5.2.0", + "react-intl": "^2.8.0", + "react-redux": "^7.0.1", + "react-router": "^5.0.0", + "react-router-dom": "^5.0.0", + "react-transition-group": "^2.9.0", "redux": "^4.0.1", + "redux-immutable": "^4.0.0", + "redux-saga": "^1.0.2", "remove-markdown": "^0.2.2", "shelljs": "^0.7.8", "video-react": "^0.13.2" diff --git a/packages/strapi-admin/webpack.config.js b/packages/strapi-admin/webpack.config.js index 31b246ca6d..1b6d9f5005 100644 --- a/packages/strapi-admin/webpack.config.js +++ b/packages/strapi-admin/webpack.config.js @@ -27,12 +27,21 @@ const PORT = 4000; const webpackPlugins = devMode ? [ new WebpackDashboard(), - new DuplicatePckgChecker(), + new DuplicatePckgChecker({ + verbose: true, + exclude(instance) { + return instance.name === 'core-js'; + }, + }), new OpenBrowserWebpackPlugin({ url: `http://localhost:${PORT}/${URLs.publicPath}`, }), ] : [ + new webpack.IgnorePlugin({ + resourceRegExp: /^\.\/locale$/, + contextRegExp: /moment$/, + }), new MiniCssExtractPlugin({ // Options similar to the same options in webpackOptions.output // both options are optional @@ -63,7 +72,7 @@ module.exports = { index: URLs.publicPath, }, port: 4000, - hot: true, + // hot: true, }, stats: devMode ? 'minimal' : 'errors-only', devtool: 'cheap-module-source-map', diff --git a/packages/strapi-helper-plugin/package.json b/packages/strapi-helper-plugin/package.json index 32ccbf4327..d06d5e36b3 100644 --- a/packages/strapi-helper-plugin/package.json +++ b/packages/strapi-helper-plugin/package.json @@ -27,87 +27,31 @@ "lint:admin" ], "devDependencies": { - "add-asset-html-webpack-plugin": "^2.1.2", - "babel-cli": "6.26.0", - "babel-core": "6.26.0", - "babel-loader": "7.1.1", - "babel-plugin-istanbul": "4.1.5", - "babel-plugin-styled-components": "1.5.1", - "babel-plugin-transform-es2015-destructuring": "6.23.0", - "babel-plugin-transform-es2015-parameters": "6.24.1", - "babel-plugin-transform-object-rest-spread": "6.26.0", - "babel-plugin-transform-react-constant-elements": "6.23.0", - "babel-plugin-transform-react-inline-elements": "6.22.0", - "babel-plugin-transform-react-remove-prop-types": "0.4.18", - "babel-preset-env": "1.6.1", - "babel-preset-react": "6.24.1", - "babel-preset-react-hmre": "1.1.1", - "babel-preset-stage-0": "6.24.1", "chalk": "^2.1.0", - "copy-webpack-plugin": "^4.3.1", - "css-loader": "^0.28.5", "cross-env": "^5.0.5", "enzyme": "^3.8.0", "enzyme-adapter-react-16": "^1.8.0", "enzyme-to-json": "^3.3.5", - "exports-loader": "^0.6.4", - "extract-text-webpack-plugin": "^3.0.0", "express": "^4.15.4", - "file-loader": "^0.11.2", - "html-loader": "^0.5.1", - "html-webpack-plugin": "^2.30.1", - "image-webpack-loader": "^4.3.1", - "lodash-webpack-plugin": "^0.11.4", - "node-sass": "^4.5.3", - "null-loader": "^0.1.1", "plop": "^2.2.0", - "postcss-cssnext": "^2.11.0", - "postcss-focus": "^2.0.0", - "postcss-loader": "^2.0.6", - "postcss-reporter": "^5.0.0", - "postcss-smart-import": "^0.7.5", - "precss": "^2.0.0", "prettier": "^1.5.3", "react-test-renderer": "^16.7.0", "rimraf": "^2.6.1", - "sass-loader": "^6.0.6", - "shelljs": "^0.7.8", - "style-loader": "^0.18.2", - "url-loader": "^1.1.1", - "webpack": "^3.5.5", - "webpack-bundle-analyzer": "^2.9.0", - "webpack-dev-middleware": "^1.12.0", - "webpack-hot-middleware": "^2.18.2" + "shelljs": "^0.7.8" }, "dependencies": { - "babel-polyfill": "6.26.0", "bootstrap": "^4.0.0-alpha.6", "classnames": "^2.2.5", - "history": "^4.9.0", - "immutable": "^3.8.2", "imports-loader": "^0.7.1", "invariant": "2.2.1", "json-loader": "^0.5.7", "lodash": "^4.17.5", "moment": "^2.16.0", - "prop-types": "^15.5.10", - "react": "^16.8.4", - "react-copy-to-clipboard": "^5.0.1", "react-datetime": "^2.15.0", - "react-dnd": "^5.0.0", - "react-dnd-html5-backend": "^5.0.1", - "react-dom": "^16.5.2", - "react-helmet": "^5.1.3", - "react-intl": "^2.7.0", "react-loadable": "^5.5.0", - "react-redux": "^5.0.7", - "react-router-dom": "^4.3.1", "react-router-redux": "^5.0.0-alpha.9", "react-transition-group": "^2.5.0", "reactstrap": "^5.0.0", - "redux": "^4.0.0", - "redux-immutable": "^4.0.0", - "redux-saga": "^0.16.0", "reselect": "^3.0.1", "styled-components": "^3.2.6", "whatwg-fetch": "^2.0.3"