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

[BUU] Add option to delete a product or variant #11846

Conversation

chahmedejaz
Copy link
Collaborator

@chahmedejaz chahmedejaz commented Nov 22, 2023

What? Why?

What should we test?

  • All the scenarios mentioned in the linked issue

Change log Category:

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

@chahmedejaz chahmedejaz force-pushed the task/11068-delete-product-or-variant branch 4 times, most recently from 86446a4 to 8541bb1 Compare December 3, 2023 18:29
@dacook
Copy link
Member

dacook commented Dec 5, 2023

Hi @chahmedejaz , looks like you've done lots of work on this, which is great. I was just wondering if you could give a rough indication of how long until it will be ready for review?
Thanks in advance.

@chahmedejaz
Copy link
Collaborator Author

Hi @chahmedejaz , looks like you've done lots of work on this, which is great. I was just wondering if you could give a rough indication of how long until it will be ready for review?
Thanks in advance.

I'm almost done with it.
Just need to create a reflex action to delete variants and the test cases. Maybe a day or 2 max.
Except for those, the user feedback message will remain.

P.S. Sorry for taking this long, actually got sick in between and couldn't work for a good chunk.😅

@dacook
Copy link
Member

dacook commented Dec 5, 2023

That's ok, sorry to hear you've been sick, I hope you're feeling better soon.

Thanks for trying out a reflex action, then we can use the loading indicator consistently 👍

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Hi Ahmed, I've reviewed and overall I think you've done a great job pulling all this together into a workable solution.

I have a few suggestions for changes (those marked with ±), can you please review these and let me know what you think?

Also one more thing: you don't need to add the issue ID to every commit message, because the PR is already linked to the issue.
This creates a lot of unnecessary comments on the issue, so could you please leave them out next time?

app/components/confirm_modal_component.rb Outdated Show resolved Hide resolved
app/components/confirm_modal_component.rb Outdated Show resolved Hide resolved
app/services/product_deleter.rb Outdated Show resolved Hide resolved
app/reflexes/products_reflex.rb Outdated Show resolved Hide resolved
app/webpacker/controllers/products_controller.js Outdated Show resolved Hide resolved
app/views/admin/products_v3/_delete_modals.html.haml Outdated Show resolved Hide resolved
@chahmedejaz
Copy link
Collaborator Author

chahmedejaz commented Dec 13, 2023

you don't need to add the issue ID to every commit message, because the PR is already linked to the issue.
This creates a lot of unnecessary comments on the issue, so could you please leave them out next time?

Sure, David. I'll take care of this next time. :)
I just have the habit of linking commits to the issue as it helps to keep track of in which issue the commit was added.
From now I'll just add the ID in the commit without the hash. This wouldn't create a comment for the commit on the issue.
Does that work?

Edit: Had to rebase to resolve the conflict, and this recreated all of the commits. And the commits having issue references are again commented on the issue 😅 Sorry about that. I'll avoid the direct issue reference in the commit message in future PRs.

@chahmedejaz
Copy link
Collaborator Author

Thank you for your comments, David. Let me incorporate those and get back to you. Thanks. 😄

@chahmedejaz
Copy link
Collaborator Author

The test seems flaky as:
It's working as expected on my machine:
image
But getting failed on the GitHub workflow😅 :
image

@sigmundpetersen
Copy link
Contributor

I re-ran the failed build.
One of the failures was flaky.
But the other seems persistent, could you look into it?

@chahmedejaz
Copy link
Collaborator Author

chahmedejaz commented Dec 19, 2023

I re-ran the failed build. One of the failures was flaky. But the other seems persistent, could you look into it?

Those specs are working fine on my machine, strange 😅
image

I looked into the issue further, seems like a file is missing in the test env which should be created by the code itself. Can you please rerun the build, maybe it gets created. Thank you.

@chahmedejaz
Copy link
Collaborator Author

Thank you @sigmundpetersen for your help here. That's strange my changes are not even related 😢
Let me dig into it further.

@sigmundpetersen
Copy link
Contributor

Ok, I think we need the perspective from a @openfoodfoundation/core-devs on this

@chahmedejaz
Copy link
Collaborator Author

if you could change the container padding to 1.2rem

