diff --git a/packages/strapi-admin/admin/src/app.js b/packages/strapi-admin/admin/src/app.js index c653c385b9..b780d9927b 100644 --- a/packages/strapi-admin/admin/src/app.js +++ b/packages/strapi-admin/admin/src/app.js @@ -40,6 +40,9 @@ import { translationMessages, languages } from './i18n'; // Create redux store with history import history from './utils/history'; + +import plugins from './plugins'; + const initialState = {}; const store = configureStore(initialState, history); const { dispatch } = store; @@ -47,7 +50,18 @@ const MOUNT_NODE = document.getElementById('app'); // TODO remove temporary to access the admin -dispatch(getAppPluginsSucceeded([])); +dispatch(getAppPluginsSucceeded(Object.keys(plugins))); + +Object.keys(plugins).forEach(plugin => { + const currentPlugin = plugins[plugin]; + + try { + merge(translationMessages, currentPlugin.translationMessages); + dispatch(pluginLoaded(currentPlugin)); + } catch (err) { + console.log({ err }); + } +}); // TODO const remoteURL = (() => { @@ -63,14 +77,6 @@ const remoteURL = (() => { return process.env.REMOTE_URL.replace(/\/$/, ''); })(); -const registerPlugin = plugin => { - // Merge admin translation messages - merge(translationMessages, plugin.translationMessages); - - plugin.leftMenuSections = plugin.leftMenuSections || []; - - dispatch(pluginLoaded(plugin)); -}; const displayNotification = (message, status) => { dispatch(showNotification(message, status)); }; @@ -85,7 +91,6 @@ window.strapi = Object.assign(window.strapi || {}, { node: MODE || 'host', remoteURL, backendURL: BACKEND_URL, - registerPlugin, notification: { success: message => { displayNotification(message, 'success'); diff --git a/packages/strapi-admin/admin/src/components/OnboardingVideo/index.js b/packages/strapi-admin/admin/src/components/OnboardingVideo/index.js index e6b95cf1b4..c2bf0e5de0 100644 --- a/packages/strapi-admin/admin/src/components/OnboardingVideo/index.js +++ b/packages/strapi-admin/admin/src/components/OnboardingVideo/index.js @@ -16,9 +16,7 @@ import styles from './styles.scss'; class OnboardingVideo extends React.Component { componentDidMount() { - this.hiddenPlayer.current.subscribeToStateChange( - this.handleChangeState, - ); + this.hiddenPlayer.current.subscribeToStateChange(this.handleChangeState); } hiddenPlayer = React.createRef(); @@ -28,7 +26,7 @@ class OnboardingVideo extends React.Component { handleChangeState = (state, prevState) => { const { duration } = state; const { id } = this.props; - + if (duration !== prevState.duration) { this.props.setVideoDuration(id, duration); } @@ -43,14 +41,16 @@ class OnboardingVideo extends React.Component { } }; - handleCurrentTimeChange = (curr) => { - this.props.getVideoCurrentTime(this.props.id, curr, this.props.video.duration); - } + handleCurrentTimeChange = curr => { + this.props.getVideoCurrentTime( + this.props.id, + curr, + this.props.video.duration, + ); + }; handleModalOpen = () => { - this.player.current.subscribeToStateChange( - this.handleChangeIsPlayingState, - ); + this.player.current.subscribeToStateChange(this.handleChangeIsPlayingState); this.player.current.play(); @@ -89,7 +89,7 @@ class OnboardingVideo extends React.Component { key={this.props.id} onClick={this.props.onClick} id={this.props.id} - className={cn(styles.listItem, video.end && (styles.finished))} + className={cn(styles.listItem, video.end && styles.finished)} >
preview @@ -98,9 +98,15 @@ class OnboardingVideo extends React.Component {

{video.title}

-

{isNaN(video.duration) ? '\xA0' : `${Math.floor(video.duration / 60)}:${Math.floor(video.duration)%60}`}

+

+ {isNaN(video.duration) + ? '\xA0' + : `${Math.floor(video.duration / 60)}:${Math.floor( + video.duration, + ) % 60}`} +

- + { e.preventDefault(); e.stopPropagation(); - this.context.router.history.push(settingsPath); + this.props.history.push(settingsPath); }, }, { @@ -106,7 +107,6 @@ class Row extends React.Component { Row.contextTypes = { currentEnvironment: PropTypes.string, - router: PropTypes.object, }; Row.propTypes = { @@ -117,4 +117,4 @@ Row.propTypes = { pluginActionSucceeded: PropTypes.bool.isRequired, }; -export default Row; +export default withRouter(Row); diff --git a/packages/strapi-admin/admin/src/containers/App/reducer.js b/packages/strapi-admin/admin/src/containers/App/reducer.js index 5ace99cf5e..78d1b07ff2 100644 --- a/packages/strapi-admin/admin/src/containers/App/reducer.js +++ b/packages/strapi-admin/admin/src/containers/App/reducer.js @@ -18,7 +18,7 @@ const initialState = fromJS({ blockApp: false, overlayBlockerData: null, hasUserPlugin: true, - isAppLoading: false, + isAppLoading: true, plugins: {}, showGlobalAppBlocker: true, }); diff --git a/packages/strapi-admin/admin/src/containers/LanguageProvider/index.js b/packages/strapi-admin/admin/src/containers/LanguageProvider/index.js index 41ad7d9322..7c618ad0fe 100644 --- a/packages/strapi-admin/admin/src/containers/LanguageProvider/index.js +++ b/packages/strapi-admin/admin/src/containers/LanguageProvider/index.js @@ -14,12 +14,19 @@ import { IntlProvider } from 'react-intl'; import { defaultsDeep } from 'lodash'; import { selectLocale } from './selectors'; -export class LanguageProvider extends React.Component { // eslint-disable-line react/prefer-stateless-function +export class LanguageProvider extends React.Component { + // eslint-disable-line react/prefer-stateless-function render() { - const messages = defaultsDeep(this.props.messages[this.props.locale], this.props.messages.en); - + const messages = defaultsDeep( + this.props.messages[this.props.locale], + this.props.messages.en, + ); return ( - + {React.Children.only(this.props.children)} ); @@ -32,10 +39,9 @@ LanguageProvider.propTypes = { messages: PropTypes.object.isRequired, }; - const mapStateToProps = createSelector( selectLocale(), - (locale) => ({ locale }) + locale => ({ locale }), ); function mapDispatchToProps(dispatch) { @@ -44,4 +50,7 @@ function mapDispatchToProps(dispatch) { }; } -export default connect(mapStateToProps, mapDispatchToProps)(LanguageProvider); +export default connect( + mapStateToProps, + mapDispatchToProps, +)(LanguageProvider); diff --git a/packages/strapi-admin/admin/src/plugins.js b/packages/strapi-admin/admin/src/plugins.js new file mode 100644 index 0000000000..3e7632a881 --- /dev/null +++ b/packages/strapi-admin/admin/src/plugins.js @@ -0,0 +1,23 @@ +// console.log(window); +const injectReducer = require('./utils/injectReducer').default; +const injectSaga = require('./utils/injectSaga').default; +const { languages } = require('./i18n'); + +window.strapi = Object.assign(window.strapi || {}, { + node: MODE || 'host', + backendURL: BACKEND_URL, + languages, + currentLanguage: + window.localStorage.getItem('strapi-admin-language') || + window.navigator.language || + window.navigator.userLanguage || + 'en', + injectReducer, + injectSaga, +}); + +module.exports = { + email: require('../../../strapi-plugin-email/admin/src').default, + 'users-permissions': require('../../../strapi-plugin-users-permissions/admin/src') + .default, +}; diff --git a/packages/strapi-admin/package.json b/packages/strapi-admin/package.json index 11c3068b99..e51d549008 100644 --- a/packages/strapi-admin/package.json +++ b/packages/strapi-admin/package.json @@ -28,11 +28,11 @@ }, "dependencies": { "@babel/polyfill": "^7.4.3", + "@babel/runtime": "^7.4.3", + "classnames": "^2.2.6", "crypto": "^1.0.1", - "friendly-errors-webpack-plugin": "^1.7.0", "history": "^4.9.0", "hoist-non-react-statics": "^3.3.0", - "html-webpack-plugin": "^3.2.0", "immutable": "^3.8.2", "intl": "^1.2.5", "invariant": "^2.2.4", @@ -56,7 +56,6 @@ "redux-saga": "^0.16.0", "remove-markdown": "^0.2.2", "reselect": "^3.0.1", - "shelljs": "^0.7.8", "strapi-helper-plugin": "3.0.0-alpha.25.2", "video-react": "^0.13.2" }, @@ -74,7 +73,9 @@ "css-loader": "^2.1.1", "duplicate-package-checker-webpack-plugin": "^3.0.0", "file-loader": "^3.0.1", + "friendly-errors-webpack-plugin": "^1.7.0", "html-loader": "^0.5.5", + "html-webpack-plugin": "^3.2.0", "image-webpack-loader": "^4.6.0", "mini-css-extract-plugin": "^0.6.0", "node-sass": "^4.11.0", @@ -84,6 +85,7 @@ "precss": "^4.0.0", "sanitize.css": "^4.1.0", "sass-loader": "^7.1.0", + "shelljs": "^0.7.8", "simple-progress-webpack-plugin": "^1.1.2", "strapi-utils": "3.0.0-alpha.25.2", "style-loader": "^0.23.1", @@ -110,4 +112,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi-admin/webpack.alias.js b/packages/strapi-admin/webpack.alias.js index 81e004838b..640e31963b 100644 --- a/packages/strapi-admin/webpack.alias.js +++ b/packages/strapi-admin/webpack.alias.js @@ -1,14 +1,10 @@ const path = require('path'); -const alias = [ - 'core-js', - 'create-react-context', - 'invariant', - 'hoist-non-react-statics', +const pkg = require('./package.json'); + +const alias = Object.keys(pkg.dependencies).concat([ 'object-assign', - 'react-popper', - 'reactstrap', 'whatwg-fetch', -]; +]); module.exports = alias.reduce((acc, curr) => { acc[curr] = path.resolve(__dirname, 'node_modules', curr); diff --git a/packages/strapi-admin/webpack.config.js b/packages/strapi-admin/webpack.config.js index 1cf4ed3aa7..960ed69b88 100644 --- a/packages/strapi-admin/webpack.config.js +++ b/packages/strapi-admin/webpack.config.js @@ -91,11 +91,6 @@ module.exports = { { test: /\.m?js$/, exclude: /node_modules/, - include: [ - path.resolve(__dirname, 'admin/src'), - path.resolve(__dirname, '../strapi-helper-plugin/lib/src'), - path.resolve(__dirname, 'node_modules/strapi-helper-plugin/lib/src'), - ], use: { loader: require.resolve('babel-loader'), options: { diff --git a/packages/strapi-helper-plugin/lib/src/app.js b/packages/strapi-helper-plugin/lib/src/app.js index e3a7d88788..2ed126763d 100644 --- a/packages/strapi-helper-plugin/lib/src/app.js +++ b/packages/strapi-helper-plugin/lib/src/app.js @@ -107,6 +107,7 @@ strapi.registerPlugin({ layout, lifecycles, leftMenuLinks: [], + leftMenuSections: [], mainComponent: Comp, name: pluginPkg.strapi.name, preventComponentRendering: false, diff --git a/packages/strapi-helper-plugin/lib/src/components/ContainerFluid/styles.scss b/packages/strapi-helper-plugin/lib/src/components/ContainerFluid/styles.scss index 7477db4972..1068eae8a9 100644 --- a/packages/strapi-helper-plugin/lib/src/components/ContainerFluid/styles.scss +++ b/packages/strapi-helper-plugin/lib/src/components/ContainerFluid/styles.scss @@ -1,3 +1,3 @@ .helperContainerFluid { - padding: 18px 30px; + padding: 18px 30px !important; } diff --git a/packages/strapi-helper-plugin/lib/src/components/HeaderNav/styles.scss b/packages/strapi-helper-plugin/lib/src/components/HeaderNav/styles.scss index cf9656eaf8..1eafbe3f78 100644 --- a/packages/strapi-helper-plugin/lib/src/components/HeaderNav/styles.scss +++ b/packages/strapi-helper-plugin/lib/src/components/HeaderNav/styles.scss @@ -1,5 +1,5 @@ -.headerNav { /* stylelint-disable */ - +.headerNav { + /* stylelint-disable */ } .headerContainer { @@ -8,10 +8,11 @@ overflow: hidden; margin-top: 4.3rem; border-radius: 2px; - box-shadow: 0 2px 4px #E3E9F3; + box-shadow: 0 2px 4px #e3e9f3; > a { - box-shadow: 1px 0 0px rgba(#DBDBDB, 0.5), inset 0px -1px 0px -2px rgba(#DBDBDB, 0.5); - background-color: #F5F5F5; + box-shadow: 1px 0 0px rgba(#dbdbdb, 0.5), + inset 0px -1px 0px -2px rgba(#dbdbdb, 0.5); + background-color: #f5f5f5; &:first-child { border-radius: 2px 0 0 0; } @@ -28,7 +29,7 @@ // max-width: 33%; height: 3.6rem; border-radius: 2px 0 0 0; - background-color: darken(#F5F5F5, 50%); + background-color: darken(#f5f5f5, 50%); text-decoration: none !important; font-family: Lato; font-size: 1.3rem; @@ -38,30 +39,37 @@ .linkActive { z-index: 10; + &:not(:first-child, :last-child) { + background-color: #ffffff !important; + font-weight: bold; + text-decoration: none !important; + box-shadow: 0 0 2px rgba(#dbdbdb, 0.5); + border-top: 0.2rem solid #1c5de7; + } } .linkActive:first-child { - background-color: #FFFFFF!important; + background-color: #ffffff !important; font-weight: bold; text-decoration: none !important; - box-shadow: 0 0 2px rgba(#DBDBDB, 0.5); - border-top: 0.2rem solid #1C5DE7; + box-shadow: 0 0 2px rgba(#dbdbdb, 0.5); + border-top: 0.2rem solid #1c5de7; } .linkActive:last-child { - background-color: #FFFFFF!important; + background-color: #ffffff !important; font-weight: bold; text-decoration: none !important; - box-shadow: 0 0 2px rgba(#DBDBDB, 0.5); - border-top: 0.2rem solid #1C5DE7; + box-shadow: 0 0 2px rgba(#dbdbdb, 0.5); + border-top: 0.2rem solid #1c5de7; } .linkActive:not(:first-child, :last-child) { - background-color: #FFFFFF!important; + background-color: #ffffff !important; font-weight: bold; text-decoration: none !important; - box-shadow: 0 0 2px rgba(#DBDBDB, 0.5); - border-top: 0.2rem solid #1C5DE7; + box-shadow: 0 0 2px rgba(#dbdbdb, 0.5); + border-top: 0.2rem solid #1c5de7; } .linkText { @@ -71,10 +79,10 @@ } .notifPoint { - height: 0.4rem; + height: 0.4rem; width: 0.4rem; margin: 1px 0 0 0.7rem; align-self: center; border-radius: 0.5rem; - background-color: #27B70F; + background-color: #27b70f; } diff --git a/packages/strapi-helper-plugin/lib/src/components/InputText/styles.scss b/packages/strapi-helper-plugin/lib/src/components/InputText/styles.scss index 4a30c12c8a..ffe46e6c6e 100644 --- a/packages/strapi-helper-plugin/lib/src/components/InputText/styles.scss +++ b/packages/strapi-helper-plugin/lib/src/components/InputText/styles.scss @@ -1,9 +1,9 @@ .textInput { height: 3.4rem; - margin-top: .9rem; + margin-top: 0.9rem; padding-left: 1rem; background-size: 0 !important; - border: 1px solid #E3E9F3; + border: 1px solid #e3e9f3; border-radius: 0.25rem; line-height: 3.4rem; font-size: 1.3rem; diff --git a/packages/strapi-helper-plugin/lib/src/index.js b/packages/strapi-helper-plugin/lib/src/index.js index b83e6a4951..61ea570aa7 100644 --- a/packages/strapi-helper-plugin/lib/src/index.js +++ b/packages/strapi-helper-plugin/lib/src/index.js @@ -12,6 +12,7 @@ export { export { default as ErrorBoundary } from './components/ErrorBoundary'; export { default as ExtendComponent } from './components/ExtendComponent'; export { default as GlobalPagination } from './components/GlobalPagination'; +export { default as HeaderNav } from './components/HeaderNav'; export { default as IcoContainer } from './components/IcoContainer'; export { default as InputAddon } from './components/InputAddon'; @@ -22,10 +23,10 @@ export { default as InputCheckbox } from './components/InputCheckbox'; export { default as InputCheckboxWithErrors, } from './components/InputCheckboxWithErrors'; -// export { default as InputDate } from './components/InputDate'; -// export { -// default as InputDateWithErrors, -// } from './components/InputDateWithErrors'; +export { default as InputDate } from './components/InputDate'; +export { + default as InputDateWithErrors, +} from './components/InputDateWithErrors'; export { default as InputEmail } from './components/InputEmail'; export { default as InputEmailWithErrors, diff --git a/packages/strapi-helper-plugin/package.json b/packages/strapi-helper-plugin/package.json index 5d152eb75a..6079326630 100644 --- a/packages/strapi-helper-plugin/package.json +++ b/packages/strapi-helper-plugin/package.json @@ -67,6 +67,7 @@ "rollup-plugin-postcss": "^2.0.3", "rollup-plugin-sass": "^1.2.2", "rollup-plugin-scss": "^1.0.1", + "rollup-plugin-sizes": "^0.5.1", "rollup-plugin-svg": "^1.0.1", "shelljs": "^0.7.8" }, @@ -90,4 +91,4 @@ "styled-components": "^3.2.6", "whatwg-fetch": "^2.0.3" } -} \ No newline at end of file +} diff --git a/packages/strapi-helper-plugin/rollup.config.js b/packages/strapi-helper-plugin/rollup.config.js index cc7aa3562f..15c0c209d7 100644 --- a/packages/strapi-helper-plugin/rollup.config.js +++ b/packages/strapi-helper-plugin/rollup.config.js @@ -14,6 +14,7 @@ export default { format: 'cjs', sourceMap: true, name: 'strapi-helper-plugin', + compact: true, }, { exports: 'named', @@ -21,6 +22,7 @@ export default { file: pkg.module, format: 'es', name: 'strapi-helper-plugin', + compact: true, }, ], @@ -34,6 +36,7 @@ export default { resolve(), commonjs(), svg(), + require('rollup-plugin-sizes')(), ], external: [ diff --git a/packages/strapi-plugin-email/admin/src/components/EditForm/index.js b/packages/strapi-plugin-email/admin/src/components/EditForm/index.js index 0b6b8520c0..146a2ecb47 100644 --- a/packages/strapi-plugin-email/admin/src/components/EditForm/index.js +++ b/packages/strapi-plugin-email/admin/src/components/EditForm/index.js @@ -7,26 +7,30 @@ import React from 'react'; import { findIndex, get, isEmpty, map } from 'lodash'; import PropTypes from 'prop-types'; -// You can find these components in either -// ./node_modules/strapi-helper-plugin/lib/src -// or strapi/packages/strapi-helper-plugin/lib/src -import Input from 'components/InputsIndex'; +import { InputsIndex as Input } from 'strapi-helper-plugin'; import styles from './styles.scss'; -class EditForm extends React.Component { - getProviderForm = () => get(this.props.settings, ['providers', this.props.selectedProviderIndex, 'auth'], {}); +class EditForm extends React.Component { + getProviderForm = () => + get( + this.props.settings, + ['providers', this.props.selectedProviderIndex, 'auth'], + {}, + ); - generateSelectOptions = () => ( - Object.keys(get(this.props.settings, 'providers', {})).reduce((acc, current) => { - const option = { - id: get(this.props.settings, ['providers', current, 'name']), - value: get(this.props.settings, ['providers', current, 'provider']), - }; - acc.push(option); - return acc; - }, []) - ) + generateSelectOptions = () => + Object.keys(get(this.props.settings, 'providers', {})).reduce( + (acc, current) => { + const option = { + id: get(this.props.settings, ['providers', current, 'name']), + value: get(this.props.settings, ['providers', current, 'provider']), + }; + acc.push(option); + return acc; + }, + [], + ); render() { return ( @@ -34,7 +38,9 @@ class EditForm extends React.Component {
( findIndex(this.props.settings.providers, ['provider', get(this.props.modifiedData, 'provider')]); + getSelectedProviderIndex = () => + findIndex(this.props.settings.providers, [ + 'provider', + get(this.props.modifiedData, 'provider'), + ]); /** * Get Settings depending on the props * @param {Object} props * @return {Func} calls the saga that gets the current settings */ - getSettings = (props) => { - const { match: { params: { env} } } = props; + getSettings = props => { + const { + match: { + params: { env }, + }, + } = props; this.props.getSettings(env); - } + }; generateLinks = () => { - const headerNavLinks = this.props.appEnvironments.reduce((acc, current) => { - const link = Object.assign(current, { to: `/plugins/email/configurations/${current.name}` }); - acc.push(link); - return acc; - }, []).sort(link => link.name === 'production'); + const headerNavLinks = this.props.appEnvironments + .reduce((acc, current) => { + const link = Object.assign(current, { + to: `/plugins/email/configurations/${current.name}`, + }); + acc.push(link); + return acc; + }, []) + .sort(link => link.name === 'production'); return headerNavLinks; - } + }; - handleSubmit = (e) => { + handleSubmit = e => { e.preventDefault(); - const formErrors = Object.keys(get(this.props.settings, ['providers', this.getSelectedProviderIndex(), 'auth'], {})).reduce((acc, current) => { + const formErrors = Object.keys( + get( + this.props.settings, + ['providers', this.getSelectedProviderIndex(), 'auth'], + {}, + ), + ).reduce((acc, current) => { if (isEmpty(get(this.props.modifiedData, current, ''))) { acc.push({ name: current, @@ -90,7 +102,7 @@ class ConfigPage extends React.Component { } return this.props.submit(); - } + }; pluginHeaderActions = [ { @@ -115,7 +127,7 @@ class ConfigPage extends React.Component { ; - } -} diff --git a/packages/strapi-plugin-email/admin/src/index.js b/packages/strapi-plugin-email/admin/src/index.js new file mode 100644 index 0000000000..973717dc93 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/index.js @@ -0,0 +1,93 @@ +import React from 'react'; +import { reduce } from 'lodash'; +import pluginPkg from '../../package.json'; +import pluginId from './pluginId'; + +import App from './containers/App'; + +const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; + +const formatMessages = messages => + reduce( + messages, + (result, value, key) => { + result[`${pluginId}.${key}`] = value; + + return result; + }, + {}, + ); +const requireTranslations = language => { + try { + return require(`./translations/${language}.json`); // eslint-disable-line global-require + } catch (error) { + console.error( + `Unable to load "${language}" translation for the plugin ${pluginId}. Please make sure "${language}.json" file exists in "pluginPath/admin/src/translations" folder.`, + ); + return; + } +}; + +const translationMessages = reduce( + strapi.languages, + (result, language) => { + result[language] = formatMessages(requireTranslations(language)); + return result; + }, + {}, +); +const layout = (() => { + try { + return require('../../config/layout.js'); // eslint-disable-line import/no-unresolved + } catch (err) { + return null; + } +})(); + +const injectedComponents = (() => { + try { + return require('./injectedComponents').default; // eslint-disable-line import/no-unresolved + } catch (err) { + return []; + } +})(); + +const initializer = (() => { + try { + return require('./initializer'); + } catch (err) { + return null; + } +})(); + +const lifecycles = (() => { + try { + return require('./lifecycles'); + } catch (err) { + return null; + } +})(); + +function Comp(props) { + return ; +} + +const plugin = { + blockerComponent: null, + blockerComponentProps: {}, + description: pluginDescription, + icon: pluginPkg.strapi.icon, + id: pluginId, + initializer, + injectedComponents, + layout, + lifecycles, + leftMenuLinks: [], + leftMenuSections: [], + mainComponent: Comp, + name: pluginPkg.strapi.name, + preventComponentRendering: false, + translationMessages, +}; + +export default plugin; diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/EditForm/index.js b/packages/strapi-plugin-users-permissions/admin/src/components/EditForm/index.js index 6553f5fa0c..334cbd3748 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/components/EditForm/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/components/EditForm/index.js @@ -1,21 +1,21 @@ /** -* -* EditForm -* -*/ + * + * EditForm + * + */ import React from 'react'; import PropTypes from 'prop-types'; import { get } from 'lodash'; import cn from 'classnames'; -import LoadingIndicator from 'components/LoadingIndicator'; -import Input from 'components/InputsIndex'; +import { InputsIndex as Input, LoadingIndicator } from 'strapi-helper-plugin'; import styles from './styles.scss'; -class EditForm extends React.Component { // eslint-disable-line react/prefer-stateless-function - generateSelectOptions = () => ( +class EditForm extends React.Component { + // eslint-disable-line react/prefer-stateless-function + generateSelectOptions = () => Object.keys(get(this.props.values, 'roles', [])).reduce((acc, current) => { const option = { id: get(this.props.values.roles, [current, 'name']), @@ -23,13 +23,17 @@ class EditForm extends React.Component { // eslint-disable-line react/prefer-sta }; acc.push(option); return acc; - }, []) - ) + }, []); render() { if (this.props.showLoaders) { return ( -
+
); @@ -39,7 +43,9 @@ class EditForm extends React.Component { // eslint-disable-line react/prefer-sta
diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js b/packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js index 147e01f76f..8d32f80ab3 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js @@ -1,8 +1,8 @@ /** -* -* InputSearchContainer -* -*/ + * + * InputSearchContainer + * + */ import React from 'react'; import { FormattedMessage } from 'react-intl'; @@ -10,12 +10,13 @@ import { findIndex, has, includes, isEmpty, map, toLower } from 'lodash'; import cn from 'classnames'; import PropTypes from 'prop-types'; -import Label from 'components/Label'; +import { Label } from 'strapi-helper-plugin'; import InputSearchLi from '../InputSearchLi'; import styles from './styles.scss'; -class InputSearchContainer extends React.Component { // eslint-disable-line react/prefer-stateless-function +class InputSearchContainer extends React.Component { + // eslint-disable-line react/prefer-stateless-function state = { errors: [], filteredUsers: this.props.values, @@ -27,11 +28,17 @@ class InputSearchContainer extends React.Component { // eslint-disable-line reac componentWillReceiveProps(nextProps) { if (nextProps.didDeleteUser !== this.props.didDeleteUser) { - this.setState({ users: nextProps.values, filteredUsers: nextProps.values }); + this.setState({ + users: nextProps.values, + filteredUsers: nextProps.values, + }); } if (nextProps.didGetUsers !== this.props.didGetUsers) { - this.setState({ users: nextProps.values, filteredUsers: nextProps.values }); + this.setState({ + users: nextProps.values, + filteredUsers: nextProps.values, + }); } if (nextProps.didFetchUsers !== this.props.didFetchUsers) { @@ -42,24 +49,31 @@ class InputSearchContainer extends React.Component { // eslint-disable-line reac handleBlur = () => this.setState({ isFocused: !this.state.isFocused }); handleChange = ({ target }) => { - const filteredUsers = isEmpty(target.value) ? - this.state.users - : this.state.users.filter((user) => includes(toLower(user.name), toLower(target.value))); + const filteredUsers = isEmpty(target.value) + ? this.state.users + : this.state.users.filter(user => + includes(toLower(user.name), toLower(target.value)), + ); if (isEmpty(filteredUsers) && !isEmpty(target.value)) { this.props.getUser(target.value); } if (isEmpty(target.value)) { - return this.setState({ value: target.value, isAdding: false, users: this.props.values, filteredUsers: this.props.values }); + return this.setState({ + value: target.value, + isAdding: false, + users: this.props.values, + filteredUsers: this.props.values, + }); } this.setState({ value: target.value, filteredUsers }); - } + }; handleFocus = () => this.setState({ isFocused: !this.state.isFocused }); - handleClick = (item) => { + handleClick = item => { if (this.state.isAdding) { const id = has(item, '_id') ? '_id' : 'id'; const users = this.props.values; @@ -72,22 +86,36 @@ class InputSearchContainer extends React.Component { // eslint-disable-line reac // Reset the input focus this.searchInput.focus(); // Empty the input and display users - this.setState({ value: '', isAdding: false, users, filteredUsers: users }); + this.setState({ + value: '', + isAdding: false, + users, + filteredUsers: users, + }); } else { this.props.onClickDelete(item); } - } + }; render() { return (