Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
21 stars 12 forks source link

feat(openchallenges): implement lazy loading in searchable dropdown filters on search pages #2637

Closed rrchai closed 1 month ago

rrchai commented 2 months ago

Changelogs

Preview

Recording 2024-05-14 at 01 15 34


The bug #2648 is not fixed in this PR, as I think it needs extra backend support, i.e. filter input data types by its ids, which will be saved for another PRs.

rrchai commented 1 month ago

The lazyLoad is enabled in all search dropdown filters, but I need more time to test the behavior when the search term is applied. I will also try to consolidate the multiple lazyLoad functions for different filters into one generic function to reduce codes.

rrchai commented 1 month ago

Currently, when users scroll down the results, it will trigger to query next page results (0...N) with constant page size. The new scrolled results will be appended to the existing results. To avoid duplicated queries, the page number is checked to make sure the same page is only loaded once.

However, when the search term is applied, the pagination of query results are different, which could lead to miss or duplicate results. I am checking ...

rrchai commented 1 month ago

Notes on Managing BehaviorSubject with Object Types

When using a BehaviorSubject to emit objects in RxJS (like debounceTime()), ensure to create a new object when updating the value emitted by a BehaviorSubject:


private platformSearchQuery: BehaviorSubject<ChallengePlatformSearchQuery> =
    new BehaviorSubject<ChallengePlatformSearchQuery>({});

setPlatformSearch(searchQuery: ChallengePlatformSearchQuery) {
    this.platformSearchQuery.next(searchQuery); // No
    this.platformSearchQuery.next({ ...searchQuery }); // Yes
}
tschaffter commented 1 month ago

ensure to create a new object when updating the value emitted by a BehaviorSubject:

Why?

Note that using the spread operator results in a shallow copy of the object. For deep copy, I am using cloneDeep from lodash.

rrchai commented 1 month ago

Why?

Note that using the spread operator results in a shallow copy of the object. For deep copy, I am using cloneDeep from lodash.

If I don't copy or force the change on the object as BehaviorSubject, the debounceTime(400) will not work as expected. Instead of waiting for 400ms, it will trigger the change as soon as I type something in search bar. I didn't look into the exactly reason, but using the spread operator seem to work on my end. I am open to change to deep copy if that's necessary.

rrchai commented 1 month ago

I will try to address two more issues for the search filters before making this pr open:

tschaffter commented 1 month ago

@rrchai Converting the PR back to draft since I saw that you made new commits. Please turn in back to Ready for review when ready.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed for 'openchallenges-app'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

tschaffter commented 1 month ago

Further exploration is needed about the flickering. The issue will be fixed in another PR.