Skip to content

Conversation

@AdamGrzybkowski
Copy link
Contributor

Closes WOOMOB-1378

Description

From the issue description:

After creating a new product, the “Trash product” button isn’t visible. It only appears after navigating back and reopening the product.

This is cause becase the trashEnabled destination argument defaulted to false when the fragment was opened from the bottom sheet. We can't simply change it to true because the same bottom sheet is used in other places, and we can only enable that option when the product details screen is opened from the product list screen.
Adding the same value as a bottom sheet destination argument would be an option, but that would create a long chain of passing arguments, because the above-mentioned bottom sheet is opened from yet another bottom sheet. It would be a pain to write and maintain.

As proposed by @hichamboushaba this PR removed the destination argument completely, and instead checked whether the product list is in the backstack.

Steps to reproduce

  1. Open the product list screen
  2. Tap on the FAB to create a new product
  3. Tap Add manually
  4. Pick a product type
  5. Tap publish
  6. Tap on the ... menu icon
  7. Verify Trash product option visibility

Testing information

The above steps are good to reproduce the bug and verify it's fixed.

Additionally, it's good to test other entry points for the Product details screen. One example is shown below, where the product is created from the onboarding checklist.

The tests that have been performed

  1. New product from product list.
  2. New product from onboarding checklist.
  3. Opening a product from the product list and verifying the option is visible.

Images/gif

Bug

Before After
product_list_flow_before product_list_flow_after

Regression test (should be the same):

Before After
onboarding_flow_before onboarding_flow_after
existing_product_before existing_product_after
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@AdamGrzybkowski AdamGrzybkowski added this to the 23.4 milestone Sep 25, 2025
@AdamGrzybkowski AdamGrzybkowski added feature: product details Related to adding or editing products, includes product settings. Bug labels Sep 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where the "Trash Product" option was not visible after creating a new product from the product list screen. The issue occurred because the trash option was controlled by a destination argument that defaulted to false.

  • Replaced the destination argument-based approach with a backstack-based check to determine when trash should be enabled
  • Removed the isTrashEnabled navigation argument from all product detail navigation calls
  • Added comprehensive tests to verify the trash option visibility logic

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ProductDetailFragment.kt Implements backstack checking logic to determine trash option visibility
ProductDetailViewModel.kt Replaces destination argument with StateFlow-based trash action control
ProductDetailViewModelTest.kt Adds comprehensive tests for trash option visibility scenarios
nav_graph_main.xml Removes isTrashEnabled navigation argument definitions
nav_graph_products.xml Removes isTrashEnabled navigation argument definitions
ProductListFragment.kt Removes isTrashEnabled argument from navigation calls
MainNavigationRouter.kt Updates interface to remove enableTrash parameters
MainActivity.kt Updates implementation to remove enableTrash parameters
DashboardTopPerformersWidgetCard.kt Removes isTrashEnabled argument from navigation call
DashboardProductStockCard.kt Removes isTrashEnabled argument from navigation call

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 25, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commita262969
Direct Downloadwoocommerce-wear-prototype-build-pr14657-a262969.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 25, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commita262969
Direct Downloadwoocommerce-prototype-build-pr14657-a262969.apk

@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.44%. Comparing base (f8018cf) to head (a262969).
⚠️ Report is 5 commits behind head on trunk.

Files with missing lines Patch % Lines
...oocommerce/android/ui/main/MainNavigationRouter.kt 0.00% 1 Missing ⚠️
...roid/ui/products/details/ProductDetailViewModel.kt 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #14657   +/-   ##
=========================================
  Coverage     38.43%   38.44%           
  Complexity     9798     9798           
=========================================
  Files          2081     2081           
  Lines        116124   116123    -1     
  Branches      15498    15500    +2     
=========================================
+ Hits          44638    44644    +6     
+ Misses        67339    67332    -7     
  Partials       4147     4147           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hichamboushaba hichamboushaba self-assigned this Sep 25, 2025
Copy link
Member

@hichamboushaba hichamboushaba left a comment

Choose a reason for hiding this comment

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

Nice work @AdamGrzybkowski 💯, pre-approving, I left two minor comments, but nothing blocking.

get() = viewModel.productDetailViewStateData.liveData.value?.productDraft

@Test
fun `given add new product flow, when trash action becomes possible, then trashOption remains hidden`() =
Copy link
Member

Choose a reason for hiding this comment

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

not a blocker, but I think we can make this test name clearer, the trash button can be available in the product creation flow, the important bit that controls whether the trash button is hidden not, is whether the product was created on the server or not yet. The current name makes it look like the trash button will always be hidden in the creation flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test doesn't verify that flow, but rather simply checks based on the initial conditions. In this case, for the AddNewProduct flow, the trash should be invisible.

That said, I think it's good to test the flow mentioned when the product is stored so I've added it here - f848f65

Copy link
Member

Choose a reason for hiding this comment

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

This test doesn't verify that flow, but rather simply checks based on the initial conditions. In this case, for the AddNewProduct flow, the trash should be invisible.

Yes I'm aware, I suggested just modifying the test name, not the test itself 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, what about: given add new product flow when product not yet created on server then trashOption is hidden?

Copy link
Member

Choose a reason for hiding this comment

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

I like it, it's clear. Thanks @AdamGrzybkowski

@AdamGrzybkowski AdamGrzybkowski force-pushed the issue/WOOMOB-1378_trash_product_invisible branch from 878d7fd to 5c49211 Compare September 29, 2025 07:08
@AdamGrzybkowski AdamGrzybkowski force-pushed the issue/WOOMOB-1378_trash_product_invisible branch from 5c49211 to a262969 Compare September 29, 2025 08:21
@AdamGrzybkowski AdamGrzybkowski merged commit 495c30a into trunk Sep 29, 2025
15 checks passed
@AdamGrzybkowski AdamGrzybkowski deleted the issue/WOOMOB-1378_trash_product_invisible branch September 29, 2025 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug feature: product details Related to adding or editing products, includes product settings.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants