Commit 2b15c78e authored by Matija Obreza's avatar Matija Obreza
Browse files

Use accession DOI as route to display page

parent 06055660
...@@ -6,7 +6,7 @@ import FilteredPage, { IPageRequest } from 'model/FilteredPage'; ...@@ -6,7 +6,7 @@ import FilteredPage, { IPageRequest } from 'model/FilteredPage';
import Accession from 'model/Accession'; import Accession from 'model/Accession';
import AccessionFilter from 'model/AccessionFilter'; import AccessionFilter from 'model/AccessionFilter';
import { list as listAccessions, getByUuid } from 'actions/genesys/accessionService'; import { list as listAccessions, getByUuid, getByDoi } from 'actions/genesys/accessionService';
import { RECEIVE_ACCESSIONS, RECEIVE_ACCESSION } from 'constants/accessions'; import { RECEIVE_ACCESSIONS, RECEIVE_ACCESSION } from 'constants/accessions';
const receiveAccessions = (paged: FilteredPage<Accession>, error = null) => ({ const receiveAccessions = (paged: FilteredPage<Accession>, error = null) => ({
...@@ -53,8 +53,11 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) = ...@@ -53,8 +53,11 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) =
}); });
}; };
export const loadAccession = (uuid: string) => (dispatch) => { export const loadAccession = ({ uuid, doi }: { uuid: string, doi: string }) => (dispatch) => {
return dispatch(getByUuid(uuid)) const loader = doi ? getByDoi : getByUuid;
const lookup = doi ? doi : uuid;
return dispatch(loader(lookup))
.then((accession) => { .then((accession) => {
dispatch(receiveAccession(accession)); dispatch(receiveAccession(accession));
}).catch((error) => { }).catch((error) => {
......
...@@ -8,7 +8,7 @@ import Accession from 'model/Accession'; ...@@ -8,7 +8,7 @@ import Accession from 'model/Accession';
import AccessionFilter from 'model/AccessionFilter'; import AccessionFilter from 'model/AccessionFilter';
import FilteredPage, { IPageRequest } from 'model/FilteredPage'; import FilteredPage, { IPageRequest } from 'model/FilteredPage';
const URL_GET_BY_DOI = UrlTemplate.parse(`${API_ROOT}/api/v1/acn/{doi}}`); const URL_GET_BY_DOI = `${API_ROOT}/api/v1/acn/{doi}`; // UrlTemplate doesn't like the / in DOI
const URL_GET_BY_UUID = UrlTemplate.parse(`${API_ROOT}/api/v1/acn/{UUID}`); const URL_GET_BY_UUID = UrlTemplate.parse(`${API_ROOT}/api/v1/acn/{UUID}`);
const URL_LIST = `${API_ROOT}/api/v1/acn/list`; const URL_LIST = `${API_ROOT}/api/v1/acn/list`;
...@@ -25,7 +25,7 @@ class AccessionService { ...@@ -25,7 +25,7 @@ class AccessionService {
*/ */
public static getByDoi(authToken: string, doi: string): Promise<Accession> { public static getByDoi(authToken: string, doi: string): Promise<Accession> {
const apiUrl = URL_GET_BY_DOI.expand({ doi }); const apiUrl = URL_GET_BY_DOI.replace(/{doi}/, doi);
// console.log(`Fetching from ${apiUrl}`); // console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ }; const content = { /* No content in request body */ };
......
...@@ -32,7 +32,7 @@ function AccessionLink({ to: accession, edit = false, children = null } ...@@ -32,7 +32,7 @@ function AccessionLink({ to: accession, edit = false, children = null }
if (accession) { if (accession) {
return ( return (
<Link to={ `/a/${accession.uuid}` }> <Link to={ accession.doi ? `/${accession.doi}` : `/a/${accession.uuid}` }>
{ children || accession.accessionNumber } { children || accession.accessionNumber }
</Link> </Link>
); );
......
...@@ -24,6 +24,7 @@ import { ScrollToTopOnMount } from 'ui/common/page/scrollers'; ...@@ -24,6 +24,7 @@ import { ScrollToTopOnMount } from 'ui/common/page/scrollers';
interface IBrowsePageProps extends React.ClassAttributes<any> { interface IBrowsePageProps extends React.ClassAttributes<any> {
t: any; t: any;
uuid: string; uuid: string;
doi: string; // DOI comes from the route without the '10.'
accession: Accession; accession: Accession;
error: any; error: any;
loadAccession: any; loadAccession: any;
...@@ -32,8 +33,8 @@ interface IBrowsePageProps extends React.ClassAttributes<any> { ...@@ -32,8 +33,8 @@ interface IBrowsePageProps extends React.ClassAttributes<any> {
class BrowsePage extends React.Component<IBrowsePageProps, any> { class BrowsePage extends React.Component<IBrowsePageProps, any> {
protected static needs = [ protected static needs = [
({ params: { uuid } }) => { ({ params: { uuid, doi } }) => {
return uuid ? loadAccession(uuid) : null; return uuid || doi ? loadAccession({ uuid, doi: `10.${doi}` }) : null;
}, },
]; ];
...@@ -42,15 +43,22 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> { ...@@ -42,15 +43,22 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
} }
public componentWillMount() { public componentWillMount() {
const { accession, uuid, loadAccession } = this.props; const { accession, doi, uuid, loadAccession } = this.props;
const theDoi = `10.${doi}`;
if (doi && (! accession || theDoi !== accession.doi)) {
loadAccession({ doi: theDoi });
}
if (uuid && (! accession || uuid !== accession.uuid)) { if (uuid && (! accession || uuid !== accession.uuid)) {
loadAccession(uuid); loadAccession({ uuid });
} }
} }
public render() { public render() {
const { t, error, accession, uuid } = this.props; const { t, error, accession, uuid, doi } = this.props;
const stillLoading: boolean = ! error && (! accession || (uuid && accession && accession.uuid !== uuid)); const theDoi = `10.${doi}`;
const stillLoading: boolean = ! error && (! accession
|| (doi && accession && accession.doi !== theDoi)
|| (uuid && accession && accession.uuid !== uuid));
return ( return (
<PageLayout> <PageLayout>
...@@ -158,10 +166,10 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> { ...@@ -158,10 +166,10 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
</div> </div>
<Properties> <Properties>
{ accession.pdci.independentItems.map((item) => ( { accession.pdci.independentItems.map((item) => (
<PropertiesItem keepEmpty small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem> <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
)) } )) }
{ accession.pdci.dependentItems.map((item) => ( { accession.pdci.dependentItems.map((item) => (
<PropertiesItem keepEmpty small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem> <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
)) } )) }
</Properties> </Properties>
</PageSection> } </PageSection> }
...@@ -185,6 +193,7 @@ const mapStateToProps = (state, ownProps) => ({ ...@@ -185,6 +193,7 @@ const mapStateToProps = (state, ownProps) => ({
accession: state.accessions.accession, accession: state.accessions.accession,
error: state.accessions.accessionError, error: state.accessions.accessionError,
uuid: ownProps.match.params.uuid, uuid: ownProps.match.params.uuid,
doi: ownProps.match.params.doi,
}); });
const mapDispatchToProps = (dispatch) => bindActionCreators({ const mapDispatchToProps = (dispatch) => bindActionCreators({
......
...@@ -70,6 +70,12 @@ const routes = [ ...@@ -70,6 +70,12 @@ const routes = [
component: AccessionDisplayPage, component: AccessionDisplayPage,
exact: true, exact: true,
}, },
{
// We need to take out the '10.' prefix for matching to work
path: '/10.:doi(\\d+\/.+)',
component: AccessionDisplayPage,
exact: true,
},
// Dashboard // Dashboard
{ {
path: '/dashboard', path: '/dashboard',
......
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