DisplayPage.tsx 19.6 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
import { withStyles } from '@material-ui/core/styles';
6
7

// Actions
8
import { loadAccession, applyFilters, loadAccessionAuditLog } from 'accessions/actions/public';
9
import {addAccessionToMyList, removeAccessionFromMyList} from 'list/actions/public';
10

11
12
13
// Constants
import { ROLE_USER } from 'constants/userRoles';

14
// Models
15
import AccessionDetails from 'model/accession/AccessionDetails';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
16
import RepositoryFile from 'model/repository/RepositoryFile';
17
import AccessionAuditLog from 'model/accession/AccessionAuditLog';
18
19

// UI
Matija Obreza's avatar
Matija Obreza committed
20
21
import PrettyDate from 'ui/common/time/PrettyDate';
import PageLayout, { PageContents, MainSection, PageSection } from 'ui/layout/PageLayout';
22
23
import ContentHeader from 'ui/common/heading/ContentHeader';
import Loading from 'ui/common/Loading';
Matija Obreza's avatar
Matija Obreza committed
24
25
26
27
28
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
29
import ReduxCheckbox from 'ui/common/checkbox';
30
import CropChips from 'crop/ui/c/CropChips';
31
import LocationMap from 'ui/common/LocationMap';
32
33
import {CountryLink, DatasetLink, InstituteLink, SubsetLink} from 'ui/genesys/Links';
import PropertiesCard from 'ui/common/PropertiesCard';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
34
import GridContainer from 'ui/layout/GridContainer';
35
import McpdDate from 'ui/common/time/McpdDate';
36
import PdciTable from './c/PdciTable';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
37
38
import ImageGalleryView from 'repository/ui/c/ImageGalleryView';
import Button from '@material-ui/core/Button/Button';
39
40
import AuditedInfo from 'ui/common/AuditedInfo';
import Authorize from 'ui/common/authorized/Authorize';
Matija Obreza's avatar
Matija Obreza committed
41

42
43
44
45
const styles = (theme) => ({
  pageSection: {
    marginBottom: '1em',
  },
Matija Obreza's avatar
Matija Obreza committed
46
47
48
49
50
51
  selected: {
    background: '#c9e2cb',
  },
  historic: {
    background: '#ffe2e2 !important',
  },
52
53
});

54

55
56
57
interface IBrowsePageProps {
  t?: any;
  classes?: any;
58

59
  uuid: string;
60
  doi: string; // DOI comes from the route without the '10.'
61
  accession: AccessionDetails;
62
  auditLog: AccessionAuditLog;
63
64
  error: any;
  loadAccession: any;
65
  loadAccessionAuditLog: any;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
66
67
68
  accessions: any;
  addAccessionToMyList: any;
  removeAccessionFromMyList: any;
Matija Obreza's avatar
Matija Obreza committed
69
  applyFilters: any;
70
71
72
73
74
}

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

  protected static needs = [
75
    ({ params: { uuid, doi } }) => {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
76
        return doi ? loadAccession({ doi: `10.${doi}` }) :  loadAccession({ uuid });
77
78
79
80
81
82
83
84
    },
  ];

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

  public componentWillMount() {
85
86
87
    const { doi, uuid, loadAccession } = this.props;
    const accession = this.props.accession ? this.props.accession.details : null;

88
89
90
91
    const theDoi = `10.${doi}`;
    if (doi && (! accession || theDoi !== accession.doi)) {
      loadAccession({ doi: theDoi });
    }
92
    if (uuid && (! accession || uuid !== accession.uuid)) {
93
      loadAccession({ uuid });
94
95
96
    }
  }

97
98
99
100
101
102
103
104
105
106
107
  private loadAuditLog = () => {
    const { doi, uuid, loadAccessionAuditLog } = this.props;

    const theDoi = `10.${doi}`;
    if (doi) {
      loadAccessionAuditLog({ doi: theDoi });
    } else {
      loadAccessionAuditLog({uuid});
    }
  }

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
108
  private onCheckboxChange = (event, checked) => {
109
      const {accession: {details: accession}, addAccessionToMyList, removeAccessionFromMyList} = this.props;
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
110
111
112
113
114
115
116
      if (checked) {
          addAccessionToMyList(accession.uuid);
      } else {
          removeAccessionFromMyList(accession.uuid);
        }
  }

