AccessionOverviewSection.tsx 8.08 KB
Newer Older
Maksym Tishchenko's avatar
Maksym Tishchenko committed
1
import * as React from 'react';
Oleksii Savran's avatar
Oleksii Savran committed
2
import { withTranslation, WithTranslation } from 'react-i18next';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
3
4
// model
import AccessionOverview from '@genesys/client/model/accession/AccessionOverview';
Oleksii Savran's avatar
Oleksii Savran committed
5
6
import PropertiesCard from 'ui/PropertiesCard';
import { VocabularyService } from '@genesys/client/service';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

interface IAccessionOverviewPageState {
  countryCodes: object;
}

interface IAccessionOverviewPageProps extends React.ClassAttributes<any> {
  overview: AccessionOverview;
}

class AccessionOverviewSection extends React.Component<IAccessionOverviewPageProps & WithTranslation, IAccessionOverviewPageState> {
  public constructor(props) {
    super(props);

    this.state = {
      countryCodes: null,
    }
  }

  private overviewKeys = ['institute.code', 'institute.country.code3', 'cropName', 'crop.shortName', 'sampStat', 'taxonomy.genus', 'taxonomy.genusSpecies',
    'taxonomy.grinTaxonomySpecies.name', 'taxonomy.currentTaxonomySpecies.name',
    'countryOfOrigin.code3', 'donorCode', 'mlsStatus', 'available', 'duplSite', 'sgsv', 'storage', 'breederCode', 'aegis'];

  public async componentDidMount() {
    const codes = await VocabularyService.decode3166Alpha3Terms(this.props.i18n.language);
Oleksii Savran's avatar
Oleksii Savran committed
31
    this.setState({ countryCodes: codes })
Maksym Tishchenko's avatar
Maksym Tishchenko committed
32
33
34
  }

