Update reducer injector in all plugins

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-04-20 10:47:56 +02:00
parent 76e63b8dd1
commit 13d4c58bbe
11 changed files with 59 additions and 117 deletions

View File

@ -104,7 +104,7 @@
"app.components.listPlugins.title.singular": "{number} Plugin ist installiert", "app.components.listPlugins.title.singular": "{number} Plugin ist installiert",
"app.components.listPluginsPage.deletePlugin.error": "Bei der Entfernung des Plugins ist ein Fehler aufgetreten", "app.components.listPluginsPage.deletePlugin.error": "Bei der Entfernung des Plugins ist ein Fehler aufgetreten",
"app.utils.SelectOption.defaultMessage": " ", "app.utils.SelectOption.defaultMessage": " ",
"app.utils.defaultMessage": "", "app.utils.defaultMessage": " ",
"app.utils.placeholder.defaultMessage": " ", "app.utils.placeholder.defaultMessage": " ",
"components.AutoReloadBlocker.description": "Führen Sie Strapi mit einem der folgenden Befehle aus:", "components.AutoReloadBlocker.description": "Führen Sie Strapi mit einem der folgenden Befehle aus:",
"components.AutoReloadBlocker.header": "Dieses Plugin benötigt das Neuladen-Feature.", "components.AutoReloadBlocker.header": "Dieses Plugin benötigt das Neuladen-Feature.",

View File

@ -7,7 +7,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';
import { CopyToClipboard } from 'react-copy-to-clipboard'; import { CopyToClipboard } from 'react-copy-to-clipboard';
import { bindActionCreators, compose } from 'redux'; import { bindActionCreators, compose } from 'redux';
import { get, isEmpty } from 'lodash'; import { get, isEmpty } from 'lodash';
@ -39,7 +38,6 @@ import {
} from './actions'; } from './actions';
// Selectors // Selectors
import selectHomePage from './selectors'; import selectHomePage from './selectors';
import reducer from './reducer';
import saga from './saga'; import saga from './saga';
export class HomePage extends React.Component { export class HomePage extends React.Component {
@ -188,9 +186,7 @@ export class HomePage extends React.Component {
onChange={() => {}} onChange={() => {}}
label={{ id: getTrad('containers.HomePage.form.jwtToken') }} label={{ id: getTrad('containers.HomePage.form.jwtToken') }}
inputDescription={{ inputDescription={{
id: getTrad( id: getTrad('containers.HomePage.form.jwtToken.description'),
'containers.HomePage.form.jwtToken.description'
),
}} }}
/> />
</div> </div>
@ -257,19 +253,7 @@ function mapDispatchToProps(dispatch) {
const mapStateToProps = selectHomePage(); const mapStateToProps = selectHomePage();
const withConnect = connect( const withConnect = connect(mapStateToProps, mapDispatchToProps);
mapStateToProps,
mapDispatchToProps
);
const withReducer = strapi.injectReducer({
key: 'homePage',
reducer,
pluginId,
});
const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId }); const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId });
export default compose( export default compose(withSaga, withConnect)(HomePage);
withReducer,
withSaga,
withConnect
)(injectIntl(HomePage));

View File

