Skip to content

Commit

Permalink
improve: add title and documentation link to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mlluciano committed May 6, 2024
1 parent 64c3820 commit 049b726
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Binary file added mkdocs/docs/assets/suggestions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions mkdocs/docs/portal/suggestions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The iDigBio portal provides a drop down menu with suggested search terms.
These suggestions are purely optional - press the enter key to close the drop down.

![dropdown menu](../assets/suggestions.png)

##### How is the suggestions list populated?

The list is populated with the top scientific names contained in iDigBio data by count, for your search term.

!!! warning "Note that suggestions are based on an aggregation of available data and not any particular taxonomic backbone. This is subject to change in the future."
1 change: 1 addition & 0 deletions mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ nav:
- 'Introduction': 'portal/index.md'
- 'Search Records': 'portal/search.md'
- 'Record Page': 'portal/recordpage.md'
- 'Suggestions': 'portal/suggestions.md'
- API:
- 'Introduction': 'api/index.md'
- Blog:
Expand Down
30 changes: 27 additions & 3 deletions public/client/js/react/src/search/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ $.widget("custom.IDBAutocomplete", $.ui.autocomplete, {
const TextFilter = ({filter, changeFilter, removeFilter, search, aggs}) => {
const [text, setText] = useState(filter.text)
const [dropdownOpen, setDropdownOpen] = useState(false)
const [dropdownOptions, setDropdownOptions] = useState()

useEffect(() => {
const label = renderTitle('Suggestions')
const options = aggs.map((agg) => {
return renderItem(agg.doc_count.toString(), agg.key)
})
setDropdownOptions([{label, options}])
}, [aggs]);

useEffect(() => {
debounce(filter)
}, []);
Expand Down Expand Up @@ -346,6 +356,22 @@ const TextFilter = ({filter, changeFilter, removeFilter, search, aggs}) => {
),
});

const renderTitle = (title) => (
<span>
{title}
<a
style={{
float: 'right',
}}
href="https://idigbio.github.io/idb-portal/portal/suggestions/"
target="_blank"
rel="noopener noreferrer"
>
How is this list populated?
</a>
</span>
);

return(
<div className="option-group filter" id={name+'-filter'} key={name}>
<a className="remove" href="#" onClick={removeFilter} data-remove={name}>
Expand All @@ -355,9 +381,7 @@ const TextFilter = ({filter, changeFilter, removeFilter, search, aggs}) => {
<div className={cl}>
{filter.name === 'scientificname' ? // only field with an aggregation for autocomplete
<AutoComplete
options={aggs.map((agg) => { //dropdown options
return renderItem(agg.doc_count.toString(), agg.key)
})}
options={dropdownOptions}
popupMatchSelectWidth={false} // Allows custom dropdown width
dropdownStyle={{ width: 400 }} // Sets the dropdown width
onSelect={handleSelect}
Expand Down

0 comments on commit 049b726

Please sign in to comment.