Hey @mariocarabotta - I've updated the modal container padding to 1.2rem. Please review and let me know how it looks. Thanks.
image

@mariocarabotta mariocarabotta added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Dec 27, 2023
@mariocarabotta
Copy link
Collaborator

if you could change the container padding to 1.2rem

Hey @mariocarabotta - I've updated the modal container padding to 1.2rem. Please review and let me know how it looks. Thanks. image

perfect! all good from my side - great job

@mariocarabotta
Copy link
Collaborator

created a separate issue for dealing with the above scenario mentioned by Maikel.

Don't reload whole table when table menu actions are performed

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

We're getting there! I have a couple of suggestions for simplifying some logic, and some questions.

app/views/admin/products_v3/_table.html.haml Outdated Show resolved Hide resolved
app/reflexes/products_reflex.rb Outdated Show resolved Hide resolved
app/views/admin/products_v3/_delete_modal.html.haml Outdated Show resolved Hide resolved
app/webpacker/controllers/product_actions_controller.js Outdated Show resolved Hide resolved
spec/system/admin/products_v3/products_spec.rb Outdated Show resolved Hide resolved
app/reflexes/products_reflex.rb Show resolved Hide resolved
@drummer83 drummer83 added the pr-staged-uk staging.openfoodnetwork.org.uk label Dec 28, 2023
@drummer83 drummer83 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Dec 28, 2023
@dacook
Copy link
Member

dacook commented Dec 28, 2023

I've reviewed Maikel's comments and I think we're all good for testing now! ⏩

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Great improvements, thank you.

The spec can still be improved but that shouldn't block the whole pull request. We can work on that separately.

Comment on lines +629 to +635
# Wait for an element with the given CSS selector and class to be present
def wait_for_class(selector, class_name)
max_wait_time = Capybara.default_max_wait_time
Timeout.timeout(max_wait_time) do
sleep(0.1) until page.has_css?(selector, class: class_name, visible: false)
end
end
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be necessary because has_css? waits already. It should be the same as:

Suggested change
# Wait for an element with the given CSS selector and class to be present
def wait_for_class(selector, class_name)
max_wait_time = Capybara.default_max_wait_time
Timeout.timeout(max_wait_time) do
sleep(0.1) until page.has_css?(selector, class: class_name, visible: false)
end
end
# Wait for an element with the given CSS selector and class to be present
def wait_for_class(selector, class_name)
page.has_css?(selector, class: class_name, visible: false)
end

But I guess that it didn't work? I wonder why...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • It works when used with visible visible: false as suggested.
  • page.has_css?(selector, class: class_name, visible: false) returns a boolean and I thought it would make more sense to use it as a boolean. 😅 i.e. if the loader is still not hidden, then make sure to wait until it's hidden.
  • If it is already hidden as the result of the wait in has_css? then the implemented sleep(0.1) won't be triggered.

If we still wanna commit the suggestion, then please let me know. No worries, we can. :)

Copy link
Member

Choose a reason for hiding this comment

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

This PR is ready for testing already. I don't want to delay it. We can optimise specs another time.

@RachL RachL added the pr-staged-fr staging.coopcircuits.fr label Jan 8, 2024
@RachL RachL self-assigned this Jan 8, 2024
@RachL
Copy link
Contributor

RachL commented Jan 8, 2024

I haven't managed to reproduce a failed deletion action. Other than that all 13 other scenario do work, thank so much @chahmedejaz !

@mariocarabotta as I'm merging you should have the action available next time you stage something or if you stage master/main branch.

@RachL RachL merged commit bd0a296 into openfoodfoundation:master Jan 8, 2024
54 checks passed
@RachL RachL removed the pr-staged-fr staging.coopcircuits.fr label Jan 8, 2024
@chahmedejaz
Copy link
Collaborator Author

I haven't managed to reproduce a failed deletion action.

Thanks for validating this, @RachL
Actually this scenario is very rare to reproduce in a production environment.
It will happen when the delete database transaction fails. It's unlikely to happen I believe.
However for the sake of validation, a dev can forcefully reproduce this scenario locally.
Please let me know if want me to share the loom for this. Thanks 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[BUU] Delete a product or variant
7 participants