@ -11,6 +11,7 @@ import pluginLogo from './assets/images/logo.svg';
import App from './containers/App'; import App from './containers/App';
import Initializer from './containers/Initializer'; import Initializer from './containers/Initializer';
import lifecycles from './lifecycles'; import lifecycles from './lifecycles';
import reducers from './reducers';
import trads from './translations'; import trads from './translations';
export default strapi => { export default strapi => {
@ -33,6 +34,7 @@ export default strapi => {
name: pluginPkg.strapi.name, name: pluginPkg.strapi.name,
pluginLogo, pluginLogo,
preventComponentRendering: false, preventComponentRendering: false,
reducers,
trads, trads,
}; };

View File

@ -0,0 +1,8 @@
import homePageReducer from './containers/HomePage/reducer';
import pluginId from './pluginId';
const reducers = {
[`${pluginId}_homePage`]: homePageReducer,
};
export default reducers;

View File

@ -10,20 +10,14 @@ import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux'; import { bindActionCreators, compose } from 'redux';
import { findIndex, get, isEmpty } from 'lodash'; import { findIndex, get, isEmpty } from 'lodash';
import { Header } from '@buffetjs/custom'; import { Header } from '@buffetjs/custom';
// You can find these components in either // You can find these components in either
// ./node_modules/strapi-helper-plugin/lib/src // ./node_modules/strapi-helper-plugin/lib/src
// or strapi/packages/strapi-helper-plugin/lib/src // or strapi/packages/strapi-helper-plugin/lib/src
import { ContainerFluid, HeaderNav, GlobalContext } from 'strapi-helper-plugin'; import { ContainerFluid, HeaderNav, GlobalContext } from 'strapi-helper-plugin';
import pluginId from '../../pluginId'; import pluginId from '../../pluginId';
// Plugin's components // Plugin's components
import EditForm from '../../components/EditForm'; import EditForm from '../../components/EditForm';
import { getSettings, onCancel, onChange, setErrors, submit } from './actions'; import { getSettings, onCancel, onChange, setErrors, submit } from './actions';
import reducer from './reducer';
import saga from './saga'; import saga from './saga';
import selectConfigPage from './selectors'; import selectConfigPage from './selectors';
@ -57,9 +51,7 @@ class ConfigPage extends React.Component {
// Redirect the user to the email list after modifying is provider // Redirect the user to the email list after modifying is provider
if (prevProps.submitSuccess !== this.props.submitSuccess) { if (prevProps.submitSuccess !== this.props.submitSuccess) {
this.props.history.push( this.props.history.push(`/plugins/email/configurations/${this.props.match.params.env}`);
`/plugins/email/configurations/${this.props.match.params.env}`
);
} }
} }
@ -101,11 +93,7 @@ class ConfigPage extends React.Component {
handleSubmit = e => { handleSubmit = e => {
e.preventDefault(); e.preventDefault();
const formErrors = Object.keys( const formErrors = Object.keys(
get( get(this.props.settings, ['providers', this.getSelectedProviderIndex(), 'auth'], {})
this.props.settings,
['providers', this.getSelectedProviderIndex(), 'auth'],
{}
)
).reduce((acc, current) => { ).reduce((acc, current) => {
if (isEmpty(get(this.props.modifiedData, current, ''))) { if (isEmpty(get(this.props.modifiedData, current, ''))) {
acc.push({ acc.push({
@ -140,10 +128,7 @@ class ConfigPage extends React.Component {
})} })}
title={{ label: formatMessage({ id: 'email.ConfigPage.title' }) }} title={{ label: formatMessage({ id: 'email.ConfigPage.title' }) }}
/> />
<HeaderNav <HeaderNav links={this.generateLinks()} style={{ marginTop: '4.6rem' }} />
links={this.generateLinks()}
style={{ marginTop: '4.6rem' }}
/>
<EditForm <EditForm
didCheckErrors={this.props.didCheckErrors} didCheckErrors={this.props.didCheckErrors}
formErrors={this.props.formErrors} formErrors={this.props.formErrors}
@ -198,20 +183,8 @@ function mapDispatchToProps(dispatch) {
const mapStateToProps = selectConfigPage(); const mapStateToProps = selectConfigPage();
const withConnect = connect( const withConnect = connect(mapStateToProps, mapDispatchToProps);
mapStateToProps,
mapDispatchToProps
);
const withReducer = strapi.injectReducer({
key: 'configPage',
reducer,
pluginId,
});
const withSaga = strapi.injectSaga({ key: 'configPage', saga, pluginId }); const withSaga = strapi.injectSaga({ key: 'configPage', saga, pluginId });
export default compose( export default compose(withSaga, withConnect)(ConfigPage);
withReducer,
withSaga,
withConnect
)(ConfigPage);

View File

@ -11,6 +11,7 @@ import pluginLogo from './assets/images/logo.svg';
import App from './containers/App'; import App from './containers/App';
import Initializer from './containers/Initializer'; import Initializer from './containers/Initializer';
import lifecycles from './lifecycles'; import lifecycles from './lifecycles';
import reducers from './reducers';
import trads from './translations'; import trads from './translations';
export default strapi => { export default strapi => {
@ -33,6 +34,7 @@ export default strapi => {
name: pluginPkg.strapi.name, name: pluginPkg.strapi.name,
pluginLogo, pluginLogo,
preventComponentRendering: false, preventComponentRendering: false,
reducers,
trads, trads,
}; };

View File

@ -0,0 +1,8 @@
import configPageReducer from './containers/ConfigPage/reducer';
import pluginId from './pluginId';
const reducers = {
[`${pluginId}_configPage`]: configPageReducer,
};
export default reducers;

View File

@ -51,8 +51,6 @@ import {
// Selectors // Selectors
import makeSelectEditPage from './selectors'; import makeSelectEditPage from './selectors';
import reducer from './reducer';
import saga from './saga'; import saga from './saga';
import { Loader, Title, Separator, Wrapper } from './Components'; import { Loader, Title, Separator, Wrapper } from './Components';
@ -221,10 +219,7 @@ export class EditPage extends React.Component {
label: formatMessage({ id: getTrad('EditPage.submit') }), label: formatMessage({ id: getTrad('EditPage.submit') }),
onClick: this.handleSubmit, onClick: this.handleSubmit,
type: 'submit', type: 'submit',
disabled: isEqual( disabled: isEqual(this.props.editPage.modifiedData, this.props.editPage.initialData),
this.props.editPage.modifiedData,
this.props.editPage.initialData
),
key: 'button-submit', key: 'button-submit',
}, },
]; ];
@ -240,9 +235,7 @@ export class EditPage extends React.Component {
selectAllActions={this.props.selectAllActions} selectAllActions={this.props.selectAllActions}
setInputPoliciesPath={this.props.setInputPoliciesPath} setInputPoliciesPath={this.props.setInputPoliciesPath}
setShouldDisplayPolicieshint={this.props.setShouldDisplayPolicieshint} setShouldDisplayPolicieshint={this.props.setShouldDisplayPolicieshint}
resetShouldDisplayPoliciesHint={ resetShouldDisplayPoliciesHint={this.props.resetShouldDisplayPoliciesHint}
this.props.resetShouldDisplayPoliciesHint
}
> >
<Wrapper> <Wrapper>
<BackHeader onClick={() => this.props.history.goBack()} /> <BackHeader onClick={() => this.props.history.goBack()} />
@ -256,11 +249,7 @@ export class EditPage extends React.Component {
<FormattedMessage <FormattedMessage
id={pluginHeaderDescription} id={pluginHeaderDescription}
values={{ values={{
description: get( description: get(this.props.editPage.initialData, 'description', ''),
this.props.editPage.initialData,
'description',
''
),
}} }}
> >
{description => { {description => {
@ -302,16 +291,11 @@ export class EditPage extends React.Component {
)} )}
{!this.showLoaderPermissions() && ( {!this.showLoaderPermissions() && (
<Plugins <Plugins
plugins={get(this.props.editPage, [ plugins={get(this.props.editPage, ['modifiedData', 'permissions'])}
'modifiedData',
'permissions',
])}
/> />
)} )}
<Policies <Policies
shouldDisplayPoliciesHint={ shouldDisplayPoliciesHint={this.props.editPage.shouldDisplayPoliciesHint}
this.props.editPage.shouldDisplayPoliciesHint
}
inputSelectName={this.props.editPage.inputPoliciesPath} inputSelectName={this.props.editPage.inputPoliciesPath}
routes={this.props.editPage.routes} routes={this.props.editPage.routes}
selectOptions={this.props.editPage.policies} selectOptions={this.props.editPage.policies}
@ -394,11 +378,7 @@ function mapDispatchToProps(dispatch) {
} }
const withConnect = connect(mapStateToProps, mapDispatchToProps); const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = strapi.injectReducer({
key: 'editPage',
reducer,
pluginId,
});
const withSaga = strapi.injectSaga({ key: 'editPage', saga, pluginId }); const withSaga = strapi.injectSaga({ key: 'editPage', saga, pluginId });
export default compose(withReducer, withSaga, withConnect)(EditPage); export default compose(withSaga, withConnect)(EditPage);

View File

@ -31,7 +31,6 @@ import {
submit, submit,
unsetDataToEdit, unsetDataToEdit,
} from './actions'; } from './actions';
import reducer from './reducer';
import saga from './saga'; import saga from './saga';
import checkFormValidity from './checkFormValidity'; import checkFormValidity from './checkFormValidity';
@ -99,8 +98,7 @@ export class HomePage extends React.Component {
UNSAFE_componentWillUpdate(nextProps) { UNSAFE_componentWillUpdate(nextProps) {
const allowedPaths = ['roles', 'providers', 'email-templates', 'advanced']; const allowedPaths = ['roles', 'providers', 'email-templates', 'advanced'];
const shouldRedirect = const shouldRedirect =
allowedPaths.filter(el => el === nextProps.match.params.settingType) allowedPaths.filter(el => el === nextProps.match.params.settingType).length === 0;
.length === 0;
if (shouldRedirect) { if (shouldRedirect) {
this.props.history.push('/404'); this.props.history.push('/404');
@ -112,9 +110,7 @@ export class HomePage extends React.Component {
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if ( if (prevProps.match.params.settingType !== this.props.match.params.settingType) {
prevProps.match.params.settingType !== this.props.match.params.settingType
) {
this.props.fetchData(this.props.match.params.settingType); this.props.fetchData(this.props.match.params.settingType);
} }
} }
@ -159,10 +155,7 @@ export class HomePage extends React.Component {
this.getEndPoint(), this.getEndPoint(),
this.props.dataToEdit, this.props.dataToEdit,
]); ]);
const initObject = get(this.props.initialData, [ const initObject = get(this.props.initialData, [this.getEndPoint(), this.props.dataToEdit]);
this.getEndPoint(),
this.props.dataToEdit,
]);
const formErrors = checkFormValidity( const formErrors = checkFormValidity(
this.props.match.params.settingType, this.props.match.params.settingType,
modifiedObject, modifiedObject,
@ -189,12 +182,8 @@ export class HomePage extends React.Component {
const { data, isLoading, modifiedData } = this.props; const { data, isLoading, modifiedData } = this.props;
return ( return (
(isLoading && (isLoading && get(data, this.getEndPoint()) === undefined && !this.isAdvanded()) ||
get(data, this.getEndPoint()) === undefined && (isLoading && this.isAdvanded() && get(modifiedData, this.getEndPoint()) === undefined)
!this.isAdvanded()) ||
(isLoading &&
this.isAdvanded() &&
get(modifiedData, this.getEndPoint()) === undefined)
); );
}; };
@ -212,13 +201,11 @@ export class HomePage extends React.Component {
} = this.props; } = this.props;
const { formatMessage } = this.context; const { formatMessage } = this.context;
const headerActions = const headerActions =
match.params.settingType === 'advanced' && match.params.settingType === 'advanced' && !isEqual(modifiedData, initialData)
!isEqual(modifiedData, initialData)
? this.pluginHeaderActions ? this.pluginHeaderActions
: []; : [];
const noButtonList = const noButtonList =
match.params.settingType === 'email-templates' || match.params.settingType === 'email-templates' || match.params.settingType === 'providers';
match.params.settingType === 'providers';
const values = get(modifiedData, this.getEndPoint(), {}); const values = get(modifiedData, this.getEndPoint(), {});
return ( return (
@ -242,10 +229,7 @@ export class HomePage extends React.Component {
})} })}
actions={headerActions} actions={headerActions}
/> />
<HeaderNav <HeaderNav links={this.headerNavLinks} style={{ marginTop: '4.6rem' }} />
links={this.headerNavLinks}
style={{ marginTop: '4.6rem' }}
/>
{!this.isAdvanded() ? ( {!this.isAdvanded() ? (
<List <List
data={get(data, this.getEndPoint(), [])} data={get(data, this.getEndPoint(), [])}
@ -324,19 +308,8 @@ function mapDispatchToProps(dispatch) {
const mapStateToProps = selectHomePage(); const mapStateToProps = selectHomePage();
const withConnect = connect( const withConnect = connect(mapStateToProps, mapDispatchToProps);
mapStateToProps,
mapDispatchToProps
);
const withReducer = strapi.injectReducer({
key: 'homePage',
reducer,
pluginId,
});
const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId }); const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId });
export default compose( export default compose(withSaga, withConnect)(injectIntl(HomePage));
withReducer,
withSaga,
withConnect
)(injectIntl(HomePage));

View File

@ -12,6 +12,7 @@ import pluginId from './pluginId';
import App from './containers/App'; import App from './containers/App';
import Initializer from './containers/Initializer'; import Initializer from './containers/Initializer';
import lifecycles from './lifecycles'; import lifecycles from './lifecycles';
import reducers from './reducers';
import trads from './translations'; import trads from './translations';
export default strapi => { export default strapi => {
@ -34,6 +35,7 @@ export default strapi => {
name: pluginPkg.strapi.name, name: pluginPkg.strapi.name,
pluginLogo, pluginLogo,
preventComponentRendering: false, preventComponentRendering: false,
reducers,
settings: {}, settings: {},
suffixUrl: () => '/roles', suffixUrl: () => '/roles',
suffixUrlToReplaceForLeftMenuHighlight: '/roles', suffixUrlToReplaceForLeftMenuHighlight: '/roles',

View File

@ -0,0 +1,10 @@
import editPageReducer from './containers/EditPage/reducer';
import homePageReducer from './containers/HomePage/reducer';
import pluginId from './pluginId';
const reducers = {
[`${pluginId}_editPage`]: editPageReducer,
[`${pluginId}_homePage`]: homePageReducer,
};
export default reducers;