Matija Obreza's avatar
Matija Obreza committed
117
118
119
120
121
122
123
124

  private applyFilterForInstituteSpecies = () => {
    const { accession: {details: accession}, applyFilters } = this.props;
    const filter = {holder: {code: [ accession.institute.code ]}, taxa: { genus: [ accession.taxonomy.genus ], species: [ accession.taxonomy.species ] }};
    applyFilters(filter);
  }


125
  public render() {
126
127
128
129
    const { t, error, uuid, doi, accessions, auditLog, classes } = this.props;

    const { auditAccession, auditAccessionId, auditAccessionCollect, auditAccessionGeo } = auditLog || { auditAccession: {}, auditAccessionId: {}, auditAccessionCollect: {}, auditAccessionGeo: {} };

130
    const { details: accession, pdci, datasets, subsets, files, imageGallery } = this.props.accession ?
131
132
      this.props.accession
      :
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
133
      {details: null, pdci: null, datasets: null, subsets: null, files: null, imageGallery: null};
134

Matija Obreza's avatar
Matija Obreza committed
135
    const isChecked  =  accession && accessions && accessions.includes(accession.uuid);
136
137
138
139
    const theDoi = `10.${doi}`;
    const stillLoading: boolean = ! error && (! accession
      || (doi && accession && accession.doi !== theDoi)
      || (uuid && accession && accession.uuid !== uuid));
140

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

143
    return (
Oleksii Savran's avatar
Oleksii Savran committed
144
      <PageLayout withFooter>
Matija Obreza's avatar
Matija Obreza committed
145
        <ScrollToTopOnMount />
Matija Obreza's avatar
Matija Obreza committed
146
        <ContentHeader title={ t('accessions.public.p.display.title') } subtitle={ t('accessions.public.p.display.subTitle') } />
Matija Obreza's avatar
Matija Obreza committed
147

148
149
150
        { stillLoading ? <Loading /> :
          <div>
            { error && <div>{ JSON.stringify(error) }</div> }
Matija Obreza's avatar
Matija Obreza committed
151

152
            { accession &&
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
153
              <PageContents className="pt-1rem">
Matija Obreza's avatar
Matija Obreza committed
154
                <MainSection className={ isChecked ? classes.selected : accession.historic ?  classes.historic : '' } title={
155
                  <div>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
156
                    { t('accessions.common.modelName') }: { accession.accessionNumber }
157
                    <div className="float-right">
158
159
160
                        <Authorize role={ ROLE_USER }>
                            <Button className="mr-20" variant="contained" onClick={ this.loadAuditLog }>{ t('accessions.public.p.display.loadChanges') }</Button>
                        </Authorize>
161
162
163
                        <ReduxCheckbox
                            label={
                                <b>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
164
                                    { isChecked ? t('accessions.public.p.display.removeFromMyList', {accessionNumber: accession.accessionNumber}) : t('accessions.public.p.display.addToMyList', {accessionNumber: accession.accessionNumber}) }
165
166
167
168
169
170
171
172
173
174
175
176
                                </b>
                            }
                            input={ {
                                value: isChecked,
                                onChange: this.onCheckboxChange,
                            } }
                        />
                    </div>
                  </div>
                  }
                >
                  <Properties>
177
                    { accession.doi && <PropertiesItem title={ t('accessions.public.p.display.DOI') }><DOI noPrefix value={ accession.doi } /></PropertiesItem> }
178
179
180
181
                    <PropertiesItem title={ t('accessions.common.acceNumb') } >
                      { accession.accessionNumber }
                      <AuditedInfo info={ auditAccession.accessionNumber }/>
                    </PropertiesItem>
182
                    <PropertiesItem title={ t('accessions.public.p.display.holdingInstitute') }>
183
184
185
                      <InstituteLink to={ accession.institute }>
                        { accession.institute.fullName }
                      </InstituteLink>
Matija Obreza's avatar
Matija Obreza committed
186
187
                      <span> &mdash; </span>
                      <CountryLink noflag country={ accession.institute.country }/>
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
                      <AuditedInfo info={ auditAccession.institute }/>
                    </PropertiesItem>
                    { accession.historic &&
                      <PropertiesItem className={ accession.historic ?  classes.historic : '' } title={ t('accessions.public.p.display.historic') }>
                        { t('accessions.public.p.display.isHistoric') }
                        <AuditedInfo info={ auditAccession.historic }/>
                      </PropertiesItem>
                    }
                    <PropertiesItem title={ t('accessions.common.instituteCode') }>
                      { accession.institute.code }
                      <AuditedInfo info={ auditAccession.instituteCode }/>
                    </PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.acquisitionDate') }>
                      <McpdDate value={ accession.acquisitionDate } />
                      <AuditedInfo info={ auditAccession.acquisitionDate }/>
203
                    </PropertiesItem>
204
205
206
207
208
209
210
                    { accession.countryOfOrigin && <PropertiesItem title={ t('accessions.common.countryOfOrigin') }>{ <CountryLink country={ accession.countryOfOrigin }/> }<AuditedInfo info={ auditAccession.countryOfOrigin }/></PropertiesItem> }
                    { accession.sampStat &&
                      <PropertiesItem title={ t('accessions.common.sampStat') }>
                        { t(`accessions.common.sampleStatus.${accession.sampStat}`) }
                        <AuditedInfo info={ auditAccession.sampStat }/>
                      </PropertiesItem>
                    }
211
                    { accession.storage && accession.storage.length > 0 && <PropertiesItem title={ t('accessions.common.storageType') }>
212
                      { accession.storage.map((storage, i) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
213
                        <div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accessions.common.storage.${storage}`) }</div>
214
215
                      )) }
                    </PropertiesItem> }
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
                    <PropertiesItem title={ t('accessions.public.p.display.availability') } keepEmpty>
                      { t(`accessions.common.available.${accession.available}`) }
                      <AuditedInfo info={ auditAccession.available }/>
                    </PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.ITPGRFAMLS') } keepEmpty>
                      { t(`accessions.common.mlsStatus.${accession.mlsStatus}`) }
                      <AuditedInfo info={ auditAccession.mlsStatus }/>
                    </PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.donorInstitute') }>
                      { accession.donorCode }
                      <AuditedInfo info={ auditAccession.donorCode }/>
                    </PropertiesItem>
                    <PropertiesItem title={ t('accessions.public.p.display.donorAccessionNumber') }>
                      { accession.donorNumb }
                      <AuditedInfo info={ auditAccession.donorNumb }/>
                    </PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
232

233
                    { accession.duplSite && accession.duplSite.length > 0 && <PropertiesItem title={ t('accessions.public.p.display.safetyDuplicationInstitute') }>
234
                      { accession.duplSite.map((duplSite, i) => (
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
235
                        <div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
236
237
                      )) }
                    </PropertiesItem> }
Matija Obreza's avatar
Matija Obreza committed
238

239
                    { accession.acceUrl && <PropertiesItem title={ t('accessions.public.p.display.accessionURL') }><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
240
241
                  </Properties>
                </MainSection>
Matija Obreza's avatar
Matija Obreza committed
242

243
244
245
246
                { imageGallery &&
                  <ImageGalleryView className={ classes.pageSection } imageGallery={ imageGallery }/>
                }

247
                <PageSection title={ t('accessions.common.taxonomy') }>
248
                  <Properties>
249
250
251
252
                    <PropertiesItem title={ t('accessions.common.genus') }>
                      { accession.taxonomy.genus }
                      <AuditedInfo info={ auditAccession.genus }/>
                    </PropertiesItem>
253
                    <PropertiesItem title={ t('accessions.common.species') }>
254
255
                      { accession.taxonomy.species }
                      { '' }
Matija Obreza's avatar
Matija Obreza committed
256
                      <a onClick={ this.applyFilterForInstituteSpecies }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</a>
257
                    </PropertiesItem>
258
259
260
                    <PropertiesItem title={ t('accessions.public.p.display.scientificName') }><SciName taxa={ accession.taxonomy.taxonNameHtml } /></PropertiesItem>
                    { accession.crop && <PropertiesItem title={ t('accessions.public.p.display.cropName') }><CropChips crops={ accession.crop.shortName } /></PropertiesItem> }
                    <PropertiesItem title={ t('accessions.public.p.display.providedCropName') }>{ accession.cropName }</PropertiesItem>
261
262
                  </Properties>
                </PageSection>
Matija Obreza's avatar
Cleanup  
Matija Obreza committed
263
264

                { (accession.donorCode || (accession.aliases && accession.aliases.length > 0)) &&
265
                  <PageSection title={ t('accessions.public.p.display.accessionNames') }>
266
                    <Properties>
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
267
                      { accession.donorCode && <PropertiesItem title={ t('accessions.common.alias.DONORNUMB') }>{ accession.donorNumb } <em>{ accession.donorCode }</em></PropertiesItem> }
268
                      { accession.aliases && accession.aliases.map((alias) => (
Viacheslav Pavlov's avatar
i18n  
Viacheslav Pavlov committed
269
                        <PropertiesItem key={ alias.id } title={ t(`accessions.common.alias.${alias.aliasType}`) }>{ alias.name } <em>{ alias.usedBy }</em></PropertiesItem>
270
271
272
273
                      )) }
                    </Properties>
                  </PageSection>
                }
274

275
                { accession.coll &&
276
                  <PageSection title={ t('accessions.public.p.display.collectingInformation') }>
277
                    <Properties>
278
279
280
281
282
283
284
285
286
287
288
289
                      { accession.countryOfOrigin &&
                        <PropertiesItem title={ t('accessions.common.countryOfOrigin') }>
                          <CountryLink country={ accession.countryOfOrigin }/>
                          <AuditedInfo info={ auditAccessionCollect.countryOfOrigin }/>
                        </PropertiesItem>
                      }
                      { accession.coll.collDate &&
                        <PropertiesItem key="collDate" title={ t(`accessions.common.coll.collDate`) }>
                          <McpdDate value={ accession.coll.collDate } />
                          <AuditedInfo info={ auditAccessionCollect.collDate }/>
                        </PropertiesItem>
                      }
290
291
292
                      { accession.coll &&
                        [ 'collMissId', 'collNumb', 'collSite', 'collSrc' ]
                          .filter((prop) => accession.coll[prop] !== null).map((prop) => (
293
294
295
296
                          <PropertiesItem key={ prop } title={ t(`accessions.common.coll.${prop}`) }>
                            { accession.coll[prop] }
                            <AuditedInfo info={ auditAccessionCollect[prop] }/>
                          </PropertiesItem>
297
                        ))
298
                      }
299
300
301
                      { accession.coll &&
                        [ 'collCode', 'collName' ]
                          .filter((prop) => accession.coll[prop].length).map((prop) => (
302
303
304
305
                          <PropertiesItem key={ prop } title={ t(`accessions.common.coll.${prop}`) }>
                            { accession.coll[prop] }
                            <AuditedInfo info={ auditAccessionCollect[prop] }/>
                          </PropertiesItem>
306
307
308
309
310
                        ))
                      }
                      { accession.geo &&
                        [ 'latitude', 'longitude', 'datum', 'method', 'uncertainty', 'elevation' ]
                          .filter((prop) => accession.geo[prop] !== null).map((prop) => (
311
312
313
314
                          <PropertiesItem key={ prop } title={ t(`accessions.common.geo.${prop}`) }>
                            { accession.geo[prop] }
                            <AuditedInfo info={ auditAccessionGeo[prop] }/>
                          </PropertiesItem>
315
316
317
318
319
                        ))
                      }
                    </Properties>

                    { hasLatLon &&
Maxym Borodenko's avatar
Maxym Borodenko committed
320
                      <LocationMap locations={ [{ id: accession.geo.id, lat: accession.geo.latitude, lng: accession.geo.longitude }] }/>
321
322
323
                    }
                  </PageSection>
                }
Matija Obreza's avatar
Matija Obreza committed
324

325
                { accession.remarks && accession.remarks.length > 0 && <PageSection title={ t('accessions.public.p.display.remarks') }>
326
327
328
329
330
331
                  <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
332

333
334
335
336
337
338
                { files &&
                  <PageSection title={ t('accessions.public.p.display.relatedResources') }>
                    <Properties>
                      { files.map((e: RepositoryFile) => (
                        <PropertiesItem key={ e.uuid } title={
                          <a href={ `/proxy/api/v1/repository/download/${e.uuid}` }>
339
                            <Button variant="contained" component="span">
340
341
342
343
344
345
346
347
348
349
350
                              { t('common:action.download') }
                            </Button>
                          </a>
                        }>
                          <b>{ e.originalFilename }</b>
                        </PropertiesItem>
                      )) }
                    </Properties>
                  </PageSection>
                }

351
                { pdci && <PdciTable pdci={ pdci } title={ t('accessions.public.p.display.pdci') }/> }
Matija Obreza's avatar
Matija Obreza committed
352

353
                <PageSection title={ t('accessions.public.p.display.metadata') }>
354
                  <Properties>
355
356
357
358
                    <PropertiesItem title={ t('common:label.UUID') }>
                      { `urn:uuid:${accession.uuid}` }
                      <AuditedInfo info={ auditAccessionId.uuid }/>
                    </PropertiesItem>
359
360
361
                    <PropertiesItem title={ t('accessions.public.p.display.permanentURL') }><ExternalLink link={ `https://purl.org/germplasm/id/${accession.uuid}` } /></PropertiesItem>
                    <PropertiesItem title={ t('common:label.lastUpdated') }><PrettyDate value={ accession.lastModifiedDate } /></PropertiesItem>
                    <PropertiesItem title={ t('common:label.created') }><PrettyDate value={ accession.createdDate } /></PropertiesItem>
362
363
                  </Properties>
                </PageSection>
364

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
365
                <GridContainer className="mb-15">
366
367
368
                  { datasets && datasets.length > 0 &&
                  <PropertiesCard
                    small
369
                    title={ t('accessions.public.p.display.associatedDatasets') }
370
                    propertyItemProps={ { keepEmpty: true } }
Matija Obreza's avatar
Matija Obreza committed
371
                    propertiesList={ datasets.map((dataset) => ({ value: <DatasetLink to={ dataset } /> })) }
372
373
374
375
376
                  />
                  }
                  { subsets && subsets.length > 0 &&
                  <PropertiesCard
                    small
377
                    title={ t('accessions.public.p.display.associatedSubsets') }
378
                    propertyItemProps={ { keepEmpty: true } }
Matija Obreza's avatar
Matija Obreza committed
379
                    propertiesList={ subsets.map((subset) => ({ value: <SubsetLink to={ subset } /> })) }
380
381
                  />
                  }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
382
                </GridContainer>
383
384
385
              </PageContents>
            }
          </div>
Matija Obreza's avatar
Matija Obreza committed
386
        }
387
388
389
390
391
392
      </PageLayout>
    );
  }
}

const mapStateToProps = (state, ownProps) => ({
393
  accession: state.accessions.public.accession,
394
  auditLog: state.accessions.public.auditLog,
395
  error: state.accessions.public.accessionError,
396
  uuid: ownProps.match.params.uuid,
397
  doi: ownProps.match.params.doi,
398
  accessions: state.list.public.myList.accessions,
399
400
401
});

const mapDispatchToProps = (dispatch) => bindActionCreators({
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
402
403
  addAccessionToMyList,
  removeAccessionFromMyList,
404
  loadAccession,
405
  loadAccessionAuditLog,
Matija Obreza's avatar
Matija Obreza committed
406
  applyFilters,
407
408
409
}, dispatch);


410
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(translate()(BrowsePage)));