-
-
Notifications
You must be signed in to change notification settings - Fork 287
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
fix: #2146 refresh product edition #2201
fix: #2146 refresh product edition #2201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cli1005!
I'm a bit embarrassed because we're currently implementing similar refresh algorithms on similar pages and similar files.
I've just merged code that will sound familiar to you in #2195, especially in edit_product_page.dart
. I suggest that you refresh your code. I also have a pending PR named #2202.
Beyond that, I think that the trick is - when updating a product on the server - to return the server product (not just a bool
), that we reuse without having to query the database.
And a difference we should maybe address now is: when do we save the product? In my latest merge about "stores", I do it when I leave the specific "edit stores" page. I think that you save when you leave the main "edit product" page. My method is safest, your method is smoothest for the end-user.
Thanks for your information, I will check and update my branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cli1005!
Not a big fan actually:
- either you changed the product, and you can get the product directly from
saveAndRefresh
- or you did not change the product, and then you don't need to refresh it as it did not change at all - unless you're very afraid someone else changed it in the meanwhile
The idea behind that being:
- if a page (that is called from the edit product page) changed the product
- that page must pop the edited product (including server and local database, everything done by
saveAndRefresh
) ornull
is nothing happened.
I think it's more robust if the called pages do everything (UI, server, local database, return product if changed).
Of course there's also the option of not saving anything until you quit the main edit page (in order to have frequent "save dialog"s), but that would require more attention about the product state.
Thanks for your suggestions :) But editing image is an exception, since we pass just the barcode instead of an object product, and the page need newly added urls to initialize the carousel, the only way to get all newly added urls is to refetch the product, since as I know, the API of uploading image does not return the new url) |
I do suggest that you return Product, at least for consistency. And btw Nutrients already do use
Yes and maybe no: I coded one method in off-dart that changes the image and returns the new url. There may be a possibility to retrieve the new image url with the methods you're using (maybe not coded yet in off-dart, but possible, still). That said, you're probably right, in that specific case (only) it would be cleaner to refresh the product from the server. I'm currently working on #2204 (probable PR today), which has an obvious impact on class
|
👌 , no problem |
@cli1005 Now #2224 is merged. Basically it adds a "check if logged in" step in |
Codecov Report
@@ Coverage Diff @@
## develop #2201 +/- ##
==========================================
- Coverage 8.86% 7.73% -1.13%
==========================================
Files 161 181 +20
Lines 6623 9096 +2473
==========================================
+ Hits 587 704 +117
- Misses 6036 8392 +2356
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cli1005! Thank you for your changes!
Still, we do things differently and we need to harmonize (your way, my way or a better way).
When I update a product, for instance its categories, I only update its categories, not the whole product (I use the barcode as a key and the categories as a value). From what I read in your code I think that you call the server with the whole product, where you changed what needed to be changed but with tons of unrelated and possibly staled data.
And after I update the product, I get a fresh one from the server. And it looks like you update your dart Product object, possibly call the server that may fail but you don't really care as the fields are already changed in your object.
In short, I'm more cautious because I update the minimum of things (I use a proxy object) and always get a server-refreshed version of the product. In your code, I'm afraid in the end your product may be in a incoherent state.
But maybe I haven't interpreted your code correctly.
if (status == null || status.error != null) { | ||
if (savedAndRefreshed != null) { | ||
return true; | ||
} else { | ||
_errorMessageAlert(appLocalizations.basic_details_add_error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already an error message in saveAndRefresh
. If you don't like the current error message that's normal, we have the make it a parameter in saveAndRefresh
.
@@ -168,39 +166,23 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> { | |||
), | |||
); | |||
|
|||
Future<bool> _saveData(LocalDatabase localDatabase) async { | |||
Future<bool> _saveData( | |||
LocalDatabase localDatabase, Product inputProduct) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First thing first, please add a ',' after inputProduct
.
Then, I would not recommend using the inputProduct
, because you're changing it. You should start from scratch with a new Product()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion, I removed the parameter inputProduct
@@ -168,39 +166,23 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> { | |||
), | |||
); | |||
|
|||
Future<bool> _saveData(LocalDatabase localDatabase) async { | |||
Future<bool> _saveData( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably return a Product?
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably return a
Product?
.
✅
} | ||
|
||
Future<bool> _fetchAndRefresh( | ||
Future<_MetaProductRefresher> _fetchAndRefresh( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_saveAndRefresh
should call this method instead of having to copy its code there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetchAndRefresh calls this method instead
@@ -112,7 +110,21 @@ class _EditProductPageState extends State<EditProductPage> { | |||
); | |||
if (refreshed ?? false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you didn't write it, but I'm sure refreshed == true
is easier to read than refreshed ?? false
.
@@ -112,7 +110,21 @@ class _EditProductPageState extends State<EditProductPage> { | |||
); | |||
if (refreshed ?? false) { | |||
_changes++; | |||
await _refreshProduct(); | |||
//Refetch product if needed for new urls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be more generous in your comment, and explain why you do it there and not in the other places where you code _changes++;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some more details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cli1005!
Thank you for your changes.
I cannot say that I agree with 100% of what I read, but what I'm reflecting about ("a standard way of updating a product") goes beyond this specific PR, so let's go with it!
What
Refresh the edit page after every edit (Basic info, Nutritions, photos)
Screenshot
simulator-screen-recording-iphone-13-2022-06-07-at-114305_VMS9o1rF.mp4
Fixes bug(s)