Skip to content

Commit aee2804

Browse files
committed
relates to hhttps://github.com/gbif/hosted-portals/issues/224
1 parent 20f7236 commit aee2804

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

packages/graphql-api/src/resources/gbif/taxon/taxon.source.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TaxonAPI extends RESTDataSource {
8181
qField: 'SCIENTIFIC'
8282
}
8383
});
84+
responseScientific.results.forEach(x => {delete x.vernacularNames});
8485
scientificResults = responseScientific.results;
8586
}
8687

packages/react-components/locales/source/en-developer/components/filterSupport.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
"updateFilter": "Update filter",
1919
"setFilter": "Set as filter",
2020
"nameWithTaxonMatchIssue": "Name before normalisation",
21+
"commonName": "Common name",
22+
"acceptedNameOf": "Accepted name for",
2123
"viewDetails": "View details"
2224
}

packages/react-components/src/utils/suggestConfig/getCommonSuggests.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,67 @@ export function getCommonSuggests({ context, suggestStyle, rootPredicate }) {
364364
</div>
365365
}
366366
},
367+
taxonKeyVernacular: {
368+
//What placeholder to show
369+
// placeholder: 'Search by scientific name',
370+
placeholder: 'search.placeholders.default',
371+
// how to get the list of suggestion data
372+
getSuggestions: ({ q, localeContext }) => {
373+
const language = localeContext?.localeMap?.iso3LetterCode ?? 'eng';
374+
const SEARCH = `
375+
query($q: String, $language: Language){
376+
taxonSuggestions( q: $q, language: $language) {
377+
key
378+
scientificName
379+
vernacularName
380+
taxonomicStatus
381+
acceptedNameOf
382+
classification {
383+
name
384+
}
385+
}
386+
}
387+
`;
388+
const { promise, cancel } = client.query({ query: SEARCH, variables: {q, language: language} });
389+
return {
390+
promise: promise.then(response => {
391+
return {
392+
data: response.data?.taxonSuggestions.map(i => i),
393+
}
394+
}),
395+
cancel
396+
}
397+
},
398+
// how to map the results to a single string value
399+
getValue: suggestion => suggestion.scientificName,
400+
// how to display the individual suggestions in the list
401+
render: function ScientificNameSuggestItem(suggestion) {
402+
const ranks = suggestion.classification.map((rank, i) => <span key={i}>{rank.name}</span>);
403+
404+
const commonNameTranslation = formatMessage({ id: `filterSupport.commonName` });
405+
const acceptedNameOfTranslation = formatMessage({ id: `filterSupport.acceptedNameOf` });
406+
407+
return <div style={{ maxWidth: '100%' }}>
408+
<div style={suggestStyle}>
409+
{suggestion.taxonomicStatus !== 'ACCEPTED' && <Tooltip title={<span><FormattedMessage id={`enums.taxonomicStatus.${suggestion.taxonomicStatus}`} /></span>}>
410+
<span style={{ display: 'inline-block', marginRight: 8, width: 8, height: 8, borderRadius: 4, background: 'orange' }}></span>
411+
</Tooltip>}
412+
{suggestion.scientificName}
413+
</div>
414+
{suggestion.vernacularName && <div style={{ marginBottom: 8, color: '#888', fontSize: '0.85em', lineHeight: 1.2 }}>
415+
<div>{commonNameTranslation}: <span style={{ color: '#555'}}>{suggestion.vernacularName}</span></div>
416+
</div>}
417+
{!suggestion.vernacularName && suggestion.acceptedNameOf && <div style={{ marginBottom: 8, color: '#888', fontSize: '0.85em', lineHeight: 1.2 }}>
418+
<div>{acceptedNameOfTranslation}: <span style={{ color: '#555'}}>{suggestion.acceptedNameOf}</span></div>
419+
</div>}
420+
<div style={{ color: '#aaa', fontSize: '0.85em' }}>
421+
<Classification>
422+
{ranks}
423+
</Classification>
424+
</div>
425+
</div>
426+
}
427+
},
367428
eventTaxonKey: {
368429
//What placeholder to show
369430
// placeholder: 'Search by scientific name',

0 commit comments

Comments
 (0)