DisplayPage.tsx 1.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';

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

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

// UI
import PageLayout, { PageContents } from 'ui/layout/PageLayout';
import ContentHeader from 'ui/common/heading/ContentHeader';
import Loading from 'ui/common/Loading';
import AccessionCard from 'ui/genesys/accession/AccessionCard';

interface IBrowsePageProps extends React.ClassAttributes<any> {
  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
28
      return uuid ? loadAccession(uuid) : null;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    },
  ];

  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() {
    const { error, accession, uuid } = this.props;
    const stillLoading: boolean = ! error && (! accession || (uuid && accession && accession.uuid !== uuid));

    return (
      <PageLayout>

        <ContentHeader title="Accession" />

        <PageContents>
          { stillLoading && <Loading /> }
          { error && <div>{ JSON.stringify(error) }</div> }
          { accession && <AccessionCard accession={ accession } /> }
        </PageContents>
      </PageLayout>
    );
  }
}

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

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


export default connect(mapStateToProps, mapDispatchToProps)(BrowsePage);