Commit f3706c8c authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza
Browse files

Upgraded to modular code layout

- move requestService actions in service folder
- user root actions and reducer renamed to public, some fixes related to getState() func
- fixed stepper view, fixed subset editor actions, now stepper routes declared only in steps.ts
- Migrate to modular layout merged
- added module for accessions
- added module for institute
- added module for subsets
parent 16ed72b9
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import {DASHBOARD_RECEIVE_SUBSETS, DASHBOARD_RECEIVE_SUBSET, DASHBOARD_REMOVE_SUBSET, DASHBOARD_APPEND_SUBSETS, ADD_CREATOR_TO_SUBSET, REMOVE_CREATOR_FROM_SUBSET, UPDATE_SUBSET_CREATOR} from 'subsets/constants';
import FilteredPage from 'model/FilteredPage';
import Subset from 'model/Subset';
import * as _ from 'lodash';
const INITIAL_STATE: {
subset: Subset;
subsetError: any;
paged: FilteredPage<Subset>;
pagedError: any;
} = {
subset: null,
subsetError: null,
paged: null,
pagedError: null,
};
function dashboardSubsets(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
case DASHBOARD_RECEIVE_SUBSET: {
const { subset, error } = action.payload;
const receivedIndex = state.paged ? state.paged.content.findIndex((item) => item.uuid === subset.uuid) : -1;
if (receivedIndex !== -1) {
return update(state, {
subset: { $set: subset },
paged: {
content: {
[receivedIndex]: {$set: subset},
},
},
subsetError: {$set: error},
});
} else {
return update(state, {
subset: { $set: subset},
paged: {$set: null},
subsetError: {$set: error},
});
}
}
case DASHBOARD_RECEIVE_SUBSETS: {
const { paged, error } = action.payload;
return update(state, {
paged: { $set: paged },
pagedError: { $set: error },
});
}
case DASHBOARD_APPEND_SUBSETS: {
const {paged, error} = action.payload;
return !state.paged ? update(state, {
paged: {$set: paged},
pagedError: {$set: error},
}) :
update(state, {
paged: {
content: {$push: paged.content},
number: {$set: paged.number},
last: {$set: paged.last},
},
pagedError: {$set: error},
});
}
case DASHBOARD_REMOVE_SUBSET: {
const removeIndex = state.paged ? _.findIndex(state.paged.content, (item) => item.uuid === action.payload.subset.uuid) : -1;
return removeIndex === -1 ? state
: update(state, {
paged: {
content: {$splice: [[removeIndex, 1]]},
numberOfElements: {$set: state.paged.numberOfElements - 1},
totalElements: {$set: state.paged.totalElements - 1},
},
});
}
case ADD_CREATOR_TO_SUBSET: {
if (state.subset) {
return update(state, {
subset: { creators: { $push: [ action.payload.creator ] } },
});
} else {
return state;
}
}
case REMOVE_CREATOR_FROM_SUBSET: {
if (state.subset) {
return update(state, {
subset: { creators: { $apply: (creators) => creators.filter((creator) => creator.uuid !== action.payload.creator.uuid) } },
});
} else {
return state;
}
}
case UPDATE_SUBSET_CREATOR: {
if (state.subset) {
const index = state.subset.creators.findIndex((creator) => creator.uuid === action.payload.creator.uuid);
return update(state, {
subset: { creators: { [index]: { $set: action.payload.creator } } },
});
} else {
return state;
}
}
default:
return state;
}
}
export default dashboardSubsets;
import { combineReducers } from 'redux';
import dashboard from './dashboard';
import publicSubsets from './public';
const rootReducer = combineReducers({
dashboard,
public: publicSubsets,
});
export default rootReducer;
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import {RECEIVE_SUBSETS, RECEIVE_SUBSET, REMOVE_SUBSET, APPEND_SUBSETS, ADD_CREATOR_TO_SUBSET, REMOVE_CREATOR_FROM_SUBSET, UPDATE_SUBSET_CREATOR} from 'constants/subsets';
import {RECEIVE_SUBSETS, RECEIVE_SUBSET, REMOVE_SUBSET, APPEND_SUBSETS, ADD_CREATOR_TO_SUBSET, REMOVE_CREATOR_FROM_SUBSET, UPDATE_SUBSET_CREATOR} from 'subsets/constants';
import FilteredPage from 'model/FilteredPage';
import Subset from 'model/Subset';
......@@ -20,7 +20,7 @@ const INITIAL_STATE: {
pagedError: null,
};
function subsets(state = INITIAL_STATE, action: IReducerAction) {
function publicSubsets(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
......@@ -118,4 +118,4 @@ function subsets(state = INITIAL_STATE, action: IReducerAction) {
}
}
export default subsets;
export default publicSubsets;
import SubsetBrowsePage from 'subsets/ui/BrowsePage';
import SubsetDisplayPage from 'subsets/ui/DisplayPage';
import SubsetDashboardPage from 'subsets/ui/dashboard/DashboardPage';
import SubsetStepper from 'subsets/ui/dashboard/StepperPage';
import BasicInfoStep from 'subsets/ui/dashboard//subset-stepper/steps/basic-info';
import steps from 'subsets/ui/dashboard/subset-stepper/steps';
import {ROLE_ADMINISTRATOR, ROLE_USER} from 'constants/userRoles';
const publicRoutes = [
{
path: '/subsets/:filterCode(v.+)?',
component: SubsetBrowsePage,
exact: true,
extraProps: {
title: 'Collection subsets',
subtitle: 'Browse subsets',
},
},
{
path: '/subsets/:uuid([a-z\\-0-9]+)',
component: SubsetDisplayPage,
exact: true,
extraProps: {
title: 'Iiik',
subtitle: 'Oook',
},
},
];
const dashboardRoutes = [
{
path: '/subsets/edit',
component: SubsetStepper,
auth: [ROLE_USER, ROLE_ADMINISTRATOR],
extraProps: {
title: 'Subset create',
},
routes: [
{
path: '/',
component: BasicInfoStep,
exact: true,
},
],
},
{
path: '/subsets/:uuid/',
component: SubsetStepper,
auth: [ROLE_USER, ROLE_ADMINISTRATOR],
extraProps: {
title: 'Subset create',
},
routes: [
...steps,
],
},
{
path: '/subsets',
component: SubsetDashboardPage,
exact: true,
extraProps: {
title: 'My Dashboard',
},
},
];
export {publicRoutes as subsetPublicRoutes, dashboardRoutes as subsetDashboardRoutes};
......@@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux';
import { parse } from 'query-string';
// Actions
import { applyFilters, loadSubsetsPage, updateRoute } from 'actions/subsets';
import { applyFilters, loadSubsetsPage, updateRoute } from 'subsets/actions/public';
// Models
import Subset from 'model/Subset';
......@@ -80,7 +80,7 @@ class BrowsePage extends BrowsePageTemplate<Subset> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.subsets.paged || undefined,
paged: state.subsets.public.paged || undefined,
filterCode: ownProps.match.params.filterCode,
});
......
......@@ -2,8 +2,9 @@ import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
// Actions
import {loadSubset, unpublishSubset} from 'actions/subsets';
import {listAccessionsPromise} from 'actions/accessions';
import {loadSubset} from 'subsets/actions/public';
import {unpublishSubset} from 'subsets/actions/editor';
import {listAccessionsPromise} from 'accessions/actions/public';
import navigateTo from 'actions/navigation';
// Models
import Subset from 'model/Subset';
......@@ -81,9 +82,9 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
subset: state.subsets.subset,
subset: state.subsets.public.subset,
userRole: state.login.authorities,
error: state.subsets.subsetError,
error: state.subsets.public.subsetError,
uuid: ownProps.match.params.uuid,
});
......
import * as React from 'react';
import { reduxForm } from 'redux-form';
import { SUBSET_FILTERFORM } from 'constants/subsets';
import { SUBSET_FILTERFORM } from 'subsets/constants';
import FiltersBlock from 'ui/common/filter/FiltersBlock';
import CollapsibleComponentSearch from 'ui/common/filter/CollapsibleComponentSearch';
......
......@@ -3,7 +3,8 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {parse} from 'query-string';
// Actions
import {applyFilters, loadMySubsets, listMySubsetsPromise, updateRoute} from 'actions/subsets';
import {loadMySubsets} from 'subsets/actions/dashboard';
import {applyFilters} from 'subsets/actions/public';
// Models
import Subset from 'model/Subset';
import FilteredPage from 'model/FilteredPage';
......@@ -51,9 +52,9 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
];
protected loadNextPage = (page: number, pageSize: number) => {
const {paged, listMySubsetsPromise} = this.props;
const {paged, loadMySubsets} = this.props;
return listMySubsetsPromise(null, {direction: paged.sort[0].direction || 'ASC', properties: [paged.sort[0].property], page, size: pageSize});
loadMySubsets(null, {direction: paged.sort[0].direction || 'ASC', properties: [paged.sort[0].property], page, size: pageSize});
}
private onPaginationChange = (page: number, results: number, sortBy: string, dir?: string) => {
......@@ -109,7 +110,7 @@ class DashboardPage extends React.Component<IDashboardPageProps> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.subsets.paged || undefined,
paged: state.subsets.dashboard.paged || undefined,
login: state.login,
pagination: {
page: +parse(ownProps.location.search).p || 0, // current page
......@@ -121,9 +122,7 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
applyFilters,
listMySubsetsPromise,
loadMySubsets,
updateRoute,
}, dispatch);
......
......@@ -5,11 +5,12 @@ import {bindActionCreators} from 'redux';
import Subset from 'model/Subset';
// actions
import {approveSubset, createSubset, deleteSubset, loadSubset, publishSubset, unpublishSubset} from 'actions/subsets';
import {approveSubset, deleteSubset, publishSubset, unpublishSubset} from 'subsets/actions/editor';
import {createSubset, loadSubset} from 'subsets/actions/dashboard';
// ui
import StepperPageTemplate from 'ui/pages/_base/StepperPage';
import steps from 'ui/pages/dashboard/subsets/subset-stepper/steps';
import steps from 'subsets/ui/dashboard/subset-stepper/steps';
class StepperPage extends StepperPageTemplate<Subset> {
......@@ -21,7 +22,7 @@ class StepperPage extends StepperPageTemplate<Subset> {
const mapStateToProps = (state, ownProps) => ({
steps,
path: 'subsets',
item: state.subsets.subset,
item: state.subsets.dashboard.subset,
pageTitle: ownProps.route.extraProps.title, // route-configured
location: ownProps.location,
uuid: ownProps.match.params.uuid,
......
import ReviewStep from 'subsets/ui/dashboard/subset-stepper/steps/review';
import CreatorsStep from 'subsets/ui/dashboard/subset-stepper/steps/creators';
import AccessionsListStep from 'subsets/ui/dashboard/subset-stepper/steps/accessions-list';
import BasicInfoStep from 'subsets/ui/dashboard/subset-stepper/steps/basic-info';
const steps = [
{
id: 1,
name: 'Basic information',
link: 'edit',
path: 'edit',
component: BasicInfoStep,
exact: true,
},
{
id: 2,
name: 'List of accessions',
link: 'edit/list-of-accessions',
path: 'edit/list-of-accessions',
component: AccessionsListStep,
exact: true,
},
{
id: 3,
name: 'Subset creators',
link: 'edit/creators',
path: 'edit/creators',
component: CreatorsStep,
exact: true,
},
{
id: 4,
name: 'Review and publish',
link: 'edit/review-and-publish',
path: 'edit/review-and-publish',
component: ReviewStep,
exact: true,
},
];
......
......@@ -2,8 +2,8 @@ import * as React from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
// actions
import {updateSubsetAccessionIdentifiers} from 'actions/subsets';
import {listAccessionsPromise} from 'actions/accessions';
import {updateSubsetAccessionIdentifiers} from 'subsets/actions/editor';
import {listAccessionsPromise} from 'accessions/actions/public'; // TODO maybe move to dashboard or import from service
// models
import Subset from 'model/Subset';
......
import * as React from 'react';
import {Field, reduxForm, FieldArray} from 'redux-form';
import {remoteSubmit} from 'actions/subsets';
import {SUBSET_FORM} from 'constants/subsets';
import {saveSubset} from 'subsets/actions/editor';
import {SUBSET_FORM} from 'subsets/constants';
import Validators from 'utilities/Validators';
import {TextField} from 'ui/common/text-field';
......@@ -76,6 +76,6 @@ class BasicInfoStep extends React.Component<ILoginContainerProps, any> {
export default reduxForm({
form: SUBSET_FORM,
onSubmit: remoteSubmit,
onSubmit: (values, dispatch) => dispatch(saveSubset(values)),
enableReinitialize: true,
})((BasicInfoStep));
......@@ -3,7 +3,7 @@ import {bindActionCreators} from 'redux';
import {isInvalid, submit} from 'redux-form';
import {connect} from 'react-redux';
// constants
import {SUBSET_FORM} from 'constants/subsets';
import {SUBSET_FORM} from 'subsets/constants';
// ui
import BasicInfoForm from './BasicInfoForm';
import StepperTemplate from 'ui/common/stepper/StepperTemplate';
......
......@@ -7,7 +7,7 @@ import {log} from 'utilities/debug';
import Validators from 'utilities/Validators';
// constants
import {SUBSET_CREATOR_FORM} from 'constants/subsets';
import {SUBSET_CREATOR_FORM} from 'subsets/constants';
// models
import Subset from 'model/Subset';
......
......@@ -5,10 +5,10 @@ import {getFormValues} from 'redux-form';
import * as _ from 'lodash';
// actions
import {createSubsetCreator, deleteSubsetCreatorRequest, updateSubsetCreatorRequest} from 'actions/subsets';
import {createSubsetCreator, deleteSubsetCreatorRequest, updateSubsetCreatorRequest} from 'subsets/actions/editor';
// constants
import { SUBSET_CREATOR_FORM} from 'constants/subsets';
import { SUBSET_CREATOR_FORM} from 'subsets/constants';
// models
import Creator from 'model/Creator';
......
......@@ -2,10 +2,10 @@ import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
// actions
import {listAccessionsPromise} from 'actions/accessions';
import {listAccessionsPromise} from 'accessions/actions/public';
// ui
import SubsetDisplay from 'ui/pages/subsets/c/SubsetDisplay';
import SubsetDisplay from 'subsets/ui/c/SubsetDisplay';
import StepperTemplate from 'ui/common/stepper/StepperTemplate';
class ReviewAndPublishStep extends StepperTemplate<any> {
......@@ -18,7 +18,7 @@ class ReviewAndPublishStep extends StepperTemplate<any> {
)
}
const mapStateToProps = (state, ownProps) => ({
accessionsPage: state.accessions.paged,
accessionsPage: state.accessions.public.paged,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
......@@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux';
import {updateHistory} from 'actions/history';
import {loadCrops} from 'crop/actions/public';
import {initMyList} from 'user/actions/root';
import {initMyList} from 'user/actions/public';
import { serverInfoRequest } from 'actions/serverInfo';
import { withRouter } from 'react-router-dom';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment