-
Notifications
You must be signed in to change notification settings - Fork 136
[WOOMOB-1722] - Properly clean the Bookings table for Today/Upcoming tabs' first page load #15022
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
Merged
+439
−77
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6cd96c
Prefer BookingFilters.EMPTY over nullable property
AdamGrzybkowski 98c6ec8
Extract Today/Upcoming DateRange creation for reuse in other places
AdamGrzybkowski 99c3735
Properly clear the Booking table for Today/Upcoming tabs
AdamGrzybkowski 5ef2be3
Make sure that only date range matching today/upcoming is applied
AdamGrzybkowski e19f6d1
Improve BookingsDateRangePresets
AdamGrzybkowski c2cf448
Wrap delete and insert in one DB transaction
AdamGrzybkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 5 additions & 24 deletions
29
...rce/src/main/kotlin/com/woocommerce/android/ui/bookings/list/BookingListFiltersBuilder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,19 @@ | ||
| package com.woocommerce.android.ui.bookings.list | ||
|
|
||
| import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsDateRangePresets | ||
| import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsFilterOption | ||
| import java.time.Clock | ||
| import java.time.LocalDate | ||
| import java.time.LocalTime | ||
| import java.time.ZoneOffset | ||
| import javax.inject.Inject | ||
|
|
||
| class BookingListFiltersBuilder @Inject constructor( | ||
| private val clock: Clock | ||
| ) { | ||
| /** | ||
| * Returns a [BookingsFilterOption.DateRange] based on the selected [BookingListTab]. | ||
| * | ||
| * We use UTC for the API calls, as the API stores the dates without timezone information, which means that | ||
| * when comparing dates, they are treated as UTC times. | ||
| * See p1759398245019489-slack-C09FHQNQERG | ||
| */ | ||
| fun BookingListTab.asDateRangeFilter(): BookingsFilterOption.DateRange? { | ||
| fun todayAtMidnight() = LocalDate.now(clock).atTime(LocalTime.MIDNIGHT).atOffset(ZoneOffset.UTC).toInstant() | ||
| fun todayAtEndOfDay() = LocalDate.now(clock).atTime(LocalTime.MAX).atOffset(ZoneOffset.UTC).toInstant() | ||
|
|
||
| return when (this) { | ||
| BookingListTab.Today -> BookingsFilterOption.DateRange( | ||
| before = todayAtEndOfDay(), | ||
| after = todayAtMidnight() | ||
| ) | ||
|
|
||
| BookingListTab.Upcoming -> BookingsFilterOption.DateRange( | ||
| before = null, | ||
| after = todayAtEndOfDay() | ||
| ) | ||
|
|
||
| BookingListTab.All -> null | ||
| } | ||
| fun BookingListTab.asDateRangeFilter(): BookingsFilterOption.DateRange? = when (this) { | ||
| BookingListTab.Today -> BookingsDateRangePresets.today(clock) | ||
| BookingListTab.Upcoming -> BookingsDateRangePresets.upcoming(clock) | ||
| BookingListTab.All -> null | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...in/org/wordpress/android/fluxc/network/rest/wpcom/wc/bookings/BookingsDateRangePresets.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings | ||
|
|
||
| import java.time.Clock | ||
| import java.time.Instant | ||
| import java.time.LocalDate | ||
| import java.time.LocalTime | ||
| import java.time.ZoneOffset | ||
|
|
||
| /** | ||
| * Factory for canonical booking date range presets used across app and data layers. | ||
| * | ||
| * Notes about time zone: | ||
| * The WC Bookings API stores dates without timezone information. To ensure | ||
| * consistent comparisons and filtering on both client and server, we construct | ||
| * ranges in UTC. | ||
| * See p1759398245019489-slack-C09FHQNQERG | ||
| */ | ||
| object BookingsDateRangePresets { | ||
| /** | ||
| * Returns a DateRange that spans the current day in UTC, inclusive of the | ||
| * full day when interpreted by the API (midnight to end-of-day). | ||
| */ | ||
| fun today(clock: Clock): BookingsFilterOption.DateRange { | ||
| val start = LocalDate.now(clock) | ||
| .atTime(LocalTime.MIDNIGHT) | ||
| .atOffset(ZoneOffset.UTC) | ||
| .toInstant() | ||
| val end = getEndOfToday(clock) | ||
| return BookingsFilterOption.DateRange(before = end, after = start) | ||
| } | ||
|
|
||
| /** | ||
| * Returns a DateRange that includes bookings strictly after the end of the | ||
| * current day in UTC (i.e., upcoming bookings from tomorrow onwards). | ||
| */ | ||
| fun upcoming(clock: Clock): BookingsFilterOption.DateRange { | ||
| val endOfToday = getEndOfToday(clock) | ||
| return BookingsFilterOption.DateRange(before = null, after = endOfToday) | ||
| } | ||
|
|
||
| private fun getEndOfToday(clock: Clock): Instant { | ||
| return LocalDate.now(clock) | ||
| .atTime(LocalTime.MAX) | ||
| .atOffset(ZoneOffset.UTC) | ||
| .toInstant() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment here is not entirely accurate. We say,
If filters are applied, only clear entries that match the applied filters,but this is only true for date filters. The issue still exists for other filter types. For example, I filtered “No-show” bookings, trashed one, refreshed the list, and it was still visible.If we want to address this for all cases, we’ll need to always delete cached entities when any filter is applied. Since it already works for the date filter, we could turn that into a more general solution. WDYT?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially did that, but then I thought that there was a reason why we added this check in the first place, so I decided to strictly add this logic for Today and Upcoming filter.
I'm open to changing that. I wonder if we had similar problems with Products or Orders, and how they were solved there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm thinking about it, I'm not sure we need it. We can only apply other filters in the
Alltab. This tab, without filters applied, will delete or bookings for a selected site on the initial load. So the problems should be less visible and we won't be clearing the data that we would get on next page loads.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, the issue is less visible for the All tab, but the All filter is saved, and it's possible that the user prefers to always keep a certain filter enabled. In that case, it becomes the same situation as the Today and Upcoming tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just tested the Products tab, and the issue exists there as well.