mirror of
https://github.com/strapi/strapi.git
synced 2025-09-03 13:50:38 +00:00
Remove separate store for users-permissions
This commit is contained in:
parent
ba471149ea
commit
72cc7d0837
@ -10,6 +10,8 @@ import {
|
||||
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';
|
||||
@ -94,4 +96,7 @@ window.strapi = Object.assign(window.strapi || {}, {
|
||||
currentLanguage: window.localStorage.getItem('strapi-admin-language') || window.navigator.language || window.navigator.userLanguage || 'en',
|
||||
lockApp,
|
||||
unlockApp,
|
||||
});
|
||||
injectReducer,
|
||||
injectSaga,
|
||||
store,
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ import getInjectors from './reducerInjectors';
|
||||
* @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 {
|
||||
static WrappedComponent = WrappedComponent;
|
||||
static displayName = `withReducer(${(WrappedComponent.displayName || WrappedComponent.name || 'Component')})`;
|
||||
@ -21,8 +21,13 @@ export default ({ key, reducer }) => (WrappedComponent) => {
|
||||
|
||||
componentWillMount() {
|
||||
const { injectReducer } = this.injectors;
|
||||
let reducerName = key;
|
||||
|
||||
injectReducer(key, reducer);
|
||||
if (pluginId) {
|
||||
reducerName = `${pluginId}-${key}`;
|
||||
}
|
||||
|
||||
injectReducer(reducerName, reducer);
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
*/
|
||||
export default ({ key, saga, mode }) => (WrappedComponent) => {
|
||||
export default ({ key, saga, mode, pluginId }) => (WrappedComponent) => {
|
||||
class InjectSaga extends React.Component {
|
||||
static WrappedComponent = WrappedComponent;
|
||||
static displayName = `withSaga(${(WrappedComponent.displayName || WrappedComponent.name || 'Component')})`;
|
||||
@ -25,8 +25,13 @@ export default ({ key, saga, mode }) => (WrappedComponent) => {
|
||||
|
||||
componentWillMount() {
|
||||
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() {
|
||||
|
@ -11,9 +11,9 @@ import './public-path.js'; // eslint-disable-line import/extensions
|
||||
|
||||
import React from 'react';
|
||||
import Loadable from 'react-loadable';
|
||||
import { Provider } from 'react-redux';
|
||||
// import { Provider } from 'react-redux';
|
||||
import LoadingIndicatorPage from 'components/LoadingIndicatorPage';
|
||||
import configureStore from './store';
|
||||
// import configureStore from './store';
|
||||
import { translationMessages } from './i18n';
|
||||
|
||||
|
||||
@ -61,22 +61,23 @@ const apiUrl = `${strapi.backendURL}/${pluginId}`;
|
||||
const router = strapi.router;
|
||||
|
||||
// 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
|
||||
function Comp(props) {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<LoadableApp {...props} />
|
||||
</Provider>
|
||||
// <Provider store={store}>
|
||||
<LoadableApp {...props} />
|
||||
// </Provider>
|
||||
);
|
||||
}
|
||||
|
||||
if (window.Cypress) {
|
||||
window.__store__ = Object.assign(window.__store__ || {}, {
|
||||
[pluginId]: store,
|
||||
});
|
||||
}
|
||||
// if (window.Cypress) {
|
||||
// window.__store__ = Object.assign(window.__store__ || {}, {
|
||||
// [pluginId]: store,
|
||||
// });
|
||||
// }
|
||||
|
||||
// Hot reloadable translation json files
|
||||
if (module.hot) {
|
||||
|
@ -8,7 +8,6 @@ import { fromJS } from 'immutable';
|
||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||
|
||||
import globalReducer from 'containers/App/reducer'; // eslint-disable-line
|
||||
|
||||
/*
|
||||
* routeReducer
|
||||
*
|
||||
|
@ -1,5 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* App actions
|
||||
*
|
||||
*/
|
@ -1,5 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* App constants
|
||||
*
|
||||
*/
|
@ -7,10 +7,9 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { createStructuredSelector } from 'reselect';
|
||||
// import { connect } from 'react-redux';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
import { bindActionCreators, compose } from 'redux';
|
||||
// import { bindActionCreators, compose } from 'redux';
|
||||
|
||||
// Utils
|
||||
import { pluginId } from 'app';
|
||||
@ -59,18 +58,17 @@ App.propTypes = {
|
||||
location: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
export function mapDispatchToProps(dispatch) {
|
||||
return bindActionCreators(
|
||||
{},
|
||||
dispatch,
|
||||
);
|
||||
}
|
||||
|
||||
const mapStateToProps = createStructuredSelector({});
|
||||
// export function mapDispatchToProps(dispatch) {
|
||||
// return bindActionCreators(
|
||||
// {},
|
||||
// dispatch,
|
||||
// );
|
||||
// }
|
||||
|
||||
// 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(
|
||||
withConnect,
|
||||
)(App);
|
||||
// export default compose(
|
||||
// withConnect,
|
||||
// )(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
|
||||
import auth from 'utils/auth';
|
||||
import injectSaga from 'utils/injectSaga';
|
||||
import injectReducer from 'utils/injectReducer';
|
||||
|
||||
import {
|
||||
hideLoginErrorsInput,
|
||||
@ -328,16 +326,8 @@ function mapDispatchToProps(dispatch) {
|
||||
}
|
||||
|
||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
||||
|
||||
/* Remove this line if the container doesn't have a route and
|
||||
* 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 });
|
||||
const withReducer = strapi.injectReducer({ key: 'authPage', reducer, pluginId: 'users-permissions' });
|
||||
const withSaga = strapi.injectSaga({ key: 'authPage', saga, pluginId: 'users-permissions' });
|
||||
|
||||
export default compose(
|
||||
withReducer,
|
||||
|
@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
|
||||
/**
|
||||
* 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
|
||||
|
@ -23,9 +23,6 @@ import PluginHeader from 'components/PluginHeader';
|
||||
import Plugins from 'components/Plugins';
|
||||
import Policies from 'components/Policies';
|
||||
|
||||
import injectSaga from 'utils/injectSaga';
|
||||
import injectReducer from 'utils/injectReducer';
|
||||
|
||||
// Actions
|
||||
import {
|
||||
addUser,
|
||||
@ -326,16 +323,8 @@ function mapDispatchToProps(dispatch) {
|
||||
}
|
||||
|
||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
||||
|
||||
/* Remove this line if the container doesn't have a route and
|
||||
* 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 });
|
||||
const withReducer = strapi.injectReducer({ key: 'editPage', reducer, pluginId: 'users-permissions'});
|
||||
const withSaga = strapi.injectSaga({ key: 'editPage', saga, pluginId: 'users-permissions' });
|
||||
|
||||
export default compose(
|
||||
withReducer,
|
||||
|
@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
|
||||
/**
|
||||
* 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
|
||||
|
@ -19,10 +19,6 @@ import List from 'components/List';
|
||||
import PluginHeader from 'components/PluginHeader';
|
||||
import PopUpForm from 'components/PopUpForm';
|
||||
|
||||
// Utils
|
||||
import injectReducer from 'utils/injectReducer';
|
||||
import injectSaga from 'utils/injectSaga';
|
||||
|
||||
// Selectors
|
||||
import selectHomePage from './selectors';
|
||||
|
||||
@ -280,8 +276,8 @@ const mapStateToProps = selectHomePage();
|
||||
|
||||
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
||||
|
||||
const withReducer = injectReducer({ key: 'homePage', reducer });
|
||||
const withSaga = injectSaga({ key: 'homePage', saga });
|
||||
const withReducer = strapi.injectReducer({ key: 'homePage', reducer, pluginId: 'users-permissions' });
|
||||
const withSaga = strapi.injectSaga({ key: 'homePage', saga, pluginId: 'users-permissions' });
|
||||
|
||||
export default compose(
|
||||
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 { 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';
|
||||
|
||||
@ -75,13 +83,14 @@ export function* submitData(action) {
|
||||
}
|
||||
// Individual exports for testing
|
||||
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, SUBMIT, submitData);
|
||||
|
||||
yield take(LOCATION_CHANGE);
|
||||
yield cancel(loadDataWatcher);
|
||||
// yield take(LOCATION_CHANGE);
|
||||
// yield cancel(loadDataWatcher);
|
||||
}
|
||||
|
||||
// All sagas to be loaded
|
||||
|
@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
|
||||
/**
|
||||
* 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user