-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10677 from woocommerce/issue/10666-see-report-hub
Add see report button in Analytic Hub
- Loading branch information
Showing
14 changed files
with
454 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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
51 changes: 51 additions & 0 deletions
51
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/GetReportUrl.kt
This file contains 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,51 @@ | ||
package com.woocommerce.android.ui.analytics.hub | ||
|
||
import com.woocommerce.android.extensions.adminUrlOrDefault | ||
import com.woocommerce.android.extensions.formatToYYYYmmDD | ||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.ui.analytics.ranges.StatsTimeRangeSelection | ||
import javax.inject.Inject | ||
|
||
class GetReportUrl @Inject constructor( | ||
private val selectedSite: SelectedSite | ||
) { | ||
operator fun invoke( | ||
selection: StatsTimeRangeSelection, | ||
card: ReportCard | ||
): String? { | ||
return selectedSite.getOrNull()?.let { siteModel -> | ||
val adminURL = siteModel.adminUrlOrDefault | ||
val page = "page=wc-admin" | ||
val path = when (card) { | ||
ReportCard.Revenue -> "path=%2Fanalytics%2Frevenue" | ||
ReportCard.Orders -> "path=%2Fanalytics%2Forders" | ||
ReportCard.Products -> "path=%2Fanalytics%2Fproducts" | ||
} | ||
val period = getPeriod(selection) | ||
val compare = "compare=previous_period" | ||
"${adminURL}admin.php?$page&$path&$period&$compare" | ||
} | ||
} | ||
|
||
private fun getPeriod(selection: StatsTimeRangeSelection): String { | ||
return when (selection.selectionType) { | ||
StatsTimeRangeSelection.SelectionType.TODAY -> "period=today" | ||
StatsTimeRangeSelection.SelectionType.YESTERDAY -> "period=yesterday" | ||
StatsTimeRangeSelection.SelectionType.LAST_WEEK -> "period=last_week" | ||
StatsTimeRangeSelection.SelectionType.LAST_MONTH -> "period=last_month" | ||
StatsTimeRangeSelection.SelectionType.LAST_QUARTER -> "period=last_quarter" | ||
StatsTimeRangeSelection.SelectionType.LAST_YEAR -> "period=last_year" | ||
StatsTimeRangeSelection.SelectionType.WEEK_TO_DATE -> "period=week" | ||
StatsTimeRangeSelection.SelectionType.MONTH_TO_DATE -> "period=month" | ||
StatsTimeRangeSelection.SelectionType.QUARTER_TO_DATE -> "period=quarter" | ||
StatsTimeRangeSelection.SelectionType.YEAR_TO_DATE -> "period=year" | ||
StatsTimeRangeSelection.SelectionType.CUSTOM -> { | ||
val startDate = selection.currentRange.start.formatToYYYYmmDD() | ||
val endDate = selection.currentRange.end.formatToYYYYmmDD() | ||
"period=custom&after=$startDate&before=$endDate" | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class ReportCard { Revenue, Orders, Products } |
This file contains 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 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 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 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 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 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 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 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.