DisplayPage.tsx 11.2 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';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
26
import LocationMap from './c/LocationMap';
Matija Obreza's avatar
Matija Obreza committed
27

28
29

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

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

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

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

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

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

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

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

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

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

        { accession &&
          <PageContents>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
            <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>
              }
            >
Matija Obreza's avatar
Matija Obreza committed
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
              <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>
Matija Obreza's avatar
Matija Obreza committed
149
                { accession.crop && <PropertiesItem title="Crop name"><CropChips crops={ accession.crop.shortName } /></PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
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
179
180
181
182
183
184
185
                <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>
Matija Obreza's avatar
Matija Obreza committed
186
              { hasLatLon && <LocationMap accessionGeo={ accession.geo } classes={ {} } /> }
Matija Obreza's avatar
Matija Obreza committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
            </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) => (
208
                  <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
209
210
                )) }
                { accession.pdci.dependentItems.map((item) => (
211
                  <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
                )) }
              </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>
        }
226
227
228
229
230
231
232
233
234
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
  accession: state.accessions.accession,
  error: state.accessions.accessionError,
  uuid: ownProps.match.params.uuid,
235
  doi: ownProps.match.params.doi,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
236
  accessions: state.user.myList.accessions,
237
238
239
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
240
241
  addAccessionToMyList,
  removeAccessionFromMyList,
242
243
244
245
  loadAccession,
}, dispatch);


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