woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
257 stars 108 forks source link

[Dynamic Dashboard] DashboardCard states refactoring. #12626

Closed hafizrahman closed 2 weeks ago

hafizrahman commented 2 weeks ago

Description

The previous logic for handling Dashboard Card's availability and display states on the Dashboard and Dashboard Customize screens felt flaky and complicated to me. The main reason was because there's a lot of different states at play, such as:

For completeness's sake, here's the availability and visibility logic that the app has to handle:

  1. Each card can be available or not based on various checks (e.g: analytics cards are only available if there are orders, Blaze is available if the site is Blaze-eligible, and so on)
  2. "available" here means that a card can be seen in Dashboard and Customize screen.
  3. Available cards can be enabled or disabled by users in the Customize screen. An enabled card becomes visible in the Dashboard, and disabled card is invisible. In any case, they're still visible in Customize screen.
  4. Special rule: for analytics cards, when they're not available, they are invisible in Dashboard but visible in Customize with the "Unavailable" status.
  5. Special rule: for non-analytics cards, when they're not available, they are invisible both in Dashboard and Customize.

What's in the PR:

This PR attempts to make the handling easier to reason with by:

  1. Updating DashboardCard to include new variables and accompanying comments related to availability and display states.
  2. This in turns simplifies the UI logic by not having to keep track unavailableDashboardCards separately anymore.
  3. Updating the logic in updateDashboardCards() to make updating cards and preserving setting easier to follow
  4. Creating generateDefaultCards() to separate concern and make the update function smaller.
  5. Updating the UI logic on how to display unavailable/hidden cards.

Testing instructions

Analytics check

  1. Start with a site with no orders,
  2. Ensure Performance and Top Performers are not shown in Dashboard,
  3. Go to Customize, ensure Performance and Top Performers are shown as "unavailable"
  4. Go to Orders,
  5. Create a new Order,
  6. Go back to Dashboard,
  7. Ensure Performance and Top Performers are not shown in Dashboard,
  8. Go to Customize, ensure Performance and Top Performers are shown as regular cards that can be enabled/disabled and reordered.

Blaze / Onboarding check

First, either start with a site that doesn't support Blaze, or change the line below in DashboardViewModel by hardcoding canShowBlaze to false:

        let initialCards = generateDefaultCards(canShowOnboarding: canShowOnboarding,
                                                canShowBlaze: canShowBlaze,
                                                canShowAnalytics: canShowAnalytics)

then,

  1. Start the app,
  2. Ensure Blaze is not shown in Dashboard,
  3. Go to Customize, ensure Blaze is not shown.
wpmobilebot commented 2 weeks ago

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

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr12626-3fc44de
Version18.4
Bundle IDcom.automattic.alpha.woocommerce
Commit3fc44de92ea04425d36e625f6aab9e671c124d6a
App Center BuildWooCommerce - Prototype Builds #8940

Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

dangermattic commented 2 weeks ago
1 Warning
:warning: View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by :no_entry_sign: Danger