DisplayPage.tsx 10.8 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';
25
26

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

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

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

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

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

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

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

    return (
      <PageLayout>
Matija Obreza's avatar
Matija Obreza committed
80
81
82
83
84
85
86
87
        <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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
            <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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
              <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) => (
202
                  <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
203
204
                )) }
                { accession.pdci.dependentItems.map((item) => (
205
                  <PropertiesItem small key={ item } title={ item.toUpperCase() }>{ accession.pdci[item] }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
                )) }
              </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>
        }
220
221
222
223
224
225
226
227
228
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
  accession: state.accessions.accession,
  error: state.accessions.accessionError,
  uuid: ownProps.match.params.uuid,
229
  doi: ownProps.match.params.doi,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
230
  accessions: state.user.myList.accessions,
231
232
233
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
234
235
  addAccessionToMyList,
  removeAccessionFromMyList,
236
237
238
239
  loadAccession,
}, dispatch);


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