Filters.tsx 8.28 KB
Newer Older
1
import * as React from 'react';
2
import { connect } from 'react-redux';
Maxym Borodenko's avatar
Maxym Borodenko committed
3
import { bindActionCreators } from 'redux';
4
import { reduxForm } from 'redux-form';
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
5
import {translate} from 'react-i18next';
6

7
import { ACCESSION_FILTERFORM } from 'accessions/constants';
8
9
10
11
12
13

import FiltersBlock from 'ui/common/filter/FiltersBlock';
import CollapsibleComponentSearch from 'ui/common/filter/CollapsibleComponentSearch';
import NumberFilter from 'ui/common/filter/NumberFilter';
import StringFilter from 'ui/common/filter/StringFilter';
import StringArrFilter from 'ui/common/filter/StringArrFilter';
Maxym Borodenko's avatar
Maxym Borodenko committed
14
import AutocompleteFilter from 'ui/common/filter/AutocompleteFilter';
15
import Accession from 'model/accession/Accession';
16
import DateFilter from 'ui/common/filter/DateFilter';
17
import BooleanFilter from 'ui/common/filter/BooleanFilter';
Maxym Borodenko's avatar
Maxym Borodenko committed
18
import { autocomplete } from 'accessions/actions/public';
19

Maxym Borodenko's avatar
Maxym Borodenko committed
20
const AccessionFilters = ({handleSubmit, initialValues, initialize, filterCode, autocomplete, terms, crops, t, ...other}) => {
21
22
  // console.log('AccessionFilters', initialValues);
  return (
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
23
24
    <FiltersBlock title={ t('accessions.public.f.filtersTitle') } handleSubmit={ handleSubmit } initialize={ initialize } { ...other }>
      <CollapsibleComponentSearch title={ t('accessions.public.f.historic') }>
25
26
27
        <BooleanFilter
          name="historic"
          terms={ terms && terms.get('historic') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
28
          notNull
29
        />
30
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
31
      <CollapsibleComponentSearch title={ t('common:f.textSearch') }>
Maxym Borodenko's avatar
Maxym Borodenko committed
32
33
34
35
36
37
        <AutocompleteFilter
          filterCode={ filterCode }
          autocomplete={ autocomplete }
          name="institute.code"
          terms={ terms && terms.get('institute.code') }
          label={ t('accessions.common.instituteCode') }
Matija Obreza's avatar
Matija Obreza committed
38
39
40
41
42
43
44
45
46
          placeholder="NGA039, IITA, International"
        />
        <AutocompleteFilter
          filterCode={ filterCode }
          autocomplete={ autocomplete }
          name="institute.country.code3"
          terms={ terms && terms.get('institute.country.iso3') }
          label={ t('accessions.model.institute.country.iso3') }
          placeholder="NGA, Nigeria"
Maxym Borodenko's avatar
Maxym Borodenko committed
47
        />
48
        <StringFilter name="accessionNumber" searchType="contains" label={ t('accessions.common.acceNumb') } placeholder="IRGC"/>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
49
        <NumberFilter name="seqNo" label={ t('accessions.public.f.seqNumber') } />
50
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
51
      <CollapsibleComponentSearch title={ t('common:f.dateSearch') }>
Matija Obreza's avatar
Matija Obreza committed
52
        <DateFilter name="createdDate" label={ t('common:f.createdDate') }/>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
53
        <DateFilter name="lastModifiedDate" label={ t('common:f.lastModifiedDate') }/>
54
      </CollapsibleComponentSearch>
55
      <CollapsibleComponentSearch title={ t('accessions.public.f.crop') }>
56
57
58
59
60
61
62
        <StringArrFilter
          name="crop"
          valueField="shortName"
          labelField="name"
          options={ crops }
          terms={ terms && terms.get('crop.shortName') }
        />
63
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
64
      <CollapsibleComponentSearch title={ t('accessions.common.taxonomy') }>
Maxym Borodenko's avatar
Maxym Borodenko committed
65
66
67
        <AutocompleteFilter
          filterCode={ filterCode }
          autocomplete={ autocomplete }
68
69
70
71
72
73
          name="taxonomy.genus"
          terms={ terms && terms.get('taxonomy.genus') }
          label={ t('accessions.common.genus') }
          placeholder="Hordeum"
          classes={ {propertiesRowLabel: 'font-italic'} }
        />
74
75
76
77
78
79
80
81
82
83
84
85
86
87
        <StringArrFilter
          name="taxonomy.genusSpecies"
          terms={ terms && terms.get('taxonomy.genusSpecies') }
          label={ t('accessions.common.genusSpecies') }
          placeholder="Hordeum vulgare"
          classes={ {propertiesRowLabel: 'font-italic'} }
        />
        <StringArrFilter
          name="taxonomy.species"
          terms={ terms && terms.get('taxonomy.species') }
          label={ t('accessions.common.species') }
          placeholder="vulgare"
          classes={ {propertiesRowLabel: 'font-italic'} }
        />
88
        <StringFilter name="taxonomy.subtaxa" searchType="contains" label={ t('accessions.public.f.subtaxon') } placeholder=""/>
89
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
90
      <CollapsibleComponentSearch title={ t('accessions.public.f.originOfMaterial') }>
Matija Obreza's avatar
Matija Obreza committed
91
92
93
94
95
96
97
98
        <AutocompleteFilter
          filterCode={ filterCode }
          autocomplete={ autocomplete }
          name="countryOfOrigin.code3"
          terms={ terms && terms.get('countryOfOrigin.code3') }
          label={ t('accessions.common.countryOfOrigin') }
          placeholder="SVN, Slovenia"
        />
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
99
100
101
        <NumberFilter name="geo.latitude" label={ t('geo.common.latitude') } />
        <NumberFilter name="geo.longitude" label={ t('geo.common.longitude') } />
        <NumberFilter name="geo.elevation" label={ t('accessions.public.f.elevation') } />
102
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
103
      <CollapsibleComponentSearch title={ t('accessions.common.sampStat') }>
104
105
106
107
        <StringArrFilter
          name="sampStat"
          options={ Accession.SAMPSTAT }
          byKey
108
          indented
109
110
          terms={ terms && terms.get('sampStat') }
        />
111
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
112
      <CollapsibleComponentSearch title={ t('accessions.common.storageType') }>
113
114
115
116
        <StringArrFilter
          name="storage"
          options={ Accession.STORAGE }
          byKey
117
          indented
118
119
          terms={ terms && terms.get('storage') }
        />
120
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
121
      <CollapsibleComponentSearch title={ t('accessions.public.f.status') }>
122
123
124
125
126
127
128
129
130
131
132
133
134
135
        <BooleanFilter
          name="available"
          label={ t('accessions.public.f.available') }
          terms={ terms && terms.get('available') }
        />
        <BooleanFilter
          name="mlsStatus"
          label={ t('accessions.public.f.mlsStatus') }
          terms={ terms && terms.get('mlsStatus') }
        />
        <BooleanFilter
          name="sgsv"
          label={ t('accessions.public.f.sgsv') }
          terms={ terms && terms.get('sgsv') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
136
          notNull
137
138
139
140
141
        />
        <BooleanFilter
          name="images"
          label={ t('accessions.public.f.images') }
          terms={ terms && terms.get('images') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
142
          notNull
143
        />
Oleksii Savran's avatar
Oleksii Savran committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
      </CollapsibleComponentSearch>
      <CollapsibleComponentSearch title={ t('accessions.public.f.climate') }>
        <NumberFilter name="geo.climate.bio1" label={ t('accessions.climate.bio1') } />
        <NumberFilter name="geo.climate.bio2" label={ t('accessions.climate.bio2') } />
        <NumberFilter name="geo.climate.bio3" label={ t('accessions.climate.bio3') } />
        <NumberFilter name="geo.climate.bio4" label={ t('accessions.climate.bio4') } />
        <NumberFilter name="geo.climate.bio5" label={ t('accessions.climate.bio5') } />
        <NumberFilter name="geo.climate.bio6" label={ t('accessions.climate.bio6') } />
        <NumberFilter name="geo.climate.bio7" label={ t('accessions.climate.bio7') } />
        <NumberFilter name="geo.climate.bio8" label={ t('accessions.climate.bio8') } />
        <NumberFilter name="geo.climate.bio9" label={ t('accessions.climate.bio9') } />
        <NumberFilter name="geo.climate.bio10" label={ t('accessions.climate.bio10') } />
        <NumberFilter name="geo.climate.bio11" label={ t('accessions.climate.bio11') } />
        <NumberFilter name="geo.climate.bio12" label={ t('accessions.climate.bio12') } />
        <NumberFilter name="geo.climate.bio13" label={ t('accessions.climate.bio13') } />
        <NumberFilter name="geo.climate.bio14" label={ t('accessions.climate.bio14') } />
        <NumberFilter name="geo.climate.bio15" label={ t('accessions.climate.bio15') } />
        <NumberFilter name="geo.climate.bio16" label={ t('accessions.climate.bio16') } />
        <NumberFilter name="geo.climate.bio17" label={ t('accessions.climate.bio17') } />
        <NumberFilter name="geo.climate.bio18" label={ t('accessions.climate.bio18') } />
        <NumberFilter name="geo.climate.bio19" label={ t('accessions.climate.bio19') } />
165
      </CollapsibleComponentSearch>
166
167
168
169
    </FiltersBlock>
  );
};

170
171
172
173
const mapStateToProps = (state, ownProps) => ({
  crops: state.crop.public.list ? state.crop.public.list.data : undefined,
});

Maxym Borodenko's avatar
Maxym Borodenko committed
174
175
176
177
const mapDispatchToProps = (dispatch) => bindActionCreators({
  autocomplete,
}, dispatch);

Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
178
export default translate()(reduxForm({
179
    enableReinitialize: true,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
180
    destroyOnUnmount: false,
181
    form: ACCESSION_FILTERFORM,
Maxym Borodenko's avatar
Maxym Borodenko committed
182
})(connect(mapStateToProps, mapDispatchToProps)(AccessionFilters)));