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

[Products] Extract subscriptions outside of the Product DB table - Part 1 #12766

Merged
merged 16 commits into from
Oct 16, 2024

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Oct 8, 2024

Part of: #12752

Depends on wordpress-mobile/WordPress-FluxC-Android#3106

Note: I want to apologize first for the size of the PR, I tried to split the work, but it's not straightforward to get a compiling working state without changing all parts at once.
I think the code review could still be straightforward, half of the changes are in the ProductDetailCardBuilder class, and most changes there are just because we started using ProductAggregate instead of Product, so a quick skim through the file would be enough.

Description

This PR is the first part in a refactor to align with the above FluxC changes that removed the METADATA column from the products table, it adds the needed changes to load the subscription details from the MetaData table, and shows them in the product details.
Saving is not handled yet, it will be added in the next PR.

Before working on this, I looked into the different options to approach it, and I considered two options:

  1. Keep the subscription property inside the model Product, this would have required to create a special mapper that aggregates the data from both tables (WCProductModel and MetaDataEntity), this mapper would replace the extension function toAppModel.
  2. Remove the subscription property from the model Product and use a separate class that aggregates the product with the subscription details.

I went with option 2, while both approaches have their pros and cons, I think approach 1 has bigger downsides:

  • Will require more changes in the whole app.
  • Could cause some performance issues as we'll have to make calls to two tables for each product (the performance impact could be negligible, but I just considered).

This PR implements the approach 2.

Steps to reproduce

  1. Open the app.
  2. Navigate to the Products tab.
  3. Open an existing product.

Testing information

  • Test opening a subscription product, and confirm all its details are shown correctly.
  • Test opening other product types, and confirm there is no regression.
  • Anything else on your mind that could catch any potential regressions.

The tests that have been performed

^

  • 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.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.
t

@hichamboushaba hichamboushaba added feature: product details Related to adding or editing products, includes product settings. type: technical debt Represents or solves tech debt of the project. labels Oct 8, 2024
@hichamboushaba hichamboushaba force-pushed the issue/12752-subscriptions-meta-1 branch from 6f3c9f5 to 16587ff Compare October 8, 2024 14:42
@dangermattic
Copy link
Collaborator

dangermattic commented Oct 8, 2024

2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ This PR is assigned to the milestone 20.8. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 8, 2024

Project dependencies changes

The following changes in project dependencies were detected (configuration vanillaReleaseRuntimeClasspath):

list
Removed Dependencies
androidx.paging:paging-common:2.1.2
androidx.paging:paging-runtime:2.1.2
com.goterl:lazysodium-android:5.0.2
com.squareup.okhttp3:okhttp-urlconnection:4.9.0
net.java.dev.jna:jna:5.5.0
org.wordpress.fluxc:fluxc-annotations:2.99.0
org.wordpress.wellsql:wellsql-annotations:2.0.0
org.wordpress:wellsql:2.0.0

Upgraded Dependencies
org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.24, (changed from 1.9.25)
org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24, (changed from 1.9.25)
org.wordpress.fluxc.plugins:woocommerce:trunk-7475ad2070b90ab63276656225890fd312188011 FAILED, (changed from 2.99.0)
org.wordpress:fluxc:trunk-7475ad2070b90ab63276656225890fd312188011 FAILED, (changed from 2.99.0)
tree
 +--- androidx.datastore:datastore-preferences:1.1.0
 |    \--- androidx.datastore:datastore-preferences-android:1.1.0
 |         \--- androidx.datastore:datastore:1.1.0
 |              \--- androidx.datastore:datastore-android:1.1.0
 |                   \--- androidx.datastore:datastore-core:1.1.0
 |                        \--- androidx.datastore:datastore-core-android:1.1.0
-|                             \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 -> 1.9.25
-|                                  +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
-|                                  \--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.25
-|                                       \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
+|                             \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 -> 1.9.24
+|                                  +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.24 -> 1.9.25 (*)
+|                                  \--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.24
+|                                       \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.24 -> 1.9.25 (*)
-+--- org.wordpress:fluxc:2.99.0
-|    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.25 (*)
-|    +--- androidx.exifinterface:exifinterface:1.0.0 -> 1.3.6
-|    |    \--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
-|    +--- androidx.security:security-crypto:1.0.0 -> 1.1.0-alpha03
-|    |    +--- androidx.annotation:annotation:1.1.0 -> 1.8.0 (*)
-|    |    +--- com.google.crypto.tink:tink-android:1.5.0
-|    |    \--- androidx.collection:collection:1.1.0 -> 1.4.0 (*)
-|    +--- com.squareup.okhttp3:okhttp-urlconnection:4.9.0
-|    |    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.12.0 (*)
-|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10 -> 1.9.10 (*)
-|    +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
-|    +--- org.apache.commons:commons-text:1.10.0 (*)
-|    +--- androidx.room:room-runtime:2.6.1 (*)
-|    +--- androidx.room:room-ktx:2.6.1
-|    |    +--- androidx.room:room-common:2.6.1 (*)
-|    |    +--- androidx.room:room-runtime:2.6.1 (*)
-|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 -> 1.9.25 (*)
-|    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1 -> 1.8.1 (*)
-|    |    +--- androidx.room:room-common:2.6.1 (c)
-|    |    \--- androidx.room:room-runtime:2.6.1 (c)
-|    +--- com.google.dagger:dagger:2.51.1
-|    |    \--- javax.inject:javax.inject:1
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1 (*)
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1 (*)
-|    +--- org.wordpress:wellsql:2.0.0
-|    |    +--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
-|    |    \--- org.wordpress.wellsql:wellsql-annotations:2.0.0
-|    +--- org.wordpress.fluxc:fluxc-annotations:2.99.0
-|    +--- org.greenrobot:eventbus:3.3.1 (*)
-|    +--- org.greenrobot:eventbus-java:3.3.1
-|    +--- com.squareup.okhttp3:okhttp:4.9.0 -> 4.12.0 (*)
-|    +--- com.android.volley:volley:1.1.1 -> 1.2.0
-|    +--- androidx.paging:paging-runtime:2.1.2
-|    |    +--- androidx.paging:paging-common:2.1.2
-|    |    |    +--- androidx.annotation:annotation:1.0.0 -> 1.8.0 (*)
-|    |    |    \--- androidx.arch.core:core-common:2.0.0 -> 2.2.0 (*)
-|    |    +--- androidx.arch.core:core-runtime:2.0.0 -> 2.2.0 (*)
-|    |    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.7.0 (*)
-|    |    +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.7.0 (*)
-|    |    \--- androidx.recyclerview:recyclerview:1.0.0 -> 1.3.2 (*)
-|    +--- com.goterl:lazysodium-android:5.0.2
-|    +--- net.java.dev.jna:jna:5.5.0
-|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
++--- org.wordpress:fluxc:trunk-7475ad2070b90ab63276656225890fd312188011 FAILED
-+--- org.wordpress.fluxc.plugins:woocommerce:2.99.0
-|    +--- org.wordpress:fluxc:2.99.0 (*)
-|    +--- com.google.code.gson:gson:2.8.5 -> 2.10.1
-|    +--- com.google.dagger:dagger:2.51.1 (*)
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1 (*)
-|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1 (*)
-|    +--- androidx.room:room-runtime:2.6.1 (*)
-|    +--- org.wordpress:wellsql:2.0.0 (*)
-|    +--- org.wordpress.fluxc:fluxc-annotations:2.99.0
-|    +--- androidx.room:room-ktx:2.6.1 (*)
-|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 (*)
++--- org.wordpress.fluxc.plugins:woocommerce:trunk-7475ad2070b90ab63276656225890fd312188011 FAILED
 +--- org.wordpress:login:1.18.0
 |    +--- com.github.bumptech.glide:glide:4.12.0 -> 4.16.0
-|    |    \--- androidx.exifinterface:exifinterface:1.3.6 (*)
+|    |    \--- androidx.exifinterface:exifinterface:1.3.6
+|    |         \--- androidx.annotation:annotation:1.2.0 -> 1.8.0 (*)
-|    \--- com.google.dagger:dagger:2.47 -> 2.51.1 (*)
+|    \--- com.google.dagger:dagger:2.47 -> 2.51.1
+|         \--- javax.inject:javax.inject:1
 +--- project :libs:cardreader
 |    +--- com.stripe:stripeterminal-localmobile:3.7.1
-|    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 |    |    +--- com.stripe:stripeterminal-external:3.7.1
-|    |    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    |    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 |    |    |    \--- com.stripe:stripeterminal-internal-models:3.7.1
-|    |    |         \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    |    |         \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 |    |    \--- com.stripe:stripeterminal-internal-common:3.7.1
-|    |         \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    |         \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 |    +--- com.stripe:stripeterminal-core:3.7.1
-|    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    |    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
-|    |    +--- androidx.security:security-crypto:1.1.0-alpha03 (*)
+|    |    +--- androidx.security:security-crypto:1.1.0-alpha03
+|    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.8.0 (*)
+|    |    |    +--- com.google.crypto.tink:tink-android:1.5.0
+|    |    |    \--- androidx.collection:collection:1.1.0 -> 1.4.0 (*)
-|    |    \--- androidx.room:room-ktx:2.6.1 (*)
+|    |    \--- androidx.room:room-ktx:2.6.1
+|    |         +--- androidx.room:room-common:2.6.1 (*)
+|    |         +--- androidx.room:room-runtime:2.6.1 (*)
+|    |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 -> 1.9.25 (*)
+|    |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1 -> 1.8.1 (*)
+|    |         +--- androidx.room:room-common:2.6.1 (c)
+|    |         \--- androidx.room:room-runtime:2.6.1 (c)
-|    \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 -> 1.9.25 (*)
+|    \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 -> 1.9.24 (*)
 +--- com.automattic:about:0.0.6
-|    \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.5.31 -> 1.9.25 (*)
+|    \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.5.31 -> 1.9.24 (*)
 +--- org.wordpress:mediapicker:0.3.1
-|    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 |    \--- org.wordpress.mediapicker:domain:0.3.1
-|         \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|         \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 +--- org.wordpress.mediapicker:source-wordpress:0.3.1
-|    \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 -> 1.9.25 (*)
+|    \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.24 (*)
 +--- io.coil-kt:coil-compose:2.1.0
 |    \--- io.coil-kt:coil-compose-base:2.1.0
 |         \--- io.coil-kt:coil-base:2.1.0
-|              \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.6.10 -> 1.9.25 (*)
+|              \--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.6.10 -> 1.9.24 (*)
-\--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 -> 1.9.25 (*)
+\--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.22 -> 1.9.24 (*)

@hichamboushaba hichamboushaba force-pushed the issue/12752-subscriptions-meta-1 branch from 16587ff to bd5764f Compare October 8, 2024 14:55
@hichamboushaba hichamboushaba force-pushed the issue/12752-subscriptions-meta-1 branch from bd5764f to 9eafa13 Compare October 8, 2024 14:58
@hichamboushaba hichamboushaba added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Oct 8, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 8, 2024

📲 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
Commit57e9381
Direct Downloadwoocommerce-wear-prototype-build-pr12766-57e9381.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 8, 2024

📲 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
Commit57e9381
Direct Downloadwoocommerce-prototype-build-pr12766-57e9381.apk

@hichamboushaba hichamboushaba force-pushed the issue/12752-subscriptions-meta-1 branch 2 times, most recently from e5e9332 to 06f0775 Compare October 9, 2024 11:35
@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 37.60218% with 229 lines in your changes missing coverage. Please review.

Project coverage is 40.84%. Comparing base (06fce27) to head (57e9381).
Report is 17 commits behind head on trunk.

Files with missing lines Patch % Lines
...id/ui/products/details/ProductDetailCardBuilder.kt 25.54% 133 Missing and 4 partials ⚠️
...roid/ui/products/details/ProductDetailViewModel.kt 45.94% 22 Missing and 18 partials ⚠️
...roducts/details/ProductDetailBottomSheetBuilder.kt 35.00% 22 Missing and 4 partials ⚠️
...ommerce/android/model/SubscriptionDetailsMapper.kt 73.80% 0 Missing and 11 partials ⚠️
...oid/ui/products/details/ProductDetailRepository.kt 0.00% 9 Missing ⚠️
...m/woocommerce/android/ui/products/ProductHelper.kt 50.00% 1 Missing and 2 partials ⚠️
.../com/woocommerce/android/model/ProductAggregate.kt 81.81% 0 Missing and 2 partials ⚠️
...in/kotlin/com/woocommerce/android/model/Product.kt 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #12766      +/-   ##
============================================
+ Coverage     40.83%   40.84%   +0.01%     
- Complexity     5739     5753      +14     
============================================
  Files          1236     1237       +1     
  Lines         69703    69725      +22     
  Branches       9668     9673       +5     
============================================
+ Hits          28460    28479      +19     
- Misses        38618    38621       +3     
  Partials       2625     2625              

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

Copy link
Contributor

@JorgeMucientes JorgeMucientes left a comment

Choose a reason for hiding this comment

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

Excellent work @hichamboushaba the code changes look good and everything I tested worked well, including updating from older version of the app to a new one with subscription products loaded into the DB.

val remoteId: Long
get() = product.remoteId

val hasShipping: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

I've noticed a bug around this. But i could confirm is not related to the changes from this PR so I created a GH issue to address it.

@hichamboushaba hichamboushaba removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Oct 16, 2024
@hichamboushaba hichamboushaba added this to the 20.8 milestone Oct 16, 2024
@hichamboushaba hichamboushaba merged commit d1751be into trunk Oct 16, 2024
17 checks passed
@hichamboushaba hichamboushaba deleted the issue/12752-subscriptions-meta-1 branch October 16, 2024 10:41
Copy link

sentry-io bot commented Oct 19, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ NumberFormatException: empty String com.woocommerce.android.ui.products.ParameterRe... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: product details Related to adding or editing products, includes product settings. type: technical debt Represents or solves tech debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants