Commit 5637e7a0 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Subsets display: 100+ accessions

accessions state divided into public and dashboard, so now no conflicts for subset accessions

fixed AccessionService use

added usage of AccessionRef, changes related to model move
parent fb55871c
// Constants
import {DASHBOARD_APPEND_ACCESSIONS, DASHBOARD_RECEIVE_ACCESSIONS} from 'accessions/constants';
// Model
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import Accession from 'model/accession/Accession';
import AccessionFilter from 'model/accession/AccessionFilter';
// Service
import AccessionService from 'service/genesys/AccessionService';
const receiveAccessions = (paged: FilteredPage<Accession>, error = null) => ({
type: DASHBOARD_RECEIVE_ACCESSIONS,
payload: { paged, error },
});
const appendAccessions = (paged: FilteredPage<Accession>, error = null) => ({
type: DASHBOARD_APPEND_ACCESSIONS,
payload: { paged, error },
});
// Load accession page without redirect
export const loadAccessionsPageAction = (page: IPageRequest, filterCode: string | AccessionFilter) => (dispatch, getState) => {
return AccessionService.list(filterCode, page)
.then((paged) => {
if (paged.number === 0) {
dispatch(receiveAccessions(paged));
} else {
dispatch(appendAccessions(paged));
}
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveAccessions(null, error.response));
});
};
......@@ -119,6 +119,20 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) =
dispatch(receiveAccessions(null, error));
});
};
// Load accession page without redirect
export const loadAccessionsPageAction = (page: IPageRequest, filterCode: string | AccessionFilter) => (dispatch, getState) => {
return AccessionService.list(filterCode, page)
.then((paged) => {
if (paged.number === 0) {
dispatch(receiveAccessions(paged));
} else {
dispatch(appendAccessions(paged));
}
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveAccessions(null, error.response));
});
};
export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) => (dispatch) => {
const loader = doi ? AccessionService.getDetailsByDoi : AccessionService.getDetailsByUuid;
......
......@@ -5,3 +5,8 @@ export const RECEIVE_ACCESSION = 'accessions/RECEIVE_ACCESSION';
export const RECEIVE_ACCESSION_MAPINFO = 'accessions/RECEIVE_ACCESSION_MAPINFO';
export const ACCESSION_FILTERFORM = 'Form/Accession/ACCESSION_FILTERFORM';
export const ACCESSION_FORM = 'Form/Accession/ACCESSION_FORM';
// Dashboard
export const DASHBOARD_RECEIVE_ACCESSIONS = 'accessions/dashboard/RECEIVE_ACCESSIONS';
export const DASHBOARD_APPEND_ACCESSIONS = 'accessions/dashboard/APPEND_ACCESSIONS';
export const DASHBOARD_RECEIVE_ACCESSION = 'accessions/dashboard/RECEIVE_ACCESSION';
import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import {DASHBOARD_RECEIVE_ACCESSIONS, DASHBOARD_RECEIVE_ACCESSION, DASHBOARD_APPEND_ACCESSIONS} from 'accessions/constants';
import FilteredPage from 'model/FilteredPage';
import Accession from 'model/accession/Accession';
const INITIAL_STATE: {
accession: Accession;
accessionError: any;
paged: FilteredPage<Accession>;
pagedError: any;
} = {
accession: null,
accessionError: null,
paged: null,
pagedError: null,
};
function dashboardAccessions(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
case DASHBOARD_RECEIVE_ACCESSION: {
const {accession, error} = action.payload;
const receivedIndex = state.paged ? state.paged.content.findIndex((item) => item.uuid === accession.uuid) : -1;
if (receivedIndex !== -1) {
return update(state, {
accession: { $set: accession },
paged: {
content: {
[receivedIndex]: {$set: accession},
},
},
accessionError: {$set: error},
});
} else {
return update(state, {
accession: { $set: accession},
paged: {$set: null},
accessionError: {$set: error},
});
}
}
case DASHBOARD_RECEIVE_ACCESSIONS: {
const { paged, error } = action.payload;
return update(state, {
paged: { $set: paged },
pagedError: { $set: error },
overview: {$set: null},
mapInfo: { $set: null },
});
}
case DASHBOARD_APPEND_ACCESSIONS: {
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 dashboardAccessions;
import { combineReducers } from 'redux';
import dashboard from './dashboard';
import publicAccessions from './public';
const rootReducer = combineReducers({
dashboard,
public: publicAccessions,
});
......
import { EmptyModel } from 'model/common.model';
import Accession from 'model/accession/Accession';
export class AccessionRef extends EmptyModel {
public doi: string;
......@@ -6,6 +7,7 @@ export class AccessionRef extends EmptyModel {
public acceNumb: string;
public genus: string;
public species: string;
public accession: Accession;
public constructor(obj?) {
super(obj);
......
......@@ -6,10 +6,11 @@ import {PublishState} from 'model/common.model';
import SubsetCreator from 'model/subset/SubsetCreator';
import FaoInstitute from 'model/genesys/FaoInstitute';
import Crop from 'model/genesys/Crop';
import {AccessionRef} from 'model/accession/AccessionRef';
class Subset {
public accessionCount: number;
public accessionRefs: string[];
public accessionRefs: AccessionRef[];
public active: boolean;
public creators: SubsetCreator[];
public createdBy: number;
......
......@@ -4,15 +4,10 @@ import {bindActionCreators} from 'redux';
// Actions
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/Subset';
import Accession from 'model/accession/Accession';
import Page from 'model/Page';
import {PublishState} from 'model/common.model';
import AccessionFilter from 'model/accession/AccessionFilter';
import {IPageRequest} from 'model/FilteredPage';
// UI
import PageLayout, { PageContents } from 'ui/layout/PageLayout';
import Loading from 'ui/common/Loading';
......@@ -28,7 +23,6 @@ interface IBrowsePageProps extends React.ClassAttributes<any> {
loadSubset: any;
navigateTo: any;
unpublishSubset: (subset: Subset) => void;
listAccessions: (filter: string | AccessionFilter, page: IPageRequest) => Promise<Page<Accession>>;
}
class BrowsePage extends React.Component<IBrowsePageProps, any> {
......@@ -59,7 +53,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
}
public render() {
const { error, subset, uuid, listAccessions, userRole } = this.props;
const { error, subset, uuid, userRole } = this.props;
const stillLoading: boolean = ! error && (! subset || (uuid && subset && subset.uuid !== uuid));
const isActionsActive: boolean = userRole.findIndex((role) => role === 'ROLE_ADMINISTRATOR') !== -1 || (subset && subset.state === PublishState.REVIEWING);
......@@ -72,7 +66,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
{ stillLoading ? <Loading /> :
<div>
{ error && <div>{ JSON.stringify(error) }</div> }
{ subset && <SubsetDisplay isActionsActive={ isActionsActive } subset={ subset } listAccessions={ listAccessions }/> }
{ subset && <SubsetDisplay isActionsActive={ isActionsActive } subset={ subset }/> }
</div>
}
</PageContents>
......@@ -92,7 +86,6 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
loadSubset,
navigateTo,
unpublishSubset,
listAccessions: listAccessionsPromise,
}, dispatch);
......
......@@ -35,40 +35,8 @@ interface IDetailInfoProps extends React.ClassAttributes<any> {
class DetailInfo extends React.Component<IDetailInfoProps, any> {
public state = {
subsetAccessions: [],
};
private loadAccessions = (accessionRefs) => {
const {listAccessions} = this.props;
const filter = new AccessionFilter();
filter.uuid = accessionRefs.map((ref) => ref.accession.uuid);
listAccessions(filter, {page: 0, size: accessionRefs.length, direction: 'ASC'})
.then((accessionPage) => this.setState({subsetAccessions: accessionPage.content}));
}
public componentWillMount() {
const {subset} = this.props;
if (subset && subset.accessionRefs && subset.accessionRefs.length > 0) {
this.loadAccessions(subset.accessionRefs);
}
}
public componentWillReceiveProps(nextProps) {
const {subset} = nextProps;
const {subsetAccessions} = this.state;
if (subset && subset.accessionRefs && subset.accessionRefs.length > 0 && (!subsetAccessions || subsetAccessions.length === 0 || subsetAccessions.length !== subset.accessionRefs.length)) {
this.loadAccessions(subset.accessionRefs);
}
}
public render() {
const {classes, subset, t} = this.props;
const {subsetAccessions} = this.state;
if (!subset) {
log('Waiting for subset.');
......@@ -91,10 +59,12 @@ class DetailInfo extends React.Component<IDetailInfoProps, any> {
}
/>
}
{ subsetAccessions && subsetAccessions.map((accession, index: number) =>
<Grid key={ accession.uuid } item xs={ 12 } className={ classes.accessionCard }>
<AccessionCard index={ index } accession={ accession }/>
</Grid>) }
{ subset.accessionRefs && subset.accessionRefs.map((accessionRef, index: number) => (
accessionRef.accession &&
<Grid key={ accessionRef.accession.uuid } item xs={ 12 } className={ classes.accessionCard }>
<AccessionCard index={ index } accession={ accessionRef.accession }/>
</Grid>
)) }
</Grid>
</div>
);
......
......@@ -43,33 +43,6 @@ const styleSheet = {
class ListOfAccession extends React.Component<IListOfAccession, any> {
private loadAccessions = (accessionRefs) => {
const {listAccessions} = this.props;
const filter = new AccessionFilter();
filter.uuid = accessionRefs.map((ref) => ref.accession.uuid);
listAccessions(filter, {page: 0, size: accessionRefs.length, direction: 'ASC'})
.then((accessionPage) => this.setState({subsetAccessions: accessionPage.content}));
}
public componentWillMount() {
const {subset} = this.props;
const {subsetAccessions} = this.state;
if (subset && subset.accessionRefs && subset.accessionRefs.length > 0 && (!subsetAccessions || subsetAccessions.length === 0)) {
this.loadAccessions(subset.accessionRefs);
}
}
public componentWillReceiveProps(nextProps) {
const {subset} = nextProps;
const {subsetAccessions} = this.state;
if (subset && subset.accessionRefs && subset.accessionRefs.length > 0 && (!subsetAccessions || subsetAccessions.length === 0 || subsetAccessions.length !== subset.accessionRefs.length)) {
this.loadAccessions(subset.accessionRefs);
}
}
public dataPasted = (e) => {
e.preventDefault();
......@@ -88,7 +61,6 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
super(props);
this.state = {
subsetAccessions: [],
csvConfig: {
separator: '\t',
escape: '\\',
......@@ -100,8 +72,7 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
public render() {
const {classes} = this.props;
const { subsetAccessions } = this.state;
const {classes, subset} = this.props;
return (
<div className={ `${ classes.root } m-20 p-20 even-row` }>
......@@ -127,9 +98,16 @@ class ListOfAccession extends React.Component<IListOfAccession, any> {
</div>
<h3>Accession list: { subsetAccessions ? subsetAccessions.length : 0 } rows</h3>
{ subsetAccessions &&
<AccessionRefsTable AccessionRefs={ subsetAccessions.map((accession) => ({doi: accession.doi, instCode: accession.institute.code, acceNumb: accession.accessionNumber, genus: accession.taxonomy.genus})) }/>
<h3>Accession list: { subset.accessionRefs ? subset.accessionRefs.length : 0 } rows</h3>
{ subset.accessionRefs &&
<AccessionRefsTable AccessionRefs={ subset.accessionRefs.map((accessionRef) => (
{
doi: accessionRef.accession.doi,
instCode: accessionRef.accession.institute.code,
acceNumb: accessionRef.accession.accessionNumber,
genus: accessionRef.accession.taxonomy.genus,
}
)) }/>
}
</div>
);
......
import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
// actions
import {listAccessionsPromise} from 'accessions/actions/public';
// ui
import SubsetDisplay from 'subsets/ui/c/SubsetDisplay';
......@@ -12,17 +10,13 @@ class ReviewAndPublishStep extends StepperTemplate<any> {
protected renderContent = () => (
<SubsetDisplay
subset={ this.props.item }
listAccessions={ this.props.listAccessions }
subsetAccessions={ this.props.accessionsPage && this.props.accessionsPage.content }
/>
)
}
const mapStateToProps = (state, ownProps) => ({
accessionsPage: state.accessions.public.paged,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
listAccessions: listAccessionsPromise,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(ReviewAndPublishStep);
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