  public render() {
Oleksii Savran's avatar
Oleksii Savran committed
35
    const { overview, t } = this.props;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
36

Oleksii Savran's avatar
Oleksii Savran committed
37
    const { countryCodes } = this.state;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
38
39
40
41
42
43
44
45
46
47
48
49


    if (!overview) {
      return null;
    }

    const overviewsTerms = new Map();

    this.overviewKeys.forEach((key) => {
      const overviewEl = overview[key];
      const terms = overviewEl && overviewEl.terms ? [].concat(overviewEl.terms) : [];
      if (overviewEl && overviewEl.other && overviewEl.other > 0) {
Oleksii Savran's avatar
Oleksii Savran committed
50
        terms.push({ term: 'accession.overview.Other', count: overviewEl.other });
Maksym Tishchenko's avatar
Maksym Tishchenko committed
51
52
      }
      if (overviewEl && overviewEl.missing && overviewEl.missing > 0) {
Oleksii Savran's avatar
Oleksii Savran committed
53
        terms.push({ term: 'accession.overview.Not specified', count: overviewEl.missing });
Maksym Tishchenko's avatar
Maksym Tishchenko committed
54
55
56
57
58
      }
      overviewsTerms.set(key, terms);
    });

    return (
59
      <div className="row">
Oleksii Savran's avatar
Oleksii Savran committed
60
        { overviewsTerms && overviewsTerms.get('crop.shortName') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
61
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
62
63
64
            propertiesList={ overviewsTerms.get('crop.shortName') }
            title={ t('accession.overview.crop shortName') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
65
66
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
67
        { overviewsTerms && overviewsTerms.get('cropName') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
68
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
69
70
71
            propertiesList={ overviewsTerms.get('cropName') }
            title={ t('accession.overview.cropName') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
72
73
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
74
        { overviewsTerms && overviewsTerms.get('taxonomy.genus') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
75
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
76
77
78
            propertiesList={ overviewsTerms.get('taxonomy.genus') }
            title={ t('accession.overview.taxonomy genus') }
            propertyItemProps={ { numeric: true, titleStyle: { fontStyle: 'italic' } } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
79
80
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
81
        { overviewsTerms && overviewsTerms.get('taxonomy.genusSpecies') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
82
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
83
84
85
            propertiesList={ overviewsTerms.get('taxonomy.genusSpecies') }
            title={ t('accession.overview.taxonomy genusSpecies') }
            propertyItemProps={ { numeric: true, titleStyle: { fontStyle: 'italic' } } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
86
87
88
          />
        }

Oleksii Savran's avatar
Oleksii Savran committed
89
        { overviewsTerms && overviewsTerms.get('taxonomy.grinTaxonomySpecies.name') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
90
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
91
92
93
            propertiesList={ overviewsTerms.get('taxonomy.grinTaxonomySpecies.name') }
            title={ t('accession.overview.taxonomy grinTaxonomySpecies') }
            propertyItemProps={ { numeric: true, titleStyle: { fontStyle: 'italic' } } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
94
95
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
96
        { overviewsTerms && overviewsTerms.get('taxonomy.currentTaxonomySpecies.name') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
97
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
98
99
100
            propertiesList={ overviewsTerms.get('taxonomy.currentTaxonomySpecies.name') }
            title={ t('accession.overview.taxonomy currentTaxonomySpecies') }
            propertyItemProps={ { numeric: true, titleStyle: { fontStyle: 'italic' } } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
101
102
103
          />
        }

Oleksii Savran's avatar
Oleksii Savran committed
104
        { overviewsTerms && overviewsTerms.get('sampStat') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
105
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
106
            propertiesList={ overviewsTerms.get('sampStat') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
107
            translationGroup="sampleStatus"
Oleksii Savran's avatar
Oleksii Savran committed
108
109
            title={ t('accession.overview.sampStat') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
110
111
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
112
        { overviewsTerms && overviewsTerms.get('storage') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
113
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
114
            propertiesList={ overviewsTerms.get('storage') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
115
            translationGroup="storage"
Oleksii Savran's avatar
Oleksii Savran committed
116
117
            title={ t('accession.overview.storage') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
118
119
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
120
        { overviewsTerms && overviewsTerms.get('countryOfOrigin.code3') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
121
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
122
123
124
125
            propertiesList={ overviewsTerms.get('countryOfOrigin.code3') }
            countyCodes={ countryCodes }
            title={ t('accession.overview.countryOfOrigin code3') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
126
127
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
128
        { overviewsTerms && overviewsTerms.get('donorCode') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
129
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
130
131
132
            propertiesList={ overviewsTerms.get('donorCode') }
            title={ t('accession.overview.donorCode') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
133
134
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
135
        { overviewsTerms && overviewsTerms.get('duplSite') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
136
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
137
138
139
            propertiesList={ overviewsTerms.get('duplSite') }
            title={ t('accession.overview.duplSite') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
140
141
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
142
        { overviewsTerms && overviewsTerms.get('breederCode') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
143
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
144
145
146
            propertiesList={ overviewsTerms.get('breederCode') }
            title={ t('accession.overview.breederCode') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
147
148
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
149
        { overviewsTerms && overviewsTerms.get('mlsStatus') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
150
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
151
            propertiesList={ overviewsTerms.get('mlsStatus') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
152
            translationGroup="mlsStatus"
Oleksii Savran's avatar
Oleksii Savran committed
153
154
            title={ t('accession.overview.mlsStatus') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
155
156
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
157
        { overviewsTerms && overviewsTerms.get('aegis') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
158
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
159
            propertiesList={ overviewsTerms.get('aegis') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
160
            translationGroup="aegisStatus"
Oleksii Savran's avatar
Oleksii Savran committed
161
162
            title={ t('accession.overview.aegis') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
163
164
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
165
        { overviewsTerms && overviewsTerms.get('available') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
166
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
167
            propertiesList={ overviewsTerms.get('available') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
168
            translationGroup="available"
Oleksii Savran's avatar
Oleksii Savran committed
169
170
            title={ t('accession.overview.available') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
171
172
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
173
        { overviewsTerms && overviewsTerms.get('historic') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
174
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
175
            propertiesList={ overviewsTerms.get('historic') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
176
            translationGroup="historic"
Oleksii Savran's avatar
Oleksii Savran committed
177
178
            title={ t('accession.overview.historic') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
179
180
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
181
        { overviewsTerms && overviewsTerms.get('sgsv') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
182
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
183
            propertiesList={ overviewsTerms.get('sgsv') }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
184
            translationGroup="sgsv"
Oleksii Savran's avatar
Oleksii Savran committed
185
186
            title={ t('accession.overview.sgsv') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
187
188
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
189
        { overviewsTerms && overviewsTerms.get('institute.code') &&
190
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
191
192
193
            propertiesList={ overviewsTerms.get('institute.code') }
            title={ t('accession.overview.institute code') }
            propertyItemProps={ { numeric: true } }
194
195
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
196
        { overviewsTerms && overviewsTerms.get('institute.country.code3') &&
197
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
198
199
200
201
            propertiesList={ overviewsTerms.get('institute.country.code3') }
            countyCodes={ countryCodes }
            title={ t('accession.overview.institute country code3') }
            propertyItemProps={ { numeric: true } }
202
203
          />
        }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
204
205
206
207
208
209
      </div>
    );
  }
}

export default withTranslation()(AccessionOverviewSection);