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: 3941 - refactoring about up-to-date product data for StatefulWidgets #4262

Merged
merged 5 commits into from
Jul 13, 2023

Conversation

monsieurtanuki
Copy link
Contributor

What

  • Refactoring about up-to-date product data for StatefulWidgets.
  • The code is a bit cleaner (e.g. less fields).
  • That gives a better view of future improvements (e.g. being able to say to the user that the nutriscore is perhaps out of sync because for that product there are pending changes on category and we're waiting for the server response cf. Weird behavior with the cache #4254)

Fixes bug(s)

Files

New file:

  • up_to_date_manager.dart: Provides the most up-to-date local product data for a StatefulWidget.

Impacted files:

  • add_new_product_page.dart: now using new class UpToDateManager
  • edit_new_packagings.dart: now using new class UpToDateManager
  • edit_ocr_page.dart: now using new class UpToDateManager
  • edit_product_page.dart: now using new class UpToDateManager
  • knowledge_panel_page.dart: now using new class UpToDateManager
  • new_product_page.dart: now using new class UpToDateManager
  • nutrition_page_loaded.dart: now using new class UpToDateManager
  • product_image_gallery.dart: now using new class UpToDateManager
  • product_image_swipeable.dart: now using new class UpToDateManager
  • product_image_viewer.dart: now using new class UpToDateManager
  • summary_card.dart: now using new class UpToDateManager

…dgets

New file:
* `up_to_date_manager.dart`: Provides the most up-to-date local product data for a StatefulWidget.

Impacted files:
* `add_new_product_page.dart`: now using new class `UpToDateManager`
* `edit_new_packagings.dart`: now using new class `UpToDateManager`
* `edit_ocr_page.dart`: now using new class `UpToDateManager`
* `edit_product_page.dart`: now using new class `UpToDateManager`
* `knowledge_panel_page.dart`: now using new class `UpToDateManager`
* `new_product_page.dart`: now using new class `UpToDateManager`
* `nutrition_page_loaded.dart`: now using new class `UpToDateManager`
* `product_image_gallery.dart`: now using new class `UpToDateManager`
* `product_image_swipeable.dart`: now using new class `UpToDateManager`
* `product_image_viewer.dart`: now using new class `UpToDateManager`
* `summary_card.dart`: now using new class `UpToDateManager`
@monsieurtanuki monsieurtanuki requested a review from a team as a code owner July 1, 2023 16:55
@github-actions github-actions bot added 🥫 Product page Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. summary card ✏️ Editing - Nutrition input ✏️ Editing - Packaging input Related to the structured input of food packaging. labels Jul 1, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2023

Codecov Report

Merging #4262 (c2ecb0a) into develop (cac58a2) will increase coverage by 0.02%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #4262      +/-   ##
===========================================
+ Coverage    10.79%   10.82%   +0.02%     
===========================================
  Files          287      288       +1     
  Lines        14288    14251      -37     
===========================================
  Hits          1542     1542              
+ Misses       12746    12709      -37     
Impacted Files Coverage Δ
...s/smooth_app/lib/data_models/up_to_date_mixin.dart 0.00% <0.00%> (ø)
...e_panel/knowledge_panels/knowledge_panel_page.dart 0.00% <0.00%> (ø)
...th_app/lib/pages/product/add_new_product_page.dart 0.00% <0.00%> (ø)
...oth_app/lib/pages/product/edit_new_packagings.dart 0.00% <0.00%> (ø)
...es/smooth_app/lib/pages/product/edit_ocr_page.dart 0.00% <0.00%> (ø)
...mooth_app/lib/pages/product/edit_product_page.dart 0.51% <0.00%> (+0.01%) ⬆️
...smooth_app/lib/pages/product/new_product_page.dart 0.00% <0.00%> (ø)
...h_app/lib/pages/product/nutrition_page_loaded.dart 0.00% <0.00%> (ø)
.../lib/pages/product/product_image_gallery_view.dart 0.00% <0.00%> (ø)
...ib/pages/product/product_image_swipeable_view.dart 0.00% <0.00%> (ø)
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

/// * we get the most up-to-date local product data
/// * we re-launch the task manager if relevant
/// * we track the barcodes currently "opened" by the app
class UpToDateManager {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't use a mixin here?
As it's specifically design for a StatefullWidget, it would simplify the integration

Otherwise, looks OK 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@g123k Thank you for the suggestion! I edited the code in the latest push: my first experience with mixin.

Not 100% convinced in that particular case, specifically because we somehow need a constructor - replaced by an "init" method as mixin doesn't accept constructors.
In the end, it looks a bit better than before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I clearly prefer this implementation, even if indeed the number of lines is similar.

(I am also very sorry, I receive random notifications from GitHub, and I totally missed your answer)

@monsieurtanuki monsieurtanuki requested a review from g123k July 7, 2023 15:35
@g123k g123k merged commit 4f35708 into openfoodfacts:develop Jul 13, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Editing - Nutrition input ✏️ Editing - Packaging input Related to the structured input of food packaging. Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page summary card
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring of UpToDateProvider
3 participants