Skip to content

Conversation

@zoran995
Copy link
Collaborator

@zoran995 zoran995 commented Aug 11, 2025

What this PR does

Fixes #

During testing the search providers, I discovered that search debounce doesn't work correctly and that we can achieve a better UX when autocomplete is disabled for some search providers.

Before:

  • Try entering more than three characters in the search box and observe that the search is triggered on each change
  • Try searching for mel\ and observe a white screen due to an unescaped regex group

After:

  • When autocomplete is disabled for some search providers, an info message for it is shown saying "Press Enter to start searching"; other search providers will search with autocomplete
  • Search is debounced correctly, and the logic is moved to the search provider mixin level
  • After the enter is pressed, it will start manual search, bypassing the debounce mechanism.
  • Search string is escaped for highlight, resolving the hard error thrown due toan unescaped group
  • Fixed a few potential issues with map credits for search providers
image

Test me

How should reviewers test this? (Hint: If you want to provide a test catalog item, create a Gist of its catalog JSON, add its url and your branch name to this url: http://ci.terria.io/<branch name>/#clean&<raw url of your gist> , and then paste that in the body of this PR)

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

@zoran995 zoran995 requested a review from na9da August 22, 2025 12:20
Comment on lines 90 to 92
get autocompleteEnabled() {
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why override this here when it is already part of LocationSearchProviderTraits and is defaulting to true? Same for the other providers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to be explicit for all search providers, I can remove it if necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was running into a bug that the value wasn't propagated correctly


supportsAutocomplete(): boolean {
return true;
async search(searchText: string, manuallyTriggered?: boolean) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubt: Could you explain when manuallyTriggered is true and why we need to differentiate both?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manuallyTriggered is when the user presses enter to start the search; in that case, we need to cancel the debounce and run the search without waiting

searchState.catalogSearchResults?.results
? searchState.catalogSearchResults.results.map(
searchState.catalogSearchProvider?.result.results
? searchState.catalogSearchProvider.result.results.map(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be catalogSearchProvider.searchResult instead (currently this results in app crash when searching from catalog explorer modal)

Comment on lines +3 to +6
const escapedKeyword = keywordToHighlight.replace(
/[.*+?^${}()|[\]\\]/g,
"\\$&"
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, there is a new RegExp.escape, although it is pretty new.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid moving it for some time, as it is still pretty new although it would work for most of the users, and this is enough to resolve the issue we are currently seeing

@na9da
Copy link
Collaborator

na9da commented Sep 5, 2025

@zoran995 - Looks good, just a few comments.

Copy link
Collaborator

@na9da na9da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search from mobile view must also be fixed.

@zoran995 zoran995 requested a review from na9da October 29, 2025 10:40
@zoran995
Copy link
Collaborator Author

@na9da this is ready for another pass, #7715 builds on top of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants