mirror of
https://github.com/strapi/strapi.git
synced 2025-09-05 14:53:01 +00:00
Remove separate store for users-permissions
This commit is contained in:
parent
ba471149ea
commit
72cc7d0837
@ -10,6 +10,8 @@ import {
|
|||||||
updatePlugin,
|
updatePlugin,
|
||||||
} from 'containers/App/actions';
|
} from 'containers/App/actions';
|
||||||
import { showNotification } from 'containers/NotificationProvider/actions';
|
import { showNotification } from 'containers/NotificationProvider/actions';
|
||||||
|
import injectReducer from './utils/injectReducer';
|
||||||
|
import injectSaga from './utils/injectSaga';
|
||||||
import { history, store } from './createStore';
|
import { history, store } from './createStore';
|
||||||
import { translationMessages, languages } from './i18n';
|
import { translationMessages, languages } from './i18n';
|
||||||
import './public-path';
|
import './public-path';
|
||||||
@ -94,4 +96,7 @@ window.strapi = Object.assign(window.strapi || {}, {
|
|||||||
currentLanguage: window.localStorage.getItem('strapi-admin-language') || window.navigator.language || window.navigator.userLanguage || 'en',
|
currentLanguage: window.localStorage.getItem('strapi-admin-language') || window.navigator.language || window.navigator.userLanguage || 'en',
|
||||||
lockApp,
|
lockApp,
|
||||||
unlockApp,
|
unlockApp,
|
||||||
|
injectReducer,
|
||||||
|
injectSaga,
|
||||||
|
store,
|
||||||
});
|
});
|
@ -11,7 +11,7 @@ import getInjectors from './reducerInjectors';
|
|||||||
* @param {function} reducer A reducer that will be injected
|
* @param {function} reducer A reducer that will be injected
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export default ({ key, reducer }) => (WrappedComponent) => {
|
export default ({ key, reducer, pluginId }) => (WrappedComponent) => {
|
||||||
class ReducerInjector extends React.Component {
|
class ReducerInjector extends React.Component {
|
||||||
static WrappedComponent = WrappedComponent;
|
static WrappedComponent = WrappedComponent;
|
||||||
static displayName = `withReducer(${(WrappedComponent.displayName || WrappedComponent.name || 'Component')})`;
|
static displayName = `withReducer(${(WrappedComponent.displayName || WrappedComponent.name || 'Component')})`;
|
||||||
@ -21,8 +21,13 @@ export default ({ key, reducer }) => (WrappedComponent) => {
|
|||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const { injectReducer } = this.injectors;
|
const { injectReducer } = this.injectors;
|
||||||
|
let reducerName = key;
|
||||||
|
|
||||||
injectReducer(key, reducer);
|
if (pluginId) {
|
||||||
|
reducerName = `${pluginId}-${key}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
injectReducer(reducerName, reducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
injectors = getInjectors(this.context.store);
|
injectors = getInjectors(this.context.store);
|
||||||
|
@ -15,7 +15,7 @@ import getInjectors from './sagaInjectors';
|
|||||||
* - constants.ONCE_TILL_UNMOUNT—behaves like 'RESTART_ON_REMOUNT' but never runs it again.
|
* - constants.ONCE_TILL_UNMOUNT—behaves like 'RESTART_ON_REMOUNT' but never runs it again.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export default ({ key, saga, mode }) => (WrappedComponent) => {
|
export default ({ key, saga, mode, pluginId }) => (WrappedComponent) => {
|
||||||
class InjectSaga extends React.Component {
|
class InjectSaga extends React.Component {
|
||||||
static WrappedComponent = WrappedComponent;
|
static WrappedComponent = WrappedComponent;
|
||||||
static displayName = `withSaga(${(WrappedComponent.displayName || WrappedComponent.name || 'Component')})`;
|
static displayName = `withSaga(${(WrappedComponent.displayName || WrappedComponent.name || 'Component')})`;
|
||||||
@ -25,8 +25,13 @@ export default ({ key, saga, mode }) => (WrappedComponent) => {
|
|||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const { injectSaga } = this.injectors;
|
const { injectSaga } = this.injectors;
|
||||||
|
let sagaName = key;
|
||||||
|
|
||||||
injectSaga(key, { saga, mode }, this.props);
|
if (pluginId) {
|
||||||
|
sagaName = `${pluginId}-${key}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
injectSaga(sagaName, { saga, mode }, this.props);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -11,9 +11,9 @@ import './public-path.js'; // eslint-disable-line import/extensions
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Loadable from 'react-loadable';
|
import Loadable from 'react-loadable';
|
||||||
import { Provider } from 'react-redux';
|
// import { Provider } from 'react-redux';
|
||||||
import LoadingIndicatorPage from 'components/LoadingIndicatorPage';
|
import LoadingIndicatorPage from 'components/LoadingIndicatorPage';
|
||||||
import configureStore from './store';
|
// import configureStore from './store';
|
||||||
import { translationMessages } from './i18n';
|
import { translationMessages } from './i18n';
|
||||||
|
|
||||||
|
|
||||||
@ -61,22 +61,23 @@ const apiUrl = `${strapi.backendURL}/${pluginId}`;
|
|||||||
const router = strapi.router;
|
const router = strapi.router;
|
||||||
|
|
||||||
// Create redux store with Strapi admin history
|
// Create redux store with Strapi admin history
|
||||||
const store = configureStore({}, strapi.router, pluginName);
|
// const store = configureStore({}, strapi.router, pluginName);
|
||||||
|
const store = strapi.store;
|
||||||
|
|
||||||
// Define the plugin root component
|
// Define the plugin root component
|
||||||
function Comp(props) {
|
function Comp(props) {
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
// <Provider store={store}>
|
||||||
<LoadableApp {...props} />
|
<LoadableApp {...props} />
|
||||||
</Provider>
|
// </Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.Cypress) {
|
// if (window.Cypress) {
|
||||||
window.__store__ = Object.assign(window.__store__ || {}, {
|
// window.__store__ = Object.assign(window.__store__ || {}, {
|
||||||
[pluginId]: store,
|
// [pluginId]: store,
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Hot reloadable translation json files
|
// Hot reloadable translation json files
|
||||||
if (module.hot) {
|
if (module.hot) {
|
||||||
|
@ -8,7 +8,6 @@ import { fromJS } from 'immutable';
|
|||||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||||
|
|
||||||
import globalReducer from 'containers/App/reducer'; // eslint-disable-line
|
import globalReducer from 'containers/App/reducer'; // eslint-disable-line
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* routeReducer
|
* routeReducer
|
||||||
*
|
*
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* App actions
|
|
||||||
*
|
|
||||||
*/
|
|
@ -1,5 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* App constants
|
|
||||||
*
|
|
||||||
*/
|
|
@ -7,10 +7,9 @@
|
|||||||
|
|
||||||
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 { createStructuredSelector } from 'reselect';
|
|
||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
import { bindActionCreators, compose } from 'redux';
|
// import { bindActionCreators, compose } from 'redux';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { pluginId } from 'app';
|
import { pluginId } from 'app';
|
||||||
@ -59,18 +58,17 @@ App.propTypes = {
|
|||||||
location: PropTypes.object.isRequired,
|
location: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function mapDispatchToProps(dispatch) {
|
// export function mapDispatchToProps(dispatch) {
|
||||||
return bindActionCreators(
|
// return bindActionCreators(
|
||||||
{},
|
// {},
|
||||||
dispatch,
|
// dispatch,
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({});
|
|
||||||
|
|
||||||
// Wrap the component to inject dispatch and state into it
|
// Wrap the component to inject dispatch and state into it
|
||||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
// const withConnect = connect(null, mapDispatchToProps);
|
||||||
|
export default App;
|
||||||
|
|
||||||
export default compose(
|
// export default compose(
|
||||||
withConnect,
|
// withConnect,
|
||||||
)(App);
|
// )(App);
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* App reducer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { fromJS } from 'immutable';
|
|
||||||
|
|
||||||
const initialState = fromJS({});
|
|
||||||
|
|
||||||
function appReducer(state = initialState, action) {
|
|
||||||
switch (action.type) {
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default appReducer;
|
|
@ -1,7 +0,0 @@
|
|||||||
// import { createSelector } from 'reselect';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Direct selector to the list state domain
|
|
||||||
*/
|
|
||||||
|
|
||||||
// const selectGlobalDomain = () => state => state.get('global');
|
|
@ -22,8 +22,6 @@ import Input from 'components/InputsIndex';
|
|||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import auth from 'utils/auth';
|
import auth from 'utils/auth';
|
||||||
import injectSaga from 'utils/injectSaga';
|
|
||||||
import injectReducer from 'utils/injectReducer';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
hideLoginErrorsInput,
|
hideLoginErrorsInput,
|
||||||
@ -328,16 +326,8 @@ function mapDispatchToProps(dispatch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
||||||
|
const withReducer = strapi.injectReducer({ key: 'authPage', reducer, pluginId: 'users-permissions' });
|
||||||
/* Remove this line if the container doesn't have a route and
|
const withSaga = strapi.injectSaga({ key: 'authPage', saga, pluginId: 'users-permissions' });
|
||||||
* check the documentation to see how to create the container's store
|
|
||||||
*/
|
|
||||||
const withReducer = injectReducer({ key: 'authPage', reducer });
|
|
||||||
|
|
||||||
/* Remove the line below the container doesn't have a route and
|
|
||||||
* check the documentation to see how to create the container's store
|
|
||||||
*/
|
|
||||||
const withSaga = injectSaga({ key: 'authPage', saga });
|
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withReducer,
|
withReducer,
|
||||||
|
@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
|
|||||||
/**
|
/**
|
||||||
* Direct selector to the authPage state domain
|
* Direct selector to the authPage state domain
|
||||||
*/
|
*/
|
||||||
const selectAuthPageDomain = () => (state) => state.get('authPage');
|
const selectAuthPageDomain = () => (state) => state.get('users-permissions-authPage');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default selector used by AuthPage
|
* Default selector used by AuthPage
|
||||||
|
@ -23,9 +23,6 @@ import PluginHeader from 'components/PluginHeader';
|
|||||||
import Plugins from 'components/Plugins';
|
import Plugins from 'components/Plugins';
|
||||||
import Policies from 'components/Policies';
|
import Policies from 'components/Policies';
|
||||||
|
|
||||||
import injectSaga from 'utils/injectSaga';
|
|
||||||
import injectReducer from 'utils/injectReducer';
|
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import {
|
import {
|
||||||
addUser,
|
addUser,
|
||||||
@ -326,16 +323,8 @@ function mapDispatchToProps(dispatch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
||||||
|
const withReducer = strapi.injectReducer({ key: 'editPage', reducer, pluginId: 'users-permissions'});
|
||||||
/* Remove this line if the container doesn't have a route and
|
const withSaga = strapi.injectSaga({ key: 'editPage', saga, pluginId: 'users-permissions' });
|
||||||
* check the documentation to see how to create the container's store
|
|
||||||
*/
|
|
||||||
const withReducer = injectReducer({ key: 'editPage', reducer });
|
|
||||||
|
|
||||||
/* Remove the line below the container doesn't have a route and
|
|
||||||
* check the documentation to see how to create the container's store
|
|
||||||
*/
|
|
||||||
const withSaga = injectSaga({ key: 'editPage', saga });
|
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withReducer,
|
withReducer,
|
||||||
|
@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
|
|||||||
/**
|
/**
|
||||||
* Direct selector to the editPage state domain
|
* Direct selector to the editPage state domain
|
||||||
*/
|
*/
|
||||||
const selectEditPageDomain = () => (state) => state.get('editPage');
|
const selectEditPageDomain = () => (state) => state.get('users-permissions-editPage');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default selector used by EditPage
|
* Default selector used by EditPage
|
||||||
|
@ -19,10 +19,6 @@ import List from 'components/List';
|
|||||||
import PluginHeader from 'components/PluginHeader';
|
import PluginHeader from 'components/PluginHeader';
|
||||||
import PopUpForm from 'components/PopUpForm';
|
import PopUpForm from 'components/PopUpForm';
|
||||||
|
|
||||||
// Utils
|
|
||||||
import injectReducer from 'utils/injectReducer';
|
|
||||||
import injectSaga from 'utils/injectSaga';
|
|
||||||
|
|
||||||
// Selectors
|
// Selectors
|
||||||
import selectHomePage from './selectors';
|
import selectHomePage from './selectors';
|
||||||
|
|
||||||
@ -280,8 +276,8 @@ const mapStateToProps = selectHomePage();
|
|||||||
|
|
||||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
||||||
|
|
||||||
const withReducer = injectReducer({ key: 'homePage', reducer });
|
const withReducer = strapi.injectReducer({ key: 'homePage', reducer, pluginId: 'users-permissions' });
|
||||||
const withSaga = injectSaga({ key: 'homePage', saga });
|
const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId: 'users-permissions' });
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withReducer,
|
withReducer,
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
// import { LOCATION_CHANGE } from 'react-router-redux';
|
||||||
import { findIndex, get } from 'lodash';
|
import { findIndex, get } from 'lodash';
|
||||||
import { takeLatest, put, fork, take, cancel, select, call } from 'redux-saga/effects';
|
import {
|
||||||
|
takeLatest,
|
||||||
|
put,
|
||||||
|
fork,
|
||||||
|
// take,
|
||||||
|
// cancel,
|
||||||
|
select,
|
||||||
|
call,
|
||||||
|
} from 'redux-saga/effects';
|
||||||
|
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
|
||||||
@ -75,13 +83,14 @@ export function* submitData(action) {
|
|||||||
}
|
}
|
||||||
// Individual exports for testing
|
// Individual exports for testing
|
||||||
export function* defaultSaga() {
|
export function* defaultSaga() {
|
||||||
const loadDataWatcher = yield fork(takeLatest, FETCH_DATA, dataFetch);
|
// const loadDataWatcher = yield fork(takeLatest, FETCH_DATA, dataFetch);
|
||||||
|
yield fork(takeLatest, FETCH_DATA, dataFetch);
|
||||||
|
|
||||||
yield fork(takeLatest, DELETE_DATA, dataDelete);
|
yield fork(takeLatest, DELETE_DATA, dataDelete);
|
||||||
yield fork(takeLatest, SUBMIT, submitData);
|
yield fork(takeLatest, SUBMIT, submitData);
|
||||||
|
|
||||||
yield take(LOCATION_CHANGE);
|
// yield take(LOCATION_CHANGE);
|
||||||
yield cancel(loadDataWatcher);
|
// yield cancel(loadDataWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All sagas to be loaded
|
// All sagas to be loaded
|
||||||
|
@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
|
|||||||
/**
|
/**
|
||||||
* Direct selector to the homePage state domain
|
* Direct selector to the homePage state domain
|
||||||
*/
|
*/
|
||||||
const selectHomePageDomain = () => state => state.get('homePage');
|
const selectHomePageDomain = () => state => state.get('users-permissions-homePage');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default selector used by HomePage
|
* Default selector used by HomePage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user