core-geonetwork
core-geonetwork copied to clipboard
Search reset button not working properly
Describe the bug Search reset button should clean up the search fields and trigger a search to show all the results.
In some cases, the button is clicked and nothing happens. Clicking it a second time, works fine.
The issue happens in 3.12.x
and main
branches.
To Reproduce Steps to reproduce the behavior:
Case 1:
- In the home page, filter by a topic category.
- In the search page, click the reset button --> Search is executed and shows all results
- Go (with the application logo in the top bar) to the home page and select the same topic category
- In the search page, click the Reset button, nothing happens.
- Click the Reset button a second time and then it works
Case 2:
- In the search page, click the search button for an empty search
- Write a search filter and click the search button
- Click reset --> First time doesn't work, second works
Expected behavior Clicking the Reset button once, cleanups the search fields and executes an empty search to return all the results.
Additional context
The code involved it's https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L321-L325
When it doesn't work, executes:
https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L324
the next time, that works, enters in:
https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L322
But if you go directly to the search page, do a search and click reset (that seems working), executes also:
https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L324
A bit unclear what is causing this wrong behaviour.
@fxprunayre
I have done some tests, changing this code:
https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L321-L325
Test 1:
if (angular.equals(params, gnSearchLocation.getParams())) {
triggerSearchFn(false);
} else {
triggerSearchFn(false);
//gnSearchLocation.setSearch(params);
}
When clicking the Reset
button, this seems working cleaning the search fields in the form and issuing a new search, but the URL hash keeps old values.
Doing a search, looks ok.
Test 2:
if (angular.equals(params, gnSearchLocation.getParams())) {
triggerSearchFn(false);
} else {
triggerSearchFn(false);
gnSearchLocation.setSearch(params);
}
When clicking the Reset
button, this seems working cleaning the search fields in the form and issuing a new search, updates the URL hash value. And only issues 1 search to the backend (A bit surprising as initially I was expecting 2).
But doing a search, issues 2 searches to the backend.
It's a bit unclear why it seems sometimes the search triggers a function that prepares and executes the query to ElasticSearch:
https://github.com/geonetwork/core-geonetwork/blob/2731e560fd9e3a8cea16047082cf557d3c0978c5/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L143-L283
And in some other cases, it seems doing that using the $location
directive. What is the criteria for this?
I would reset lastSearchUrl
gnSearchLocation.lastSearchUrl = null;
in https://github.com/geonetwork/core-geonetwork/blob/main/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L357
to avoid https://github.com/geonetwork/core-geonetwork/blob/main/web-ui/src/main/resources/catalog/components/search/searchmanager/SearchFormDirective.js#L332-L333
What do you think ?
@fxprunayre I've tried and it seems working.
I don't fully understand the logic to handle this, but apparently the change works.