AccessionOverviewSection.tsx 7.87 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
import { connect } from 'react-redux';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
4
5
// model
import AccessionOverview from '@genesys/client/model/accession/AccessionOverview';
Oleksii Savran's avatar
Oleksii Savran committed
6
import PropertiesCard from 'ui/common/PropertiesCard';
Maksym Tishchenko's avatar
Maksym Tishchenko committed
7
8
9

interface IAccessionOverviewPageProps extends React.ClassAttributes<any> {
  overview: AccessionOverview;
Oleksii Savran's avatar
Redux    
Oleksii Savran committed
10
  countryCodes: Record<string, string>;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
11
12
}

Oleksii Savran's avatar
Redux    
Oleksii Savran committed
13
class AccessionOverviewSection extends React.Component<IAccessionOverviewPageProps & WithTranslation> {
Maksym Tishchenko's avatar
Maksym Tishchenko committed
14
15
16
17
18
19
20
21
22
  public constructor(props) {
    super(props);
  }

  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 render() {
Oleksii Savran's avatar
Redux    
Oleksii Savran committed
23
    const { overview, t, countryCodes } = this.props;
Maksym Tishchenko's avatar
Maksym Tishchenko committed
24
25
26
27
28
29
30
31
32
33
34

    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
35
        terms.push({ term: 'accession.overview.Other', count: overviewEl.other });
Maksym Tishchenko's avatar
Maksym Tishchenko committed
36
37
      }
      if (overviewEl && overviewEl.missing && overviewEl.missing > 0) {
Oleksii Savran's avatar
Oleksii Savran committed
38
        terms.push({ term: 'accession.overview.Not specified', count: overviewEl.missing });
Maksym Tishchenko's avatar
Maksym Tishchenko committed
39
40
41
42
43
      }
      overviewsTerms.set(key, terms);
    });

    return (
44
      <div className="row">
Oleksii Savran's avatar
Oleksii Savran committed
45
        { overviewsTerms && overviewsTerms.get('crop.shortName') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
46
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
47
48
49
            propertiesList={ overviewsTerms.get('crop.shortName') }
            title={ t('accession.overview.crop shortName') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
50
51
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
52
        { overviewsTerms && overviewsTerms.get('cropName') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
53
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
54
55
56
            propertiesList={ overviewsTerms.get('cropName') }
            title={ t('accession.overview.cropName') }
            propertyItemProps={ { numeric: true } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
57
58
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
59
        { overviewsTerms && overviewsTerms.get('taxonomy.genus') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
60
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
61
62
63
            propertiesList={ overviewsTerms.get('taxonomy.genus') }
            title={ t('accession.overview.taxonomy genus') }
            propertyItemProps={ { numeric: true, titleStyle: { fontStyle: 'italic' } } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
64
65
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
66
        { overviewsTerms && overviewsTerms.get('taxonomy.genusSpecies') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
67
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
68
69
70
            propertiesList={ overviewsTerms.get('taxonomy.genusSpecies') }
            title={ t('accession.overview.taxonomy genusSpecies') }
            propertyItemProps={ { numeric: true, titleStyle: { fontStyle: 'italic' } } }
Maksym Tishchenko's avatar
Maksym Tishchenko committed
71
72
73
          />
        }

Oleksii Savran's avatar
Oleksii Savran committed
74
        { overviewsTerms && overviewsTerms.get('taxonomy.grinTaxonomySpecies.name') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
75
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
76
77
78
            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
79
80
          />
        }
Oleksii Savran's avatar
Oleksii Savran committed
81
        { overviewsTerms && overviewsTerms.get('taxonomy.currentTaxonomySpecies.name') &&
Maksym Tishchenko's avatar
Maksym Tishchenko committed
82
          <PropertiesCard
Oleksii Savran's avatar
Oleksii Savran committed
83
84
85
            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
86
87
88
          />
        }

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

Maksym Tishchenko's avatar
Maksym Tishchenko committed
194

Oleksii Savran's avatar
Redux    
Oleksii Savran committed
195
const mapStateToProps = (state) => ({
Oleksii Savran's avatar
Oleksii Savran committed
196
  countryCodes: state.decoding.countryCodes,
Oleksii Savran's avatar
Redux    
Oleksii Savran committed
197
198
199
});

export default connect(mapStateToProps)(withTranslation()(AccessionOverviewSection));