Filters.tsx 7.94 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
38
39
        <AutocompleteFilter
          filterCode={ filterCode }
          autocomplete={ autocomplete }
          name="institute.code"
          terms={ terms && terms.get('institute.code') }
          label={ t('accessions.common.instituteCode') }
          placeholder="NGA039"
        />
40
41
        <StringArrFilter name="institute.country.code3" label={ t('accessions.model.institute.country.iso3') } placeholder="NGA"/>
        <StringFilter name="accessionNumber" searchType="contains" label={ t('accessions.common.acceNumb') } placeholder="IRGC"/>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
42
        <NumberFilter name="seqNo" label={ t('accessions.public.f.seqNumber') } />
43
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
44
      <CollapsibleComponentSearch title={ t('common:f.dateSearch') }>
Matija Obreza's avatar
Matija Obreza committed
45
        <DateFilter name="createdDate" label={ t('common:f.createdDate') }/>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
46
        <DateFilter name="lastModifiedDate" label={ t('common:f.lastModifiedDate') }/>
47
      </CollapsibleComponentSearch>
48
      <CollapsibleComponentSearch title={ t('accessions.public.f.crop') }>
49
50
51
52
53
54
55
        <StringArrFilter
          name="crop"
          valueField="shortName"
          labelField="name"
          options={ crops }
          terms={ terms && terms.get('crop.shortName') }
        />
56
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
57
      <CollapsibleComponentSearch title={ t('accessions.common.taxonomy') }>
Maxym Borodenko's avatar
Maxym Borodenko committed
58
59
60
        <AutocompleteFilter
          filterCode={ filterCode }
          autocomplete={ autocomplete }
61
62
63
64
65
66
          name="taxonomy.genus"
          terms={ terms && terms.get('taxonomy.genus') }
          label={ t('accessions.common.genus') }
          placeholder="Hordeum"
          classes={ {propertiesRowLabel: 'font-italic'} }
        />
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        <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'} }
        />
81
        <StringFilter name="taxonomy.subtaxa" searchType="contains" label={ t('accessions.public.f.subtaxon') } placeholder=""/>
82
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
83
      <CollapsibleComponentSearch title={ t('accessions.public.f.originOfMaterial') }>
84
        <StringArrFilter name="countryOfOrigin.code3" terms={ terms && terms.get('countryOfOrigin.code3') } label={ t('accessions.common.countryOfOrigin') } placeholder="SVN"/>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
85
86
87
        <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') } />
88
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
89
      <CollapsibleComponentSearch title={ t('accessions.common.sampStat') }>
90
91
92
93
        <StringArrFilter
          name="sampStat"
          options={ Accession.SAMPSTAT }
          byKey
94
          indented
95
96
          terms={ terms && terms.get('sampStat') }
        />
97
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
98
      <CollapsibleComponentSearch title={ t('accessions.common.storageType') }>
99
100
101
102
        <StringArrFilter
          name="storage"
          options={ Accession.STORAGE }
          byKey
103
          indented
104
105
          terms={ terms && terms.get('storage') }
        />
106
      </CollapsibleComponentSearch>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
107
      <CollapsibleComponentSearch title={ t('accessions.public.f.status') }>
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        <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
122
          notNull
123
124
125
126
127
        />
        <BooleanFilter
          name="images"
          label={ t('accessions.public.f.images') }
          terms={ terms && terms.get('images') }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
128
          notNull
129
        />
Oleksii Savran's avatar
Oleksii Savran committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
      </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') } />
151
      </CollapsibleComponentSearch>
152
153
154
155
    </FiltersBlock>
  );
};

156
157
158
159
const mapStateToProps = (state, ownProps) => ({
  crops: state.crop.public.list ? state.crop.public.list.data : undefined,
});

Maxym Borodenko's avatar
Maxym Borodenko committed
160
161
162
163
const mapDispatchToProps = (dispatch) => bindActionCreators({
  autocomplete,
}, dispatch);

Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
164
export default translate()(reduxForm({
165
    enableReinitialize: true,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
166
    destroyOnUnmount: false,
167
    form: ACCESSION_FILTERFORM,
Maxym Borodenko's avatar
Maxym Borodenko committed
168
})(connect(mapStateToProps, mapDispatchToProps)(AccessionFilters)));