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