Commit ccfb430b authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'api-434-filter-by-genus-species' into 'master'

Api 434 filter by genus species

See merge request genesys-pgr/genesys-ui!279
parents 53edc0d5 7fab3fbf
......@@ -66,7 +66,7 @@
},
"taxa": {
"genus": "Genus",
"species": "Species",
"species": "Specific epithet",
"subtaxa": "Subtaxa"
},
"owner": {
......@@ -77,7 +77,8 @@
},
"taxonomy": {
"genus": "Genus",
"species": "Species",
"species": "Specific epithet",
"genusSpecies": "Species",
"subtaxa": "Subtaxon"
},
"sgsv": "Backup in SGSV",
......@@ -524,7 +525,7 @@
},
"taxonomy": "Taxonomy",
"genus": "Genus",
"species": "Species",
"species": "Specific epithet",
"doi": "DOI",
"sampStat": "Biological status of accession",
"storageType": "Type of germplasm storage",
......@@ -664,7 +665,8 @@
"instituteCode": "Institute code",
"taxonomy": "Taxonomy",
"genus": "Genus",
"species": "Species",
"genusSpecies": "Species",
"species": "Specific epithet",
"doi": "DOI",
"sampStat": "Biological status of accession",
"storageType": "Type of germplasm storage",
......
......@@ -172,7 +172,7 @@
},
"taxonomy": "Taxonomy",
"genus": "Genus",
"species": "Species",
"species": "Specific epithet",
"doi": "DOI",
"sampStat": "Biological status of accession",
"storageType": "Type of germplasm storage",
......@@ -314,7 +314,8 @@
"instituteCode": "Institute code",
"taxonomy": "Taxonomy",
"genus": "Genus",
"species": "Species",
"genusSpecies": "Species",
"species": "Specific epithet",
"doi": "DOI",
"sampStat": "Biological status of accession",
"storageType": "Type of germplasm storage",
......
......@@ -135,7 +135,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
private applyFilterForInstituteSpecies = () => {
const { accession: {details: accession}, applyFilters } = this.props;
const filter = {holder: {code: [ accession.institute.code ]}, taxa: { genus: [ accession.taxonomy.genus ], species: [ accession.taxonomy.species ] }};
const filter = { institute: { code: [accession.institute.code] }, taxonomy: { genusSpecies: [ `${accession.taxonomy.genus} ${accession.taxonomy.species}` ] } };
applyFilters(filter);
}
......
......@@ -30,6 +30,7 @@ import LayersIcon from '@material-ui/icons/Layers';
import ClimateIcon from '@material-ui/icons/WbSunny';
import FilterIcon from '@material-ui/icons/PermDataSetting';
import CancelIcon from '@material-ui/icons/Cancel';
import ApiCall from 'model/ApiCall';
let MapComponent;
......@@ -45,7 +46,7 @@ interface IMapPageProps {
t?: any;
apiUrl: string;
mapInfo: AccessionMapInfo;
mapInfo: ApiCall<AccessionMapInfo>;
suggestions: any;
currentTab: string;
filterCode: string;
......@@ -178,7 +179,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
public componentWillMount() {
const { mapInfo, filterCode, loadAccessionsMapInfo, initialPosition, initialZoom } = this.props;
// console.log(`Filter code for map ${filterCode} ?== ${mapInfo && mapInfo.filterCode}`, filterCode, mapInfo ? mapInfo.filterCode : 'No mapInfo');
if (mapInfo && mapInfo.filterCode !== filterCode) {
if (mapInfo && !mapInfo.loading && mapInfo.data.filterCode !== filterCode) {
// console.log(`mapInfo.filterCode !== filterCode. updatingRoute`);
loadAccessionsMapInfo(filterCode || '', {center: initialPosition, zoom: initialZoom});
} else if (!mapInfo) {
......@@ -269,7 +270,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
return;
}
const {mapInfo: {filter}, geoJsonRequest} = this.props;
const {mapInfo: { data: { filter } }, geoJsonRequest} = this.props;
const correctLng = Math.abs(e.latlng.lng) > 180 ? (360 + e.latlng.lng) % 180 : e.latlng.lng;
......@@ -317,17 +318,21 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
[50, -50],
];
if (! mapInfo) {
if (! mapInfo || mapInfo.loading) {
return <Loading />;
} else if (mapInfo.error) {
return <div>{ mapInfo.error }</div>;
}
if (Math.abs(mapInfo.bounds[0][0] - mapInfo.bounds[1][0]) < Math.abs(initialBounds[0][0] - initialBounds[1][0])) {
initialBounds[0][0] = mapInfo.bounds[0][0];
initialBounds[1][0] = mapInfo.bounds[1][0];
}
if (Math.abs(mapInfo.bounds[0][1] - mapInfo.bounds[1][1]) < Math.abs(initialBounds[0][1] - initialBounds[1][1])) {
initialBounds[0][1] = mapInfo.bounds[0][1];
initialBounds[1][1] = mapInfo.bounds[1][1];
if (mapInfo.data.bounds[0][0] !== null && mapInfo.data.bounds[1][0] !== null) {
if (Math.abs(mapInfo.data.bounds[0][0] - mapInfo.data.bounds[1][0]) < Math.abs(initialBounds[0][0] - initialBounds[1][0])) {
initialBounds[0][0] = mapInfo.data.bounds[0][0];
initialBounds[1][0] = mapInfo.data.bounds[1][0];
}
if (Math.abs(mapInfo.data.bounds[0][1] - mapInfo.data.bounds[1][1]) < Math.abs(initialBounds[0][1] - initialBounds[1][1])) {
initialBounds[0][1] = mapInfo.data.bounds[0][1];
initialBounds[1][1] = mapInfo.data.bounds[1][1];
}
}
const suggestionTerms = new Map();
......@@ -340,7 +345,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
});
}
console.log(suggestionTerms);
// console.log(suggestionTerms);
// const color = 'f00ba0';
const layerUrl = `{s}/acn/tile/{z}/{x}/{y}?f=${filterCode ? filterCode : ''}`; // `&color=${color}`;
......@@ -351,7 +356,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
<ContentHeader title={ t('accessions.public.p.browse.title') } subTitle={ t('accessions.public.p.browse.subTitle') } />
<Drawer variant="temporary" open={ sidebarOpened } onClose={ this.closeSidebar }>
<AccessionsFilters terms={ suggestionTerms } onSubmit={ loadAccessionsMapInfo } initialValues={ mapInfo && mapInfo.filter }/>
<AccessionsFilters terms={ suggestionTerms } onSubmit={ loadAccessionsMapInfo } initialValues={ mapInfo.data.filter }/>
</Drawer>
......@@ -378,10 +383,10 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
</Tabs>
<PrettyFilters
prefix="accessions"
filterObj={ mapInfo && mapInfo.filter || {} }
filterObj={ mapInfo.data.filter || {} }
onSubmit={ this.myApplyFilters }
displayName="accessions.common.modelName"
amount={ mapInfo && mapInfo.accessionCount }
amount={ mapInfo.data.accessionCount }
/>
<div className={ `${classes.leafletContainer} ${trackClickPos && classes.crosshair}` }>
{ loading && <Loading /> }
......@@ -392,7 +397,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
center={ position }
zoom={ initialZoom || 3 } minZoom={ 2 } maxZoom={ 14 }
zoomDelta={ 0.5 }
bounds={ !initialZoom && initialPosition[0] && !initialPosition[1] ? mapInfo.bounds : initialBounds }
bounds={ !initialZoom && initialPosition[0] && !initialPosition[1] ? mapInfo.data.bounds : initialBounds }
ref={ (ref) => this.mapRef = ref }
>
<Control position="topleft">
......@@ -467,7 +472,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
updateWhenZooming={ false }
attribution="&amp;copy Accession localities from <a href=&quot;/&quot;>Genesys PGR</a>"
url={ layerUrl }
subdomains={ mapInfo.tileServers }
subdomains={ mapInfo.data.tileServers }
/>
{ geoData && geoData.length > 0 &&
<Rectangle
......@@ -492,8 +497,7 @@ class BrowsePage extends React.Component<IMapPageProps, any> {
const mapStateToProps = (state, ownProps) => ({
suggestions: state.accessions.public.suggestions,
mapInfo: state.accessions.public.mapInfo ? state.accessions.public.mapInfo.data : undefined,
loading: state.accessions.public.mapInfo ? state.accessions.public.mapInfo.loading : false,
mapInfo: state.accessions.public.mapInfo,
mapLayers: state.accessions.public.mapLayers,
filterCode: ownProps.match.params.filterCode || (state.accessions.public.mapInfo ? state.accessions.public.mapInfo.data && state.accessions.public.mapInfo.data.filterCode : ''),
currentTab: ownProps.match.params.tab || 'map', // current tab, or ownProps.location.pathname
......
......@@ -97,6 +97,7 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
case 'countryOfOrigin.code3':
case 'taxonomy.genus':
case 'taxonomy.species':
case 'taxonomy.genusSpecies':
case 'storage':
_.set(updatedFilter, property, _.concat(_.get(updatedFilter, property), term).filter(x => x != null));
break;
......@@ -203,7 +204,7 @@ class BrowsePage extends React.Component<IOverviewPageProps, any> {
<PropertiesCard propertiesList={ overviewsTerms.get('taxonomy.genus').map((term) => ({title: term.term, value: filterByTerm('taxonomy.genus', term, term.count) })) } title={ t(`accessions.common.overview.taxonomy genus`) } small propertyItemProps={ { numeric: true, classes: {propertiesRowLabel: 'font-italic'} } } />
}
{ overviewsTerms && overviewsTerms.get('taxonomy.genusSpecies') && overviewsTerms.get('taxonomy.genusSpecies').length > 2 &&
<PropertiesCard propertiesList={ overviewsTerms.get('taxonomy.genusSpecies').map((term) => ({title: term.term, value: term.count })) } title={ t(`accessions.common.overview.taxonomy genusSpecies`) } small propertyItemProps={ { numeric: true, classes: {propertiesRowLabel: 'font-italic'} } } />
<PropertiesCard propertiesList={ overviewsTerms.get('taxonomy.genusSpecies').map((term) => ({title: term.term, value: filterByTerm('taxonomy.genusSpecies', term, term.count) })) } title={ t(`accessions.common.overview.taxonomy genusSpecies`) } small propertyItemProps={ { numeric: true, classes: {propertiesRowLabel: 'font-italic'} } } />
}
{ overviewsTerms && overviewsTerms.get('sampStat') && overviewsTerms.get('sampStat').length > 2 &&
<PropertiesCard propertiesList={ overviewsTerms.get('sampStat')
......
......@@ -52,7 +52,20 @@ const AccessionFilters = ({handleSubmit, initialize, terms, crops, t, ...other})
placeholder="Hordeum"
classes={ {propertiesRowLabel: 'font-italic'} }
/>
<StringArrFilter name="taxonomy.species" label={ t('accessions.common.species') } placeholder="vulgare"/>
<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'} }
/>
<StringFilter name="taxonomy.subtaxa" searchType="contains" label={ t('accessions.public.f.subtaxon') } placeholder=""/>
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title={ t('accessions.public.f.originOfMaterial') }>
......
......@@ -14,6 +14,7 @@ class TaxonomyFilter {
public species?: string[];
public subtaxa?: StringFilter;
public version?: number[];
public genusSpecies?: string[];
}
......
......@@ -66,7 +66,7 @@
},
"taxa": {
"genus": "Genus",
"species": "Species",
"species": "Specific epithet",
"subtaxa": "Subtaxa"
},
"owner": {
......@@ -77,7 +77,8 @@
},
"taxonomy": {
"genus": "Genus",
"species": "Species",
"species": "Specific epithet",
"genusSpecies": "Species",
"subtaxa": "Subtaxon"
},
"sgsv": "Backup in SGSV",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment