Commit 79336076 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Server 331 accession apiv1 wrap overview response

parent 78758833
......@@ -56,7 +56,6 @@ export const applyFilters = (filters: string | AccessionFilter, page: IPageReque
return dispatch(listAccessions(filters, page))
.then((paged) => {
dispatch(receiveAccessions(paged));
dispatch(overviewAccessions(paged.filterCode));
dispatch(updateRoute(paged));
}).catch((error) => {
console.log(`API error`, error);
......@@ -66,14 +65,13 @@ export const applyFilters = (filters: string | AccessionFilter, page: IPageReque
export const applyOverviewFilters = (filters: string | AccessionFilter, page: IPageRequest = { page: 0 }) => (dispatch) => {
console.log('Applying new filter', filters);
return dispatch(listAccessions(filters, page))
.then((paged) => {
dispatch(receiveAccessions(paged));
dispatch(overviewAccessions(paged.filterCode));
dispatch(updateRoute(paged, '/a/overview'));
return dispatch(listAccessionOverview(filters))
.then((overview) => {
dispatch(receiveAccessionOverview(overview));
dispatch(updateRoute2(overview.filterCode, '/a/overview'));
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveAccessions(null, error.response));
dispatch(receiveAccessionOverview(null, error.response));
});
};
......@@ -133,6 +131,6 @@ export const overviewAccessions = (filterCode: string) => (dispatch) => {
dispatch(receiveAccessionOverview(overview));
}).catch((error) => {
console.log(`API error`, error);
dispatch(receiveAccession(null, error.response));
dispatch(receiveAccessionOverview(null, error.response));
});
};
import AccessionFilter from 'model/AccessionFilter';
/*
* Defined in Swagger as '#/definitions/AccessionOverview'
*/
class AccessionOverview {
public filterCode: string;
public filter: AccessionFilter;
public overview: any;
}
export default AccessionOverview;
......@@ -6,13 +6,14 @@ import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEN
import FilteredPage from 'model/FilteredPage';
import Accession from 'model/Accession';
import AccessionMapInfo from 'model/AccessionMapInfo';
import AccessionOverview from 'model/AccessionOverview';
const INITIAL_STATE: {
accession: Accession;
accessionError: any;
paged: FilteredPage<Accession>;
pagedError: any;
overview: any;
overview: AccessionOverview;
mapInfo: AccessionMapInfo;
} = {
accession: null,
......
......@@ -11,6 +11,7 @@ import {applyFilters, loadAccessionsPage, listAccessionsPromise, updateRoute, ap
import Accession from 'model/Accession';
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import AccessionFilter from 'model/AccessionFilter';
import AccessionOverview from 'model/AccessionOverview';
// UI
import PageLayout, { PageContents } from 'ui/layout/PageLayout';
......@@ -26,7 +27,7 @@ import AccessionFilters from './c/Filters';
import Button from '@material-ui/core/Button';
interface IOverviewPageProps extends React.ClassAttributes<any> {
overview: any;
overview: AccessionOverview;
paged: FilteredPage<Accession>;
filterCode: string;
applyOverviewFilters: (filters: string | AccessionFilter, page?: IPageRequest) => void;
......@@ -53,16 +54,15 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
}
public componentWillMount() {
const { overview, paged, filterCode, applyOverviewFilters, updateRoute } = this.props;
if (! overview) {
const { overview, filterCode, applyOverviewFilters } = this.props;
if (! overview || filterCode !== overview.filterCode) {
applyOverviewFilters(filterCode || '');
} else {
updateRoute(paged, '/a/overview');
}
}
public render() {
const { paged, filterCode, currentTab, applyOverviewFilters, overview, t } = this.props;
const { filterCode, currentTab, applyOverviewFilters, overview: overviewWrapper, t } = this.props;
const overview = overviewWrapper && overviewWrapper.overview || null;
const overviewKeys = ['institute.code', 'institute.country.code3', 'cropName', 'crop.shortName', 'sampStat', 'taxonomy.genus', 'taxonomy.genusSpecies',
'countryOfOrigin.code3', 'donorCode', 'mlsStatus', 'available', 'duplSite', 'sgsv', 'storage', 'breederCode'];
......@@ -79,7 +79,7 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
return (
<PageLayout
sidebar={
<AccessionFilters initialValues={ paged && paged.filter || {} } onSubmit={ applyOverviewFilters }/>
<AccessionFilters initialValues={ overviewWrapper && overviewWrapper.filter || {} } onSubmit={ applyOverviewFilters }/>
}
>
<ContentHeader title="Accession browser" subTitle="Explore curated sets of accessions" />
......@@ -97,7 +97,7 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
</Tabs>
<PrettyFilters
prefix="accessions"
filterObj={ paged && paged.filter || {} }
filterObj={ overviewWrapper && overviewWrapper.filter || {} }
onSubmit={ applyOverviewFilters }
/>
{ overview &&
......
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