DisplayPage.tsx 12.9 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

// Actions
import { loadAccession } from 'actions/accessions';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
8
import {addAccessionToMyList, removeAccessionFromMyList} from 'actions/user';
9
10
11
12
13

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

// UI
Matija Obreza's avatar
Matija Obreza committed
14
15
16
import { Link } from 'react-router-dom';
import PrettyDate from 'ui/common/time/PrettyDate';
import PageLayout, { PageContents, MainSection, PageSection } from 'ui/layout/PageLayout';
17
18
import ContentHeader from 'ui/common/heading/ContentHeader';
import Loading from 'ui/common/Loading';
Matija Obreza's avatar
Matija Obreza committed
19
20
21
22
23
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';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
24
import ReduxCheckbox from 'ui/common/checkbox';
Matija Obreza's avatar
Matija Obreza committed
25
import CropChips from 'ui/genesys/crop/CropChips';
26
import LocationMap from 'ui/common/LocationMap';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
27
import {CountryLink, InstituteLink} from 'ui/genesys/Links';
28
import McpdDate from 'ui/common/time/McpdDate';
Matija Obreza's avatar
Matija Obreza committed
29

30
31

interface IBrowsePageProps extends React.ClassAttributes<any> {
Matija Obreza's avatar
Matija Obreza committed
32
  t: any;
33
  uuid: string;
34
  doi: string; // DOI comes from the route without the '10.'
35
36
37
  accession: Accession;
  error: any;
  loadAccession: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
38
39
40
  accessions: any;
  addAccessionToMyList: any;
  removeAccessionFromMyList: any;
41
42
43
44
45
}

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

  protected static needs = [
46
    ({ params: { uuid, doi } }) => {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
47
        return doi ? loadAccession({ doi: `10.${doi}` }) :  loadAccession({ uuid });
48
49
50
51
52
53
54
55
    },
  ];

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

  public componentWillMount() {
56
57
58
59
60
    const { accession, doi, uuid, loadAccession } = this.props;
    const theDoi = `10.${doi}`;
    if (doi && (! accession || theDoi !== accession.doi)) {
      loadAccession({ doi: theDoi });
    }
61
    if (uuid && (! accession || uuid !== accession.uuid)) {
62
      loadAccession({ uuid });
63
64
65
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
66
67
68
69
70
71
72
73
74
  private onCheckboxChange = (event, checked) => {
      const {accession, addAccessionToMyList, removeAccessionFromMyList} = this.props;
      if (checked) {
          addAccessionToMyList(accession.uuid);
      } else {
          removeAccessionFromMyList(accession.uuid);
        }
  }

75
  public render() {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
76
77
    const { t, error, accession, uuid, doi, accessions } = this.props;
    const  isChecked  =  accession && accessions && accessions.includes(accession.uuid);
78
79
80
81
    const theDoi = `10.${doi}`;
    const stillLoading: boolean = ! error && (! accession
      || (doi && accession && accession.doi !== theDoi)
      || (uuid && accession && accession.uuid !== uuid));
82

Matija Obreza's avatar
Matija Obreza committed
83
84
    const hasLatLon = accession && accession.geo && accession.geo.latitude !== null && accession.geo.longitude !== null;

85
86
    return (
      <PageLayout>
Matija Obreza's avatar
Matija Obreza committed
87
88
89
        <ScrollToTopOnMount />
        <ContentHeader title="Accession details" subtitle="Passport data and everything else" />

90
91
92
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
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
            { accession &&
              <PageContents>
                <MainSection title={
                  <div>
                    Accession: { accession.accessionNumber }
                    <div className="float-right">
                        <ReduxCheckbox
                            label={
                                <b>
                                    { isChecked ? `Remove ${accession.accessionNumber} from my list` : `Add ${accession.accessionNumber} to my list` }
                                </b>
                            }
                            input={ {
                                value: isChecked,
                                onChange: this.onCheckboxChange,
                            } }
                        />
                    </div>
                  </div>
                  }
                >
                  <Properties>
                    { accession.doi && <PropertiesItem title="DOI"><DOI noPrefix value={ accession.doi } /></PropertiesItem> }
                    <PropertiesItem title="Accession number">{ accession.accessionNumber }</PropertiesItem>
                    <PropertiesItem title="Holding institute">
                      <InstituteLink to={ accession.institute }>
                        { accession.institute.fullName }
                      </InstituteLink>
                    </PropertiesItem>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
123
                    <PropertiesItem title="Country of holding institute">{ <CountryLink country={ accession.institute.country }/> }</PropertiesItem>
124
                    <PropertiesItem title="Institute code">{ accession.institute.code }</PropertiesItem>
125
                    <PropertiesItem title="Acquisition date"><McpdDate value={ accession.acquisitionDate } /></PropertiesItem>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
126
                    <PropertiesItem title="Country of origin">{ accession.countryOfOrigin.name }</PropertiesItem>
127
                    { accession.sampStat && <PropertiesItem title="Biological status of accession">{ t(`accession.sampleStatus.${accession.sampStat}`) }</PropertiesItem> }
128
129
                    { accession.storage && accession.storage.length > 0 && <PropertiesItem title="Type of Germplasm storage">
                      { accession.storage.map((storage, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
130
                        <div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accession.storage.${storage}`) }</div>
131
132
                      )) }
                    </PropertiesItem> }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
133
134
                    <PropertiesItem title="Availability for distribution" keepEmpty>{ t(`accession.available.${accession.available}`) }</PropertiesItem>
                    <PropertiesItem title="Availability for distribution under the MLS" keepEmpty>{ t(`accession.available.${accession.mlsStatus}`) }</PropertiesItem>
135
136
                    <PropertiesItem title="Donor institute">{ accession.donorCode }</PropertiesItem>
                    <PropertiesItem title="Donor accession number">{ accession.donorNumb }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
137

138
139
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title="Safety duplication institute">
                      { accession.duplSite.map((duplSite, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
140
                        <div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
141
142
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
143

144
145
146
                    { accession.acceUrl && <PropertiesItem title="Accession URL"><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
147

148
149
150
151
152
153
154
155
156
157
158
159
160
                <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"><CropChips crops={ accession.crop.shortName } /></PropertiesItem> }
                    <PropertiesItem title="Provided crop name">{ accession.cropName }</PropertiesItem>
                  </Properties>
                </PageSection>
Matija Obreza's avatar
Matija Obreza committed
161

162
163
164
165
166
167
168
169
                <PageSection title="Accession names">
                  <Properties>
                    { 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>
170

171
172
173
                { accession.coll &&
                  <PageSection title="Collecting information">
                    <Properties>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
174
                      { accession.countryOfOrigin && <PropertiesItem title="Country of origin">{ <CountryLink country={ accession.countryOfOrigin }/> }</PropertiesItem> }
175
176
177
178
179
180
                      { accession.coll.collDate &&   <PropertiesItem key="collDate" title={ t(`accession.coll.collDate`) }><McpdDate value={ accession.coll.collDate } /></PropertiesItem> }
                      { accession.coll &&
                        [ 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                          .filter((prop) => accession.coll[prop] !== null).map((prop) => (
                          <PropertiesItem key={ prop } title={ t(`accession.coll.${prop}`) }>{ accession.coll[prop] }</PropertiesItem>
                        ))
181
                      }
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
                      { 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>

                    { hasLatLon &&
                      <LocationMap
                        location={
                          {
                            id: accession.geo.id,
                            lat: accession.geo.latitude,
                            lng: accession.geo.longitude,
                          }
                        }
                      />
                    }
                  </PageSection>
                }
Matija Obreza's avatar
Matija Obreza committed
209

210
211
212
213
214
215
216
                { 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> }
Matija Obreza's avatar
Matija Obreza committed
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
                { 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 small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
                    )) }
                    { accession.pdci.dependentItems.map((item) => (
                      <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
                    )) }
                  </Properties>
                </PageSection> }
Matija Obreza's avatar
Matija Obreza committed
236

237
238
239
240
241
242
243
244
245
246
247
                <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>
            }
          </div>
Matija Obreza's avatar
Matija Obreza committed
248
        }
249
250
251
252
253
254
255
256
257
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
  accession: state.accessions.accession,
  error: state.accessions.accessionError,
  uuid: ownProps.match.params.uuid,
258
  doi: ownProps.match.params.doi,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
259
  accessions: state.user.myList.accessions,
260
261
262
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
263
264
  addAccessionToMyList,
  removeAccessionFromMyList,
265
266
267
268
  loadAccession,
}, dispatch);


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