Skip to content
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

feat: 719 - Suggestion Manager with suggestions for the latest input #720

Merged
merged 3 commits into from
Apr 1, 2023

Conversation

monsieurtanuki
Copy link
Contributor

New files:

  • api_suggestion_manager_test.dart: Unit tests for SuggestionManager
  • suggestion_manager.dart: Manager that returns the suggestions for the latest input.

Impacted files:

  • open_food_api_client.dart: added a comment mentioning SuggestionManager.
  • openfoodfacts.dart: exported new file suggestion_manager.dart

What

  • New class SuggestionManager that was needed for autocomplete widgets.
  • We already had a method in order to get suggestions.
  • With the manager, the user sees the most relevant suggestions (that match the latest input), regardless of the time taken by each individual call to the getSuggestions method (typically, when the oldest call takes more time than a more recent call).

Fixes bug(s)

New files:
* `api_suggestion_manager_test.dart`: Unit tests for `SuggestionManager`
* `suggestion_manager.dart`: Manager that returns the suggestions for the latest input.

Impacted files:
* `open_food_api_client.dart`: added a comment mentioning `SuggestionManager`.
* `openfoodfacts.dart`: exported new file `suggestion_manager.dart`
Deleted file:
* `api_get_autocompleted_suggestions_test.dart`: based on a deprecated method

Impacted files:
* `api_get_suggestions_test.dart`: fixed test
* `available_attribute_groups.dart`: now uses `HttpHelper().jsonDecode`
* `available_preference_importances.dart`: now uses `HttpHelper().jsonDecode`
* `events.dart`: now uses `HttpHelper().jsonDecode`
* `folksonomy.dart`: now uses `HttpHelper().jsonDecode`
* `http_helper.dart`: new `jsonDecode` method that deals with typical OFF server html error pages
* `invalid_barcodes.dart`: now uses `HttpHelper().jsonDecode`
* `open_food_api_client.dart`: now uses `HttpHelper().jsonDecode`
* `ordered_nutrient_test.dart`: now uses `HttpHelper().jsonDecode`
* `product_from_json_test.dart`: now uses `HttpHelper().jsonDecode`
* `status.dart`: now uses `HttpHelper().jsonDecode`
@monsieurtanuki monsieurtanuki linked an issue Mar 26, 2023 that may be closed by this pull request
Impacted file:
* `http_helper.dart`: added the "software error" case to `jsonDecode` method
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

Heyy @monsieurtanuki looks great besides some missing documentation in the README

Also, sorry for my late response, but now I'm done with exams for some time at least :D

}

/// cf. https://openfoodfacts.github.io/openfoodfacts-server/reference/api-v3/#get-/api/v3/taxonomy_suggestions
///
/// Consider using [SuggestionManager].
Copy link
Member

Choose a reason for hiding this comment

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

Could you update the README

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you update the README

I will once the code is merged, as I cannot point to the doc of a class that does not exist yet.

@@ -257,7 +260,7 @@ void main() {
test('Suggestions for additives', () async {
List<String> result = await OpenFoodAPIClient.getSuggestions(
TagType.ADDITIVES,
language: OpenFoodFactsLanguage.RUSSIAN,
Copy link
Member

Choose a reason for hiding this comment

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

What impact does this have

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason the test does not pass anymore in Russian.
As we more or less agreed that it was more relevant to run integration tests with server data than unit tests with local json files, once in a while we have to "fix" tests.

@monsieurtanuki monsieurtanuki merged commit 5a31a09 into openfoodfacts:master Apr 1, 2023
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev for your review!

@monsieurtanuki
Copy link
Contributor Author

@M123-dev When is the doc refreshed btw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants