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: Add all scanned products to list #3401

Merged
merged 10 commits into from Dec 22, 2022

Conversation

M123-dev
Copy link
Member

@M123-dev M123-dev commented Dec 2, 2022

What

Now you can add all scanned products to a List

@codecov-commenter
Copy link

codecov-commenter commented Dec 2, 2022

Codecov Report

Merging #3401 (ff21ad1) into develop (4a3b1a9) will increase coverage by 0.94%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop    #3401      +/-   ##
===========================================
+ Coverage    10.32%   11.27%   +0.94%     
===========================================
  Files          260      260              
  Lines        12595    12575      -20     
===========================================
+ Hits          1301     1418     +117     
+ Misses       11294    11157     -137     
Impacted Files Coverage Δ
...cards/product_cards/smooth_product_card_found.dart 0.00% <0.00%> (ø)
...ages/smooth_app/lib/database/dao_product_list.dart 0.00% <0.00%> (ø)
...mooth_app/lib/pages/personalized_ranking_page.dart 0.00% <0.00%> (ø)
...smooth_app/lib/pages/product/new_product_page.dart 0.00% <0.00%> (ø)
...app/lib/pages/product_list_user_dialog_helper.dart 0.00% <0.00%> (-0.56%) ⬇️
packages/smooth_app/lib/pages/image_crop_page.dart 0.00% <0.00%> (-1.36%) ⬇️
...ckages/smooth_app/lib/tmp_crop_image/rotation.dart 2.50% <0.00%> (-0.36%) ⬇️
...kages/smooth_app/lib/helpers/analytics_helper.dart 5.00% <0.00%> (-0.13%) ⬇️
packages/smooth_app/lib/main.dart 14.40% <0.00%> (-0.13%) ⬇️
...mooth_app/lib/widgets/smooth_product_carousel.dart 2.45% <0.00%> (-0.07%) ⬇️
... and 21 more

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

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Looks OK @M123-dev, but there is a couple of remarks that are rather important:

  • you should await when you update with async
  • it would be great to code a distinct dialog method that lets the user select user lists (and create new ones)

Feel free to dismiss the other comments.

@github-actions github-actions bot added Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page labels Dec 6, 2022
@M123-dev
Copy link
Member Author

M123-dev commented Dec 6, 2022

I did some refactoring @monsieurtanuki hopefully all your suggestions should be adressed with this

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @M123-dev!
I have the funny impression that you did refactor, but not in the direction I suggested - I had in mind an agnostic selectedLists selectUserLists(allLists, initiallySelectedLists) dialog method.
That doesn't help my review, especially as these days I have limited time to dedicate to the project.
Feel free to ignore my comments and to merge anyway, as long as the code works as intended.

formKey,
textEditingController,
),
onFieldSubmitted: (_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot see the added value of removing method _onNewListValueSubmitted as it's called twice,

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @M123-dev!
Again, I cannot say that there's something obviously wrong in your code, it's just that I imagined a different way to code it - and there are tons of ways to code it anyway.
Feel free to merge any time.

@M123-dev
Copy link
Member Author

M123-dev commented Dec 16, 2022

Sorry for my absence on this PR, had a lot of exams over the last few weeks 😄

Now everything should be done, the lists are preselected if all barcodes to add are included and the dialog is a little more abstract so that it can be reused more often.

Feel free to have a look at the changes or just merge @monsieurtanuki 😃

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @M123-dev!
Obviously you don't like my concept of "method that returns the product lists selected by the user". Fair enough.
Please have a look at my comments: I'm afraid there are some await missing.

packages/smooth_app/lib/database/dao_product_list.dart Outdated Show resolved Hide resolved
.bulkInsert(ProductList.user(name), widget.barcodes.toList());
}
builder: (BuildContext context) => _UserLists(
lists: lists.toSet(),
Copy link
Contributor

Choose a reason for hiding this comment

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

You may loose the order, mayn't you? (for the record that's my first "mayn't you?")

Copy link
Member Author

Choose a reason for hiding this comment

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

https://api.dart.dev/stable/2.18.1/dart-core/Set/toSet.html

Creates a Set with the same elements and behavior as this Set.

The returned set behaves the same as this set with regard to adding and removing elements. It initially contains the same elements. If this set specifies an ordering of the elements, the returned set will have the same order.

Just double checked your may :D
Looks like the order is kept and this wouldn't be a problem would it? The lists in the list screen are also ordered alphabetically

Copy link
Contributor

Choose a reason for hiding this comment

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

If this set specifies an ordering of the elements

I don't know what that means. We just add items. The set itself does not specify anything, does it?
I don't like this dart confusion with tacitly "ordered" Sets.

and this wouldn't be a problem

That would be a minor problem, I'll give you that.

@monsieurtanuki
Copy link
Contributor

Sorry for my absence on this PR, had a lot of exams over the last few weeks 😄

I hope you passed ;)

@M123-dev
Copy link
Member Author

Added the awaits + renamed the one list and no I don't have something against a method which returns the selected lists I only think that it's simpler to understand this way. Returning the lists would mean we have a method which returns the return of a showAlert which would (preferably) show a StatelessWidget which would need to pop them. Doable but not as easy to read.

And thanks 😄

@monsieurtanuki
Copy link
Contributor

Added the awaits + renamed the one list and no I don't have something against a method which returns the selected lists I only think that it's simpler to understand this way.

Then we disagree on that matter. Not a big deal though.

Returning the lists would mean we have a method which returns the return of a showAlert which would (preferably) show a StatelessWidget which would need to pop them. Doable but not as easy to read.

As far as I remember you cannot display a StatelessWidget, you need to refresh the checkboxes and handle the "create list" feature.

And thanks 😄

You're welcome :)

Please get rid of the first LoadingDialog.run(future: daoProductList.getUserLists(), ...), we don't need it because we call it afterwards with more parameters, and we don't need the LoadingDialog either.

And then we're probably done.

@M123-dev
Copy link
Member Author

I removed the loading dialog but we still need the async call for all lists, later we only get the lists which should be selected. daoProductList.getUserLists(withBarcodes: barcodes);

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @M123-dev!
Looks ok to me - you're right, you have to call twice the "getUserLists" method, once for all lists and once for the lists that contain the barcodes.

@@ -224,31 +224,31 @@ class DaoProductList extends AbstractDao {
/// Adds or removes list of barcodes to/from a [productList] in one go (depending on [include])
Future<void> bulkSet(
final ProductList productList,
final List<String> barcodesToAdd, {
List<String> barcodes, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
List<String> barcodes, {
final List<String> barcodes, {

),
) ??
<String>[];
final List<String> selectedLists = await daoProductList.getUserLists(
Copy link
Contributor

Choose a reason for hiding this comment

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

We would be better off calling it in the first place with the parameters, wouldn't we?
cf. just above:

final List<String>? lists = await LoadingDialog.run<List<String>>(
      context: context,
      future: daoProductList.getUserLists(),
    );

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't follow what you mean by this,

having both calls (with and without barcode filter) directly next to eachother?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assumed it was possible to get both data (all lists and all lists with barcodes) with one call, but that's not the case.
You're right: we do need two calls.

.bulkInsert(ProductList.user(name), widget.barcodes.toList());
}
builder: (BuildContext context) => _UserLists(
lists: lists.toSet(),
Copy link
Contributor

Choose a reason for hiding this comment

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

If this set specifies an ordering of the elements

I don't know what that means. We just add items. The set itself does not specify anything, does it?
I don't like this dart confusion with tacitly "ordered" Sets.

and this wouldn't be a problem

That would be a minor problem, I'll give you that.

@M123-dev
Copy link
Member Author

I don't know what that means. We just add items. The set itself does not specify anything, does it?
I don't like this dart confusion with tacitly "ordered" Sets.

I agree with you it's not written very explicitly, my guess is that it just keeps the order of the list. I started switching to sets here so that we avoid dublicates in lists from the ground up.

@monsieurtanuki
Copy link
Contributor

I agree with you it's not written very explicitly, my guess is that it just keeps the order of the list. I started switching to sets here so that we avoid dublicates in lists from the ground up.

I think it's a false good idea. As long as we need sorted collections and that we do handle the duplicates, switching to Set instead of List adds more trouble than it solves.

@M123-dev Anyway, you started this PR 3 weeks ago, the conversation level is 51, I approved 3 times including the latest version 6 hours ago, so without further ado please merge unless something really problematic is still there.

@M123-dev M123-dev merged commit 1cce8cc into develop Dec 22, 2022
@M123-dev M123-dev deleted the feat-Add-als-scanned-products-to-list branch December 22, 2022 11:46
@M123-dev
Copy link
Member Author

Thanks for the review @monsieurtanuki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database 🌐 l10n Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. 🥫 Product page User lists
Development

Successfully merging this pull request may close these issues.

None yet

3 participants