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 {loginAppRequest} from 'actions/login';
import {checkTokenRequest} from 'user/actions/root';
import {checkTokenRequest} from 'user/actions/public';
function checkAuthTokenRequest(req, dispatch) {
const token = req.cookies.access_token;
......
......@@ -8,8 +8,8 @@ import AccessionFilter from 'model/AccessionFilter';
import AccessionDetails from 'model/AccessionDetails';
import AccessionMapInfo from 'model/AccessionMapInfo';
import {list as listAccessions, getDetailsByUuid, getDetailsByDoi, listOverview as listAccessionOverview, toUUID, mapInfo} from 'actions/genesys/accessionService';
import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO} from 'constants/accessions';
import {list as listAccessions, getDetailsByUuid, getDetailsByDoi, listOverview as listAccessionOverview, toUUID, mapInfo} from 'service/genesys/actions/accessionService';
import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO} from 'accessions/constants';
const receiveAccessions = (paged: FilteredPage<Accession>, error = null) => ({
type: RECEIVE_ACCESSIONS,
......@@ -97,7 +97,7 @@ export const loadAccessionsMapInfo = (filters: string | AccessionFilter) => (dis
};
export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) => {
const filterCode = getState().accessions.paged.filterCode;
const filterCode = getState().accessions.public.paged.filterCode;
return dispatch(listAccessions(filterCode, page))
.then((paged) => {
if (paged.number === 0) {
......
import { combineReducers } from 'redux';
import publicAccessions from './public';
const rootReducer = combineReducers({
public: publicAccessions,
});
export default rootReducer;
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO} from 'constants/accessions';
import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO} from 'accessions/constants';
import FilteredPage from 'model/FilteredPage';
import Accession from 'model/Accession';
......@@ -24,7 +24,7 @@ const INITIAL_STATE: {
mapInfo: null,
};
function accessions(state = INITIAL_STATE, action: IReducerAction) {
function publicAccessions(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
......@@ -102,4 +102,4 @@ function accessions(state = INITIAL_STATE, action: IReducerAction) {
}
}
export default accessions;
export default publicAccessions;
import AccessionBrowsePage from 'accessions/ui/BrowsePage';
import MapBrowsePage from 'accessions/ui/MapPage';
import AccessionDisplayPage from 'accessions/ui/DisplayPage';
import AccessionOverviewPage from 'accessions/ui/OverviewPage';
const publicRoutes = [
{
path: '/a/:filterCode(v.+)?',
component: AccessionBrowsePage,
exact: true,
},
{
path: '/a/overview/:filterCode(v.+)?',
component: AccessionOverviewPage,
exact: true,
},
{
path: '/a/map/:filterCode(v.+)?',
component: MapBrowsePage,
exact: true,
},
{
path: '/a/:uuid([a-z\\-0-9]+)',
component: AccessionDisplayPage,
exact: true,
},
{
// We need to take out the '10.' prefix for matching to work
path: '/10.:doi(\\d+\/.+)',
component: AccessionDisplayPage,
exact: true,
},
];
export {publicRoutes as accessionPublicRoutes};
......@@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux';
import { parse } from 'query-string';
// Actions
import { applyFilters, loadAccessionsPage, updateRoute } from 'actions/accessions';
import { applyFilters, loadAccessionsPage, updateRoute } from 'accessions/actions/public';
// Models
import Accession from 'model/Accession';
......@@ -95,7 +95,7 @@ class BrowsePage extends BrowsePageTemplate<Accession> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.accessions.paged || undefined,
paged: state.accessions.public.paged || undefined,
filterCode: ownProps.match.params.filterCode,
currentTab: ownProps.match.params.tab || 'data', // current tab, or ownProps.location.pathname
});
......
......@@ -4,8 +4,8 @@ import {bindActionCreators} from 'redux';
import { translate } from 'react-i18next';
// Actions
import { loadAccession } from 'actions/accessions';
import {addAccessionToMyList, removeAccessionFromMyList} from 'user/actions/root';
import { loadAccession } from 'accessions/actions/public';
import {addAccessionToMyList, removeAccessionFromMyList} from 'user/actions/public';
// Models
import AccessionDetails from 'model/AccessionDetails';
......@@ -267,11 +267,11 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
accession: state.accessions.accession,
error: state.accessions.accessionError,
accession: state.accessions.public.accession,
error: state.accessions.public.accessionError,
uuid: ownProps.match.params.uuid,
doi: ownProps.match.params.doi,
accessions: state.user.root.myList.accessions,
accessions: state.user.public.myList.accessions,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
......@@ -2,7 +2,7 @@ import * as React from 'react';
import {connect} from 'react-redux';
import {withStyles} from '@material-ui/core/styles';
import {bindActionCreators} from 'redux';
import { loadAccessionsMapInfo } from 'actions/accessions';
import { loadAccessionsMapInfo } from 'accessions/actions/public';
import AccessionFilter from 'model/AccessionFilter';
import Loading from 'ui/common/Loading';
import AccessionMapInfo from 'model/AccessionMapInfo';
......@@ -129,7 +129,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
mapInfo: state.accessions.mapInfo || undefined,
mapInfo: state.accessions.public.mapInfo || undefined,
filterCode: ownProps.match.params.filterCode || '',
currentTab: ownProps.match.params.tab || 'map', // current tab, or ownProps.location.pathname
});
......
......@@ -6,7 +6,7 @@ import { translate } from 'react-i18next';
import * as _ from 'lodash';
// Actions
import {applyFilters, loadAccessionsPage, listAccessionsPromise, updateRoute, applyOverviewFilters, loadAccessionsOverviewPage} from 'actions/accessions';
import {applyFilters, loadAccessionsPage, listAccessionsPromise, updateRoute, applyOverviewFilters, loadAccessionsOverviewPage} from 'accessions/actions/public';
import { showSnackbar } from 'actions/snackbar';
// Models
......@@ -211,8 +211,8 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
paged: state.accessions.paged || undefined,
overview: state.accessions.overview,
paged: state.accessions.public.paged || undefined,
overview: state.accessions.public.overview,
filterCode: ownProps.match.params.filterCode,
currentTab: ownProps.match.params.tab || 'overview', // current tab, or ownProps.location.pathname
});
......
import * as React from 'react';
import { reduxForm } from 'redux-form';
import { ACCESSION_FILTERFORM } from 'constants/accessions';
import { ACCESSION_FILTERFORM } from 'accessions/constants';
import FiltersBlock from 'ui/common/filter/FiltersBlock';
import CollapsibleComponentSearch from 'ui/common/filter/CollapsibleComponentSearch';
......@@ -10,7 +10,7 @@ import NumberFilter from 'ui/common/filter/NumberFilter';
import StringFilter from 'ui/common/filter/StringFilter';
import StringArrFilter from 'ui/common/filter/StringArrFilter';
import Accession from 'model/Accession';
import DateFilter from '../../../common/filter/DateFilter';
import DateFilter from 'ui/common/filter/DateFilter';
const AccessionFilters = ({handleSubmit, initialValues, initialize, ...other}) => {
// console.log('AccessionFilters', initialValues);
......
......@@ -4,7 +4,7 @@ import * as cookies from 'es-cookie';
import { clearCookies, saveCookies } from 'utilities';
import { ROLE_CLIENT } from 'constants/userRoles';
import {log} from 'utilities/debug';
import {loginUser} from 'user/actions/root';
import {loginUser} from 'user/actions/public';
export function checkAccessTokens(dispatch) {
const cookieToken: string = typeof window !== 'undefined' && cookies.get('access_token');
......
import * as _ from 'lodash';
import {getRequest, listRequests, sendValidationEmail, recheckPid, validateRequest} from 'actions/genesys/requestService';
// constants
import {APPEND_MATERIAL_REQUESTS, RECEIVE_MATERIAL_REQUEST, RECEIVE_MATERIAL_REQUESTS} from 'constants/requests';
// models
import MaterialRequest from 'model/MaterialRequest';
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
const receiveRequests = (paged: FilteredPage<MaterialRequest>, error = null) => ({
type: RECEIVE_MATERIAL_REQUESTS,
payload: { paged, error },
});
const appendRequests = (paged: FilteredPage<MaterialRequest>, error = null) => ({
type: APPEND_MATERIAL_REQUESTS,
payload: { paged, error },
});
const receiveRequest = (request: MaterialRequest, error = null) => ({
type: RECEIVE_MATERIAL_REQUEST,
payload: { request, error },
});
const refreshRequestPID = (request: MaterialRequest) => (dispatch, getState) => {
const page = getState().requests.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));
}
};
const refreshRequest = (request: MaterialRequest) => (dispatch, getState) => {
const page = getState().requests.paged;
if (page) {
const toUpdateIndex = _.findIndex(page.content, (contentItem) => contentItem.uuid === request.uuid);
if (toUpdateIndex !== -1) {
page.content[toUpdateIndex] = request;
}
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));
dispatch(refreshRequest(request));
})
.catch((error) => {
dispatch(receiveRequest(null, error));
});
};
export const sendValidationEmailAction = (uuid: string) => (dispatch) => {
return dispatch(sendValidationEmail(uuid))
.then((request) => {
dispatch(receiveRequest(request));
dispatch(refreshRequest(request));
})
.catch((error) => {
dispatch(receiveRequest(null, error));
});
};
// Actions
import {get, list as listInstitutes} from 'service/genesys/actions/instituteService';
// Constants
import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECEIVE_INSTITUTES} from 'institutes/constants';
// Model
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import FaoInstitute from 'model/FaoInstitute';
const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: DASHBOARD_RECEIVE_INSTITUTES,
payload: { paged, error },
});
const appendInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: DASHBOARD_APPEND_INSTITUTES,
payload: { paged, error },
});
const receiveInstitute = (institute: FaoInstitute, error = null) => ({
type: DASHBOARD_RECEIVE_INSTITUTE,
payload: { institute, error },
});
export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) => {
const filterCode = getState().institutes.paged.filterCode;
return dispatch(listInstitutes(filterCode, page))
.then((paged) => {
if (paged.number === 0) {
dispatch(receiveInstitutes(paged));
} else {
dispatch(appendInstitutes(paged));
}
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveInstitutes(null, error));
});
};
export const loadInstitute = (code: string) => (dispatch) => {
return dispatch(get(code))
.then((institute) => {
dispatch(receiveInstitute(institute));
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveInstitute(null, error));
});
};
import { list as listInstitutes, get } from 'actions/genesys/instituteService';
import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'constants/institutes';
import { list as listInstitutes, get } from 'service/genesys/actions/instituteService';
import navigateTo from 'actions/navigation';
import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institutes/constants';
import FaoInstitute from 'model/FaoInstitute';
import FaoInstituteFilter from 'model/FaoInstituteFilter';
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import navigateTo from './navigation';
const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: RECEIVE_INSTITUTES,
payload: { paged, error },
......
......@@ -2,4 +2,8 @@ export const RECEIVE_INSTITUTES = 'institutes/RECEIVE_INSTITUTES';
export const APPEND_INSTITUTES = 'institutes/APPEND_INSTITUTES';
export const RECEIVE_INSTITUTE = 'institutes/RECEIVE_INSTITUTE';
export const DASHBOARD_RECEIVE_INSTITUTES = 'institutes/dashboard/RECEIVE_INSTITUTES';
export const DASHBOARD_APPEND_INSTITUTES = 'institutes/dashboard/APPEND_INSTITUTES';
export const DASHBOARD_RECEIVE_INSTITUTE = 'institutes/dashboard/RECEIVE_INSTITUTE';
export const INSTITUTE_FILTERFORM = 'Form/institutes/INSTITUTE_FILTERFORM';
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import FilteredPage from 'model/FilteredPage';
import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECEIVE_INSTITUTES} from 'institutes/constants';
import FaoInstitute from 'model/FaoInstitute';
const INITIAL_STATE: {
institute: FaoInstitute;
instituteError: any;
paged: FilteredPage<FaoInstitute>;
pagedError: any;
} = {
institute: null,
instituteError: null,
paged: null,
pagedError: null,
};
function dashboardInstitutes(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
case DASHBOARD_RECEIVE_INSTITUTE: {
const { institute, error } = action.payload;
const receivedIndex = state.paged ? state.paged.content.findIndex((item) => item.code === institute.code) : -1;
if (receivedIndex !== -1) {
return update(state, {
institute: { $set: institute },
paged: {
content: {
[receivedIndex]: {$set: institute},
},
},
instituteError: {$set: error},
});
} else {
return update(state, {
institute: { $set: institute},
paged: {$set: null},
instituteError: {$set: error},
});
}
}
case DASHBOARD_RECEIVE_INSTITUTES: {
const { paged, error } = action.payload;
return update(state, {
paged: { $set: paged },
pagedError: { $set: error },
});
}
case DASHBOARD_APPEND_INSTITUTES: {
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},
});
}
default:
return state;
}
}
export default dashboardInstitutes;
import { combineReducers } from 'redux';
import dashboard from './dashboard';
import publicInstitutes from './public';
const rootReducer = combineReducers({
dashboard,
public: publicInstitutes,
});
export default rootReducer;
......@@ -3,7 +3,7 @@ import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import FilteredPage from 'model/FilteredPage';
import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'constants/institutes';
import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institutes/constants';
import FaoInstitute from 'model/FaoInstitute';
const INITIAL_STATE: {
......@@ -18,7 +18,7 @@ const INITIAL_STATE: {
pagedError: null,
};
function institutes(state = INITIAL_STATE, action: IReducerAction) {
function publicInstitutes(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
......@@ -75,4 +75,4 @@ function institutes(state = INITIAL_STATE, action: IReducerAction) {
}
}
export default institutes;
export default publicInstitutes;
Markdown is supported
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