Skip to content

MBL-2135: SearchAndFilter viewmodel #2247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 10, 2025
Merged

MBL-2135: SearchAndFilter viewmodel #2247

merged 16 commits into from
Mar 10, 2025

Conversation

Arkariang
Copy link
Contributor

@Arkariang Arkariang commented Mar 5, 2025

📲 What

  • ViewModel now handles be able to search terms

🤔 Why

Some background context on why the change is needed.

🛠 How

  • on VM init debuncing searchterm will trigger the query with specific discovery params

    • if serarch term is empty will return sorting popular results
    • if search terms contains any term will return results for the terms and sorting popular.
      ℹ️ (More sorting and filtering options will be extended in follow up tickets)
  • Reftags added when pressing a project result of a search (either with or without terms, take a look at unit tests if more details required).

  • Analytics events triggered with every search query execution ( 1CTA, 1 PAGE_VIEWED) with the discovery params.
    ℹ️ (PAGE_VIEWD) even will be extended with pagination pages information on following tickets.

  • Error handling via red snackbar with generic error message.

  • CancellationException (within KSApolloClient) is not considered an error, when using collectLatest previous suspend functions/flow emissions will be canceled, this is the expected behaviour as we want to execute networking and update UI only with the most recent params and should not be considered an error that requires user feedback.

👀 See

searchExperience.mp4

| | |

📋 QA

  • Either in staging or production perform some terms searching, when there is no search term a collection of "popular" projects will be presented.
  • Try to navigate to some of the project results live or in prelaunch state.

Story 📖

MBL-2135

* @param selectedProject The project selected by the user.
* @return The project and its appropriate ref tag.
*/
private fun projectAndRefTag(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method has been ported directly from the old search experience.

@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 75.90361% with 20 lines in your changes missing coverage. Please review.

Project coverage is 67.71%. Comparing base (2e7adb0) to head (e66fb30).

Files with missing lines Patch % Lines
...tures/search/viewmodel/SearchAndFilterViewModel.kt 83.82% 3 Missing and 8 partials ⚠️
...arter/ui/activities/compose/search/SearchScreen.kt 40.00% 8 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2247      +/-   ##
============================================
+ Coverage     67.69%   67.71%   +0.02%     
- Complexity     2204     2219      +15     
============================================
  Files           360      360              
  Lines         24357    24419      +62     
  Branches       3582     3593      +11     
============================================
+ Hits          16488    16535      +47     
- Misses         5987     5999      +12     
- Partials       1882     1885       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if (debouncedTerm.isEmpty() || debouncedTerm.isBlank()) {
_params.emit(popularDiscoveryParam)
} else
_params.emit(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In future additions, with category selection or project sort, there will be inputs to this VM (similar to updateSearchTerm) that will add new emissions to _params with each user selection.
In the future will likely not collect searchTerm chain but rather params

assertEquals(eCounter, 1)
assertEquals(exception?.message, "Something went wrong")
}
// @Test
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will create a separate ticket for this one.
This test is failing on CI, but working fine when launched locally 😮‍💨

@Arkariang Arkariang self-assigned this Mar 6, 2025
@Arkariang Arkariang marked this pull request as ready for review March 6, 2025 17:31
@@ -1911,6 +1912,9 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient
private suspend fun <T> executeForResult(block: suspend () -> T): Result<T> =
try {
Result.success(block())
} catch (cancellationException: CancellationException) {
// - When using try catch blocks with suspending functions always rethrow CancellationExceptions and not threat them as an error
throw cancellationException
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👌


viewModel.provideErrorAction { message ->
lifecycleScope.launch {
snackbarHostState.showSnackbar(
Copy link
Contributor

Choose a reason for hiding this comment

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

Might enqueue multiple snackbars while searching

Copy link
Contributor

@tonyteate tonyteate left a comment

Choose a reason for hiding this comment

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

Lgtm! 👍

@Arkariang Arkariang merged commit 22e685d into master Mar 10, 2025
3 checks passed
@Arkariang Arkariang deleted the imartin/MBL-2135 branch March 10, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants