DisplayPage.tsx 9.16 KB
Newer Older
1
2
3
import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
Matija Obreza's avatar
Matija Obreza committed
4
import { translate } from 'react-i18next';
5
6
7
8
9
10
11
12

// Actions
import { loadAccession } from 'actions/accessions';

// Models
import Accession from 'model/Accession';

// UI
Matija Obreza's avatar
Matija Obreza committed
13
14
15
import { Link } from 'react-router-dom';
import PrettyDate from 'ui/common/time/PrettyDate';
import PageLayout, { PageContents, MainSection, PageSection } from 'ui/layout/PageLayout';
16
17
import ContentHeader from 'ui/common/heading/ContentHeader';
import Loading from 'ui/common/Loading';
Matija Obreza's avatar
Matija Obreza committed
18
19
20
21
22
import { Properties, PropertiesItem } from 'ui/common/Properties';
import DOI from 'ui/common/DOI';
import { ExternalLink } from 'ui/common/Links';
import SciName from 'ui/genesys/SciName';
import { ScrollToTopOnMount } from 'ui/common/page/scrollers';
23
24

interface IBrowsePageProps extends React.ClassAttributes<any> {
Matija Obreza's avatar
Matija Obreza committed
25
  t: any;
26
27
28
29
30
31
32
33
34
35
  uuid: string;
  accession: Accession;
  error: any;
  loadAccession: any;
}

class BrowsePage extends React.Component<IBrowsePageProps, any> {

  protected static needs = [
    ({ params: { uuid } }) => {
Matija Obreza's avatar
Matija Obreza committed
36
      return uuid ? loadAccession(uuid) : null;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    },
  ];

  constructor(props: IBrowsePageProps, context: any) {
      super(props, context);
  }

  public componentWillMount() {
    const { accession, uuid, loadAccession } = this.props;
    if (uuid && (! accession || uuid !== accession.uuid)) {
      loadAccession(uuid);
    }
  }

  public render() {
Matija Obreza's avatar
Matija Obreza committed
52
    const { t, error, accession, uuid } = this.props;
53
54
55
56
    const stillLoading: boolean = ! error && (! accession || (uuid && accession && accession.uuid !== uuid));

    return (
      <PageLayout>
Matija Obreza's avatar
Matija Obreza committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
        <ScrollToTopOnMount />
        <ContentHeader title="Accession details" subtitle="Passport data and everything else" />

        { stillLoading && <Loading /> }
        { error && <div>{ JSON.stringify(error) }</div> }

        { accession &&
          <PageContents>
            <MainSection title={ `Accession: ${accession.accessionNumber}` }>
              <Properties>
                { accession.doi && <PropertiesItem title="DOI"><DOI noPrefix value={ accession.doi } /></PropertiesItem> }
                <PropertiesItem title="Accession number">{ accession.accessionNumber }</PropertiesItem>
                <PropertiesItem title="Holding institute">{ accession.institute.fullName }</PropertiesItem>
                <PropertiesItem title="Country of holding institute">{ accession.institute.country.name }</PropertiesItem>
                <PropertiesItem title="Acquisition date">{ accession.acquisitionDate }</PropertiesItem>

                <PropertiesItem title="Biological status of accession">{ accession.sampStat }</PropertiesItem>
                <PropertiesItem title="Availability for distribution">{ t(`accession.available.${accession.available}`) }</PropertiesItem>

                { accession.storage && accession.storage.length > 0 && <PropertiesItem title="Type of Germplasm storage">
                  { accession.storage.map((storage, i) => (
                    <div key={ storage }>{ t(`accession.storage.${storage}`) }</div>
                  )) }
                </PropertiesItem> }
                <PropertiesItem title="Donor institute">{ accession.donorCode }</PropertiesItem>
                <PropertiesItem title="Donor accession number">{ accession.donorNumb }</PropertiesItem>

                { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title="Safety duplication institute">
                  { accession.duplSite.map((duplSite, i) => (
                    <div key={ duplSite }>{ duplSite }</div>
                  )) }
                </PropertiesItem> }

                { accession.acceUrl && <PropertiesItem title="Accession URL"><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
              </Properties>
            </MainSection>

            <PageSection title="Taxonomy">
              <Properties>
                <PropertiesItem title="Genus">{ accession.taxonomy.genus }</PropertiesItem>
                <PropertiesItem title="Species">
                  { accession.taxonomy.species }
                  { '' }
                  <Link to={ '/a' }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</Link>
                </PropertiesItem>
                <PropertiesItem title="Scientific name"><SciName taxa={ accession.taxonomy.taxonNameHtml } /></PropertiesItem>
                { accession.crop && <PropertiesItem title="Crop name">{ accession.crop.name }</PropertiesItem> }
                <PropertiesItem title="Provided crop name">{ accession.cropName }</PropertiesItem>
              </Properties>
            </PageSection>

            <PageSection title="Accession names">
              <Properties>
                { accession.coll && accession.coll.collNumb && <PropertiesItem title={ t('accession.alias.COLLNUMB') }>{ accession.coll.collNumb } { accession.coll.collCode }</PropertiesItem> }
                { accession.donorCode && <PropertiesItem title={ t('accession.alias.DONORNUMB') }>{ accession.donorNumb } { accession.donorCode }</PropertiesItem> }
                { accession.aliases && accession.aliases.map((alias) => (
                  <PropertiesItem key={ alias.id } title={ t(`accession.alias.${alias.aliasType}`) }>{ alias.name } { alias.usedBy }</PropertiesItem>
                )) }
              </Properties>
            </PageSection>

            <PageSection title="Collecting information">
              <Properties>
                { accession.countryOfOrigin && <PropertiesItem title="Country of origin">{ accession.countryOfOrigin.name }</PropertiesItem> }
                { accession.coll &&
                  [ 'collDate', 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                    .filter((prop) => accession.coll[prop] !== null).map((prop) => (
                    <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                  ))
                }
                { accession.coll &&
                  [ 'collCode', 'collName' ]
                    .filter((prop) => accession.coll[prop].length).map((prop) => (
                    <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                  ))
                }
                { accession.geo &&
                  [ 'latitude', 'longitude', 'datum', 'method', 'uncertainty', 'elevation' ]
                    .filter((prop) => accession.geo[prop] !== null).map((prop) => (
                    <PropertiesItem key={ prop } title={ t(`accession.geo.${prop}`) }>{ accession.geo[prop] }</PropertiesItem>
                  ))
                }
              </Properties>
            </PageSection>

            { accession.remarks && accession.remarks.length > 0 && <PageSection title="Remarks">
              <Properties>
                { accession.remarks && accession.remarks.map((remark) => (
                  <PropertiesItem key={ remark.id } title={ remark.fieldName }>{ remark.remark }</PropertiesItem>
                )) }
              </Properties>
            </PageSection> }

            { accession.pdci && <PageSection title="Passport Data Completeness Index">
              <div style={ { marginBottom: '2em', padding: '2em', backgroundColor: '#b6c1b4', borderRadius: '6px' } }>
                <span style={ { fontSize: '1.5em' } }>
                  { t('accession.pdciScore', { score: accession.pdci.score }) }
                  { /*<p>{ t(`accession.pdciInstitute`, { score: accession.pdci.score }) }</p>*/ }
                </span>
                  { ' ' }
                  <a href="#">Read about Passport Data Completeness Index</a>
              </div>
              <Properties>
                { accession.pdci.independentItems.map((item) => (
                  <PropertiesItem keepEmpty 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>
                )) }
              </Properties>
            </PageSection> }

            <PageSection title="Metadata">
              <Properties>
                <PropertiesItem title="UUID">{ `urn:uuid:${accession.uuid}` }</PropertiesItem>
                <PropertiesItem title="Permanent URL"><ExternalLink link={ `https://purl.org/germplasm/id/${accession.uuid}` } /></PropertiesItem>
                <PropertiesItem title="Last updated"><PrettyDate value={ accession.lastModifiedDate } /></PropertiesItem>
                <PropertiesItem title="Created"><PrettyDate value={ accession.createdDate } /></PropertiesItem>
              </Properties>
            </PageSection>
          </PageContents>
        }
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
  accession: state.accessions.accession,
  error: state.accessions.accessionError,
  uuid: ownProps.match.params.uuid,
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
  loadAccession,
}, dispatch);


Matija Obreza's avatar
Matija Obreza committed
195
export default connect(mapStateToProps, mapDispatchToProps)(translate()(BrowsePage));