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 InstituteBrowsePage from 'institutes/ui/BrowsePage';
import InstituteDisplayPage from 'institutes/ui/DisplayPage';
const publicRoutes = [
{
path: '/wiews/:filterCode(v.+)?',
component: InstituteBrowsePage,
exact: true,
},
{
path: '/wiews/:wiewsCode([a-z\\-0-9]+)',
component: InstituteDisplayPage,
exact: true,
},
];
const dashboardRoutes = [
// not yet
];
export {publicRoutes as institutePublicRoutes, dashboardRoutes as instituteDashboardRoutes};
......@@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux';
import { parse } from 'query-string';
// Actions
import {applyFilters, loadInstitutesPage, updateRoute} from 'actions/institutes';
import {applyFilters, loadInstitutesPage, updateRoute} from 'institutes/actions/public';
// Models
import FaoInstitute from 'model/FaoInstitute';
......@@ -79,7 +79,7 @@ class BrowsePage extends BrowsePageTemplate<FaoInstitute> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.institutes.paged || undefined,
paged: state.institutes.public.paged || undefined,
filterCode: ownProps.match.params.filterCode,
});
......
......@@ -5,8 +5,8 @@ import { translate } from 'react-i18next';
import { Link } from 'react-router-dom';
// Actions
import {loadInstitute} from 'actions/institutes';
import {applyFilters} from 'actions/accessions';
import {loadInstitute} from 'institutes/actions/public';
import {applyFilters} from 'accessions/actions/public';
// Models
import FaoInstituteDetails from 'model/FaoInstituteDetails';
......@@ -246,8 +246,8 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
institute: state.institutes.institute,
error: state.institutes.instituteError,
institute: state.institutes.public.institute,
error: state.institutes.public.instituteError,
code: ownProps.match.params.wiewsCode,
});
......
import * as React from 'react';
import { reduxForm } from 'redux-form';
import { INSTITUTE_FILTERFORM } from 'constants/institutes';
import { INSTITUTE_FILTERFORM } from 'institutes/constants';
import FiltersBlock from 'ui/common/filter/FiltersBlock';
import CollapsibleComponentSearch from 'ui/common/filter/CollapsibleComponentSearch';
......
......@@ -8,14 +8,14 @@ import history from './history';
import pageTitle from './pageTitle';
import snackbar from './snackbar';
import filterCode from './filterCode';
import subsets from './subsets';
import accessions from './accessions';
import institutes from './institute';
import subsets from 'subsets/reducers';
import accessions from 'accessions/reducers';
import institutes from 'institutes/reducers';
import applicationConfig from './applicationConfig';
import crop from 'crop/reducers';
import user from 'user/reducers';
import requests from 'requests/reducers';
import repository from 'repository/reducers';
import requests from './requests';
const rootReducer = combineReducers({
routing: routerReducer,
......
import * as _ from 'lodash';
import {getRequest, listRequests, sendValidationEmail, recheckPid, validateRequest} from 'service/genesys/actions/requestService';
// constants
import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RECEIVE_MATERIAL_REQUESTS} from 'requests/constants';
// models
import MaterialRequest from 'model/MaterialRequest';
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
const receiveRequests = (paged: FilteredPage<MaterialRequest>, error = null) => ({
type: ADMIN_RECEIVE_MATERIAL_REQUESTS,
payload: { paged, error },
});
const appendRequests = (paged: FilteredPage<MaterialRequest>, error = null) => ({
type: ADMIN_APPEND_MATERIAL_REQUESTS,
payload: { paged, error },
});
const receiveRequest = (request: MaterialRequest, error = null) => ({
type: ADMIN_RECEIVE_MATERIAL_REQUEST,
payload: { request, error },
});
const refreshRequestPID = (request: MaterialRequest) => (dispatch, getState) => {
const page = getState().requests.admin.paged;
if (page) {
const toUpdateIndex = _.findIndex(page.content, (contentItem) => contentItem.uuid === request.uuid);
if (toUpdateIndex !== -1) {
page.content[toUpdateIndex].body.pid = request.body.pid;
}
return dispatch(receiveRequests(page));
}
};
export { listRequests as listMaterialRequestsPromise };
export const listMaterialRequests = (page: IPageRequest) => (dispatch) => {
return dispatch(listRequests(null, page))
.then((page) => {
if (page.number === 0) {
dispatch(receiveRequests(page));
} else {
dispatch(appendRequests(page));
}
})
.catch((error) => {
dispatch(receiveRequests(null, error));
});
};
export const loadMaterialRequest = (uuid: string) => (dispatch) => {
return dispatch(getRequest(uuid))
.then((request) => {
dispatch(receiveRequest(request));
})
.catch((error) => {
dispatch(receiveRequest(null, error));
});
};
export const recheckPidAction = (uuid: string) => (dispatch) => {
return dispatch(recheckPid(uuid))
.then((request) => {
dispatch(receiveRequest(request));
dispatch(refreshRequestPID(request));
})
.catch((error) => {
dispatch(receiveRequest(null, error));
});
};
export const validateRequestAction = (uuid: string) => (dispatch) => {
return dispatch(validateRequest(uuid))
.then((request) => {
dispatch(receiveRequest(request));
})
.catch((error) => {
dispatch(receiveRequest(null, error));
});
};
export const sendValidationEmailAction = (uuid: string) => (dispatch) => {
return dispatch(sendValidationEmail(uuid))
.then((request) => {
dispatch(receiveRequest(request));
})
.catch((error) => {
dispatch(receiveRequest(null, error));
});
};
export const RECEIVE_MATERIAL_REQUESTS = 'requests/RECEIVE_MATERIAL_REQUESTS';
export const APPEND_MATERIAL_REQUESTS = 'requests/APPEND_MATERIAL_REQUESTS';
export const RECEIVE_MATERIAL_REQUEST = 'requests/RECEIVE_MATERIAL_REQUEST';
export const ADMIN_RECEIVE_MATERIAL_REQUESTS = 'requests/admin/RECEIVE_MATERIAL_REQUESTS';
export const ADMIN_APPEND_MATERIAL_REQUESTS = 'requests/admin/APPEND_MATERIAL_REQUESTS';
export const ADMIN_RECEIVE_MATERIAL_REQUEST = 'requests/admin/RECEIVE_MATERIAL_REQUEST';
......@@ -4,7 +4,7 @@ import { IReducerAction } from 'model/common.model';
import MaterialRequest from 'model/MaterialRequest';
import FilteredPage from 'model/FilteredPage';
import {APPEND_MATERIAL_REQUESTS, RECEIVE_MATERIAL_REQUEST, RECEIVE_MATERIAL_REQUESTS} from 'constants/requests';
import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RECEIVE_MATERIAL_REQUESTS} from 'requests/constants';
const INITIAL_STATE: {
request: Request;
......@@ -18,11 +18,11 @@ const INITIAL_STATE: {
pagedError: null,
};
function requests(state = INITIAL_STATE, action: IReducerAction) {
function adminRequests(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
case RECEIVE_MATERIAL_REQUEST: {
case ADMIN_RECEIVE_MATERIAL_REQUEST: {
const { request, error } = action.payload;
const receivedIndex = state.paged ? state.paged.content.findIndex((item) => item.uuid === request.uuid) : -1;
......@@ -45,7 +45,7 @@ function requests(state = INITIAL_STATE, action: IReducerAction) {
}
}
case RECEIVE_MATERIAL_REQUESTS: {
case ADMIN_RECEIVE_MATERIAL_REQUESTS: {
const { paged, error } = action.payload;
return update(state, {
paged: { $set: paged },
......@@ -53,7 +53,7 @@ function requests(state = INITIAL_STATE, action: IReducerAction) {
});
}
case APPEND_MATERIAL_REQUESTS: {
case ADMIN_APPEND_MATERIAL_REQUESTS: {
const {paged, error} = action.payload;
return !state.paged ? update(state, {
......@@ -74,4 +74,4 @@ function requests(state = INITIAL_STATE, action: IReducerAction) {
}
}
export default requests;
export default adminRequests;
import { combineReducers } from 'redux';
import admin from './admin';
const rootReducer = combineReducers({
admin,
});
export default rootReducer;
import RequestBrowsePage from 'requests/ui/admin/BrowsePage';
import RequestDisplayPage from 'requests/ui/admin/DisplayPage';
const adminRoutes = [
{
path: '/requests',
component: RequestBrowsePage,
exact: true,
extraProps: {
title: 'Requests',
},
},
{
path: '/requests/:uuid',
component: RequestDisplayPage,
exact: true,
extraProps: {
title: 'Request info',
},
},
];
export {adminRoutes as requestsAdminRoutes};
......@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
// Actions
import {listMaterialRequests} from 'actions/requests';
import {listMaterialRequests} from 'requests/actions/admin';
// Models
import MaterialRequest from 'model/MaterialRequest';
......@@ -51,7 +51,7 @@ class BrowsePage extends BrowsePageTemplate<any> {
}
const mapStateToProps = (state) => ({
paged: state.requests.paged || undefined,
paged: state.requests.admin.paged || undefined,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
......@@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux';
import {translate} from 'react-i18next';
// Actions
import {loadMaterialRequest, sendValidationEmailAction, recheckPidAction, validateRequestAction} from 'actions/requests';
import {loadMaterialRequest, sendValidationEmailAction, recheckPidAction, validateRequestAction} from 'requests/actions/admin';
// Models
import MaterialRequest from 'model/MaterialRequest';
......@@ -127,7 +127,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
request: state.requests.request,
request: state.requests.admin.request,
requestId: ownProps.match.params.uuid,
});
......
// Actions
import {listMine as listMySubsets, get} from 'service/genesys/actions/subsetService';
// Constants
import {DASHBOARD_APPEND_SUBSETS, DASHBOARD_RECEIVE_SUBSET, DASHBOARD_RECEIVE_SUBSETS, DASHBOARD_REMOVE_SUBSET} from 'subsets/constants';
// Model
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import Subset from 'model/Subset';
const receiveSubsets = (paged: FilteredPage<Subset>, error = null) => ({
type: DASHBOARD_RECEIVE_SUBSETS,
payload: { paged, error },
});
const appendSubsets = (paged: FilteredPage<Subset>, error = null) => ({
type: DASHBOARD_APPEND_SUBSETS,
payload: { paged, error },
});
export const receiveSubset = (subset: Subset, error = null) => ({
type: DASHBOARD_RECEIVE_SUBSET,
payload: { subset, error },
});
export const removeSubset = (subset: Subset) => ({
type: DASHBOARD_REMOVE_SUBSET,
payload: { subset },
});
export const createSubset = () => (dispatch) => {
dispatch(receiveSubset(new Subset()));
};
export const loadSubset = (uuid: string) => (dispatch) => {
return dispatch(get(uuid))
.then((subset) => {
dispatch(receiveSubset(subset));
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveSubset(null, error));
});
};
export const loadMySubsets = (page: IPageRequest) => (dispatch, getState) => {
return dispatch(listMySubsets('', page))
.then((paged) => {
if (paged.number === 0) {
dispatch(receiveSubsets(paged));
} else {
dispatch(appendSubsets(paged));
}
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveSubsets(null, error));
});
};
// Actions
import navigateTo from 'actions/navigation';
import {addAccessions, create, remove, update, updatePublishState} from 'service/genesys/actions/subsetService';
import {toUUIDPromise} from 'accessions/actions/public'; // TODO
import {receiveSubset, removeSubset} from './dashboard';
// Constants
import {ADD_CREATOR_TO_SUBSET, REMOVE_CREATOR_FROM_SUBSET, UPDATE_SUBSET_CREATOR} from 'subsets/constants';
// Model
import Creator from 'model/Creator';
import Subset from 'model/Subset';
import {PublishState} from 'model/common.model';
import {AccessionIdentifier} from 'model/dataset.model';
// Service
import SubsetService from 'service/genesys/SubsetService';
// UI
import steps from 'subsets/ui/dashboard/subset-stepper/steps';
// Accession Identifiers step
export const updateSubsetAccessionIdentifiers = (subset: Subset, accessionIdentifiers: AccessionIdentifier[]) => (dispatch) => {
dispatch(toUUIDPromise(accessionIdentifiers))
.then((accessionIdentifiers) => {
dispatch(addAccessions(subset.uuid, subset.version, Object.keys(accessionIdentifiers)))
.then((subset) => {
dispatch(receiveSubset(subset));
});
});
};
// Review step
export const publishSubset = (subset: Subset) => (dispatch) => {
return dispatch(updatePublishState(subset, PublishState.REVIEWING))
.then((subset) => {
dispatch(receiveSubset(subset));
});
};
export const unpublishSubset = (subset: Subset) => (dispatch) => {
return dispatch(updatePublishState(subset, PublishState.DRAFT))
.then((subset) => {
dispatch(receiveSubset(subset));
});
};
export const approveSubset = (subset: Subset) => (dispatch) => {
return dispatch(updatePublishState(subset, PublishState.PUBLISHED))
.then((subset) => {
dispatch(receiveSubset(subset));
});
};
export const deleteSubset = (subset: Subset) => (dispatch) => {
return dispatch(remove(subset.uuid, subset.version))
.then((subset) => {
dispatch(removeSubset(subset));
});
};
// Creators step
const addCreatorToSubset = (creator: Creator) => ({
type: ADD_CREATOR_TO_SUBSET,
payload: { creator },
});
const updateCreator = (creator: Creator) => ({
type: UPDATE_SUBSET_CREATOR,
payload : { creator },
});
const removeCreator = (creator: Creator) => ({
type: REMOVE_CREATOR_FROM_SUBSET,
payload : { creator },
});
export const createSubsetCreator = () => (dispatch, getState) => {
const currentSubset = getState().subsets.dashboard.subset;
return SubsetService.createCreator(getState().login.access_token, currentSubset.uuid)
.then((obj) => {
dispatch(addCreatorToSubset(obj));
}).catch((error) => {
console.log('Create creator error', error);
});
};
export const updateSubsetCreatorRequest = (creator: Creator) => (dispatch, getState) => {
const currentSubset = getState().subsets.dashboard.subset;
const token = getState().login.access_token;
return SubsetService.updateCreator(token, currentSubset.uuid, creator)
.then((obj) => {
dispatch(updateCreator(obj));
}).catch((error) => {
console.log('Update creator error', error);
});
};
export const deleteSubsetCreatorRequest = (creator: Creator) => (dispatch, getState) => {
const token = getState().login.access_token;
const currentSubset = getState().subsets.dashboard.subset;
return SubsetService.deleteCreator(token, currentSubset.uuid, creator)
.then((obj) => {
dispatch(removeCreator(obj));
}).catch((error) => {
console.log('Delete creator error', error);
});
};
// Common
const gotoNextStep = (subset: Subset) => {
return (dispatch, getState) => {
const link = window.location.pathname.split('/').pop();
const stepId = steps.find((e) => e.path.endsWith(link)).id;
const path = steps.find((e) => e.id === (stepId + 1)).path;
dispatch(navigateTo(`/dashboard/subsets/${subset.uuid}/${path}`));
};
};
export const remoteSubmit = (values: Subset, dispatch) => {
dispatch(saveSubset(values));
};
export const saveSubset = (subset: Subset) => (dispatch) => {
if (! subset.uuid) {
subset.publisher = subset.wiewsCode;
return dispatch(create(subset))
.then((subset) => {
dispatch(receiveSubset(subset));
dispatch(gotoNextStep(subset));
});
}
return dispatch(update(subset))
.then((subset) => dispatch(receiveSubset(subset)));
};
......@@ -2,20 +2,17 @@
* This is a top-level group for actions in /subsets/* routes.
*/
// Actions
import navigateTo from 'actions/navigation';
import {list as listSubsets, listMine as listMySubsets, get, update, addAccessions, remove, create, updatePublishState} from 'actions/genesys/subsetService';
import {toUUIDPromise} from 'actions/accessions';
import {list as listSubsets, listMine as listMySubsets, get} from 'service/genesys/actions/subsetService';
// Constants
import {RECEIVE_SUBSETS, RECEIVE_SUBSET, APPEND_SUBSETS} from 'subsets/constants';
// Model
import FilteredPage, { IPageRequest } from 'model/FilteredPage';
import Subset from 'model/Subset';
import SubsetFilter from 'model/SubsetFilter';
import {AccessionIdentifier} from 'model/dataset.model';
import {PublishState} from 'model/common.model';
import Creator from 'model/Creator';
import steps from 'ui/pages/dashboard/subsets/subset-stepper/steps';
import {RECEIVE_SUBSETS, RECEIVE_SUBSET, APPEND_SUBSETS, REMOVE_SUBSET, REMOVE_CREATOR_FROM_SUBSET, UPDATE_SUBSET_CREATOR, ADD_CREATOR_TO_SUBSET} from 'constants/subsets';
import SubsetService from 'service/genesys/SubsetService';
const receiveSubsets = (paged: FilteredPage<Subset>, error = null) => ({
type: RECEIVE_SUBSETS,
......@@ -34,12 +31,7 @@ const receiveSubset = (subset: Subset, error = null) => ({
export { listSubsets as listSubsetsPromise, listMySubsets as listMySubsetsPromise };
const removeSubset = (subset) => (dispatch) => {
dispatch({
type: REMOVE_SUBSET,
payload: { subset },
});
};
export const updateRoute = (paged: FilteredPage<Subset>) => (dispatch) => {
const qs = {
......@@ -62,7 +54,7 @@ export const applyFilters = (filters: string | SubsetFilter, page: IPageRequest
};
export const loadSubsetsPage = (page: IPageRequest) => (dispatch, getState) => {
const filterCode = getState().subsets.paged.filterCode;
const filterCode = getState().subsets.public.paged.filterCode;
return dispatch(listSubsets(filterCode, page))
.then((paged) => {
if (paged.number === 0) {
......@@ -77,16 +69,6 @@ export const loadSubsetsPage = (page: IPageRequest) => (dispatch, getState) => {
});
};
export const loadMySubsets = (page: IPageRequest) => (dispatch, getState) => {
return dispatch(listMySubsets('', page))
.then((paged) => {
dispatch(receiveSubsets(paged));
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveSubsets(null, error));
});
};
export const loadSubset = (uuid: string) => (dispatch) => {
return dispatch(get(uuid))
.then((subset) => {
......@@ -97,116 +79,4 @@ export const loadSubset = (uuid: string) => (dispatch) => {
});
};
export const createSubset = () => (dispatch) => {
dispatch(receiveSubset(new Subset()));
};
export const saveSubset = (subset: Subset) => (dispatch) => {
if (! subset.uuid) {
subset.publisher = subset.wiewsCode;
return dispatch(create(subset))
.then((subset) => {
dispatch(receiveSubset(subset));
dispatch(gotoNextStep