Skip to content

Conversation

@AmandaRiu
Copy link
Contributor

@AmandaRiu AmandaRiu commented Aug 7, 2018

Fixes #283

This PR adds the Orders to fulfill card to the Dashboard.

--- screen shot 2018-08-07 at 5 55 17 pm

UI

This card should only be visible is the total count of orders to fulfill > 0. Otherwise it should be hidden.

This card makes use of pluralized strings to display the correct version of the string if there is only one order vs more than one order.

---

Navigation Changes

This feature required a new type of navigation, cross-TopLevelFragment. To keep this flexible, I've created a new interface called TopLevelFragmentRouter. It only contains one simple function showOrderList(...) at the moment, but can later accept a bunch of routing options. It also allows us to do stuff like this so we know the hosting activity can handle this feature:

(activity as? TopLevelFragmentRouter)?.showOrderList(CoreOrderStatus.PROCESSING.value) 

I envision the TopLevelFragment design being replaced with the new Android Navigation components eventually, but for now, I've been trying to keep them generic and reusable whenever possible to avoid a bunch of custom routing scenarios. To this end, I've added a new property to TopLevelFragment named deferInit. This allows for loading a top level fragment and specifying that a portion of the initialization code be skipped so it can manually be executed later. Using this property I can leave all the code for locating and/or creating a TopLevelFragment generic and then in the case of the OrderListFragment pass along a status filter and call a method to finish loading.

Refreshing the Dashboard cards

The data for the dashboard cards are fetched upon initialization, and then refreshed under the following scenarios:

  • Manually via pull to refresh
  • When any of the OnOrderChanged events are consumed except when the event wouldn't cause the dashboard to fall out of sync with the orders view. So the FETCH_ORDER_NOTES event is ignored. Any OnOrderChanged event that has an error is also ignored.

If the DashboardFragment is currently in the background, we just set a flag so it knows to refresh when it comes to the foreground.

Dependencies

The FluxC PR must be merged before this PR can be merged.

cc: @nbradbury @aforcier

AmandaRiu added 12 commits August 2, 2018 19:18
Includes the layout XML, custom class, and plural string support.
This makes the method much more flexible for future use with custom statuses and helps to clean up usage for the orders to fulfill dashboard card.
This is used to prevent the orders list fragment from loading the full list before we can set the status filter. This also gives us a generic way of deferring initialization of any of the top level fragments for similar cases in the future.
AmandaRiu added 4 commits August 7, 2018 16:00
Since `onBackStackChanged()` is from the childFragmentManager, this method will never be called until we start opening child fragments on top of the DashboardFragment. 

The `isActive` property now uses both the childFragmentManager's backstack count as well as the hidden property to determine this fragments visibility.
The `isActive` property now uses both the childFragmentManager's backstack count as well as the hidden property to determine this fragments visibility.
Refresh if an OnOrderChanged event was received that wasn't either a fetch order count response, or a request for order notes (since those happen frequently).
@AmandaRiu AmandaRiu added this to the External open beta group milestone Aug 7, 2018
@AmandaRiu AmandaRiu added the MVLP label Aug 7, 2018
@AmandaRiu AmandaRiu requested a review from nbradbury August 7, 2018 22:58
@AmandaRiu AmandaRiu removed their assignment Aug 7, 2018
@AmandaRiu AmandaRiu added status: do not merge Dependent on another PR, ready for review but not ready for merge. and removed [Status] Not Ready for Review labels Aug 7, 2018
@nbradbury nbradbury self-assigned this Aug 8, 2018
fun refreshDashboard()
fun setLoadingIndicator(active: Boolean)
fun showStats(revenueStats: Map<String, Double>, salesStats: Map<String, Int>, granularity: StatsGranularity)
fun hideOrdersCard()
Copy link
Contributor

Choose a reason for hiding this comment

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

These two functions (and the view itself) seem mis-named to me. How about using UnfilledOrdersCard instead of simply OrdersCard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me. Fixed in 5b1863a

app:layout_constraintTop_toBottomOf="@+id/alertAction_title"/>

<!-- Action Button -->
<Button
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this button have android:background="?android:attr/selectableItemBackground"?

Copy link
Contributor Author

@AmandaRiu AmandaRiu Aug 8, 2018

Choose a reason for hiding this comment

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

Good catch, this should have a style attribute assigned to it. Fixed in 78fc331

@nbradbury
Copy link
Contributor

The way the card suddenly appears is a little odd to me. How about fading it in instead?

hideOrdersCard()
loadDataPending = false
setLoadingIndicator(true)
presenter.loadOrdersToFulfillCount()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these three lines be replaced with refreshDashboard()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1217c0c

if (isActive) {
setLoadingIndicator(true)
presenter.loadStats(dashboard_stats.activeGranularity, forced = true)
presenter.loadOrdersToFulfillCount()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add loadDataPending = false here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 fixed in 1217c0c

dashboardView?.showOrdersCard(count)
} ?: dashboardView?.hideOrdersCard()
} ?: if (!event.isError && event.causeOfChange != WCOrderAction.FETCH_ORDER_NOTES) {
dashboardView?.refreshDashboard()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this because it causes the dashboard to refresh even if nothing has changed. That seems wasteful since refreshing requires two non-trivial network requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But something may have changed. An example scenario:

  • User opens app, the dashboard loads and the orders to fulfill card displays 3
  • User clicks view orders
  • While the user is viewing the orders list, another order is submitted on their store
  • the user refreshes the orders list view and sees the order
  • the user switches back to the dashboard - the dashboard refreshes with the updated information because it was listening for that refresh event on orders.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess since the refresh is deferred until the next time the dashboard is accessed then this isn't as big a deal as I thought, but down the road it really would be nice if we only made network requests when we know they're necessary (ie: something has changed). In the meantime, though, can we also skip the refresh when the cause of change is POST_ORDER_NOTE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it really would be nice if we only made network requests when we know they're necessary

That's the plan once notifications are done.

can we also skip the refresh when the cause of change is POST_ORDER_NOTE

Absolutely! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Post order notes event is ignored as of 2038fad

}

fun updateOrdersCount(count: Int) {
val titleTxt = resources.getQuantityString(R.plurals.dashboard_fulfill_orders_title, count, count)
Copy link
Contributor

Choose a reason for hiding this comment

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

As Alex mentioned earlier, we can't use Android plurals due to a limitation in Glotpress. Also, this isn't handling the situation where there are more than 50 orders. Instead of saying 50+ it just says 50.

screenshot_1533747691

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in e0d40ab

@AmandaRiu
Copy link
Contributor Author

@nbradbury Thanks for the thorough review! Ready for a second round 🥇

@AmandaRiu AmandaRiu removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Aug 8, 2018
@nbradbury
Copy link
Contributor

@AmandaRiu This all looks great, except that it still doesn't handle the case where there are more than 50 orders. In that situation it's supposed to say 50+, right?

AmandaRiu added 2 commits August 9, 2018 21:50
…r fetching

This is temporary until we have an api endpoint that will provide a total count directly.
@AmandaRiu
Copy link
Contributor Author

@nbradbury Added support for displaying the plus sign. Ready for a 3rd round 🤦‍♀️

screen shot 2018-08-09 at 9 56 49 pm

@nbradbury
Copy link
Contributor

Added support for displaying the plus sign. Ready for a 3rd round

@AmandaRiu I'm not seeing this - did you forget to push the change?

@AmandaRiu
Copy link
Contributor Author

AmandaRiu commented Aug 10, 2018

@nbradbury it would seem I did! ✔️ Done

@AmandaRiu
Copy link
Contributor Author

@nbradbury Yay! tests finally passed!

@nbradbury
Copy link
Contributor

:shipit:

@nbradbury nbradbury merged commit 5c5b264 into develop Aug 12, 2018
@nbradbury nbradbury deleted the issue/283_dash_orders branch August 12, 2018 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants