Add feature user-admin

Change-Id: Idcdc718ee502fd803a96409e67109cdac5b8b806
This commit is contained in:
Manuel Stahl 2019-02-07 13:23:30 +01:00
parent deefc950f9
commit 07bc32c05d
14 changed files with 135 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux'; import { routerReducer } from 'react-router-redux';
import homeReducer from '../features/home/redux/reducer'; import homeReducer from '../features/home/redux/reducer';
import commonReducer from '../features/common/redux/reducer'; import commonReducer from '../features/common/redux/reducer';
import userAdminReducer from '../features/user-admin/redux/reducer';
// NOTE 1: DO NOT CHANGE the 'reducerMap' name and the declaration pattern. // NOTE 1: DO NOT CHANGE the 'reducerMap' name and the declaration pattern.
// This is used for Rekit cmds to register new features, remove features, etc. // This is used for Rekit cmds to register new features, remove features, etc.
@ -12,6 +13,7 @@ const reducerMap = {
router: routerReducer, router: routerReducer,
home: homeReducer, home: homeReducer,
common: commonReducer, common: commonReducer,
userAdmin: userAdminReducer,
}; };
export default combineReducers(reducerMap); export default combineReducers(reducerMap);

View File

@ -1,14 +1,16 @@
import { App } from '../features/home'; import { App } from '../features/home';
import { PageNotFound } from '../features/common'; import { PageNotFound } from '../features/common';
import homeRoute from '../features/home/route';
import commonRoute from '../features/common/route';
import _ from 'lodash'; import _ from 'lodash';
import commonRoute from '../features/common/route';
import homeRoute from '../features/home/route';
import userAdminRoute from '../features/user-admin/route';
// NOTE: DO NOT CHANGE the 'childRoutes' name and the declaration pattern. // NOTE: DO NOT CHANGE the 'childRoutes' name and the declaration pattern.
// This is used for Rekit cmds to register routes config for new features, and remove config when remove features, etc. // This is used for Rekit cmds to register routes config for new features, and remove config when remove features, etc.
const childRoutes = [ const childRoutes = [
homeRoute, homeRoute,
commonRoute, commonRoute,
userAdminRoute,
]; ];
const routes = [{ const routes = [{

View File

@ -0,0 +1,39 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as actions from './redux/actions';
export class DefaultPage extends Component {
static propTypes = {
userAdmin: PropTypes.object.isRequired,
actions: PropTypes.object.isRequired,
};
render() {
return (
<div className="user-admin-default-page">
Page Content: user-admin/DefaultPage
</div>
);
}
}
/* istanbul ignore next */
function mapStateToProps(state) {
return {
userAdmin: state.userAdmin,
};
}
/* istanbul ignore next */
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({ ...actions }, dispatch)
};
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(DefaultPage);

View File

@ -0,0 +1,5 @@
@import '../../styles/mixins';
.user-admin-default-page {
}

View File

@ -0,0 +1 @@
export { default as DefaultPage } from './DefaultPage';

View File

View File

@ -0,0 +1,11 @@
// Initial state is the place you define all initial values for the Redux store of the feature.
// In the 'standard' way, initialState is defined in reducers: http://redux.js.org/docs/basics/Reducers.html
// But when application grows, there will be multiple reducers files, it's not intuitive what data is managed by the whole store.
// So Rekit extracts the initial state definition into a separate module so that you can have
// a quick view about what data is used for the feature, at any time.
// NOTE: initialState constant is necessary so that Rekit could auto add initial state when creating async actions.
const initialState = {
};
export default initialState;

View File

@ -0,0 +1,23 @@
// This is the root reducer of the feature. It is used for:
// 1. Load reducers from each action in the feature and process them one by one.
// Note that this part of code is mainly maintained by Rekit, you usually don't need to edit them.
// 2. Write cross-topic reducers. If a reducer is not bound to some specific action.
// Then it could be written here.
// Learn more from the introduction of this approach:
// https://medium.com/@nate_wang/a-new-approach-for-managing-redux-actions-91c26ce8b5da.
import initialState from './initialState';
const reducers = [
];
export default function reducer(state = initialState, action) {
let newState;
switch (action.type) {
// Handle cross-topic actions here
default:
newState = state;
break;
}
return reducers.reduce((s, r) => r(s, action), newState);
}

View File

@ -0,0 +1,14 @@
// This is the JSON way to define React Router rules in a Rekit app.
// Learn more from: http://rekit.js.org/docs/routing.html
import {
DefaultPage,
} from './';
export default {
path: 'user-admin',
name: 'User admin',
childRoutes: [
{ path: 'default-page', name: 'Default page', component: DefaultPage, isIndex: true },
],
};

View File

@ -0,0 +1,2 @@
@import '../../styles/mixins';
@import './DefaultPage';

View File

@ -2,3 +2,4 @@
@import './global'; @import './global';
@import '../features/home/style'; @import '../features/home/style';
@import '../features/common/style'; @import '../features/common/style';
@import '../features/user-admin/style';

View File

@ -0,0 +1,19 @@
import React from 'react';
import { shallow } from 'enzyme';
import { DefaultPage } from '../../../src/features/user-admin/DefaultPage';
describe('user-admin/DefaultPage', () => {
it('renders node with correct class name', () => {
const props = {
userAdmin: {},
actions: {},
};
const renderedComponent = shallow(
<DefaultPage {...props} />
);
expect(
renderedComponent.find('.user-admin-default-page').length
).toBe(1);
});
});

View File

@ -0,0 +1,14 @@
import reducer from '../../../../src/features/user-admin/redux/reducer';
describe('user-admin/redux/reducer', () => {
it('does nothing if no matched action', () => {
const prevState = {};
const state = reducer(
prevState,
{ type: '__UNKNOWN_ACTION_TYPE__' }
);
expect(state).toBe(prevState);
});
// TODO: add global reducer test if needed.
});