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

Orders: Show trash option in order status filter list #13974

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Networking/Networking/Model/OrderStatusEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum OrderStatusEnum: Codable, Hashable, Comparable, Sendable, GeneratedF
case cancelled
case refunded
case failed
case trash
case custom(String)
}

Expand Down Expand Up @@ -71,6 +72,12 @@ public extension OrderStatusEnum {
value: "Refunded",
comment: "Display label for refunded order status."
)
case .trash:
return NSLocalizedString(
"orderStatusEnum.localizedName.trash",
value: "Trash",
comment: "Display label for trashed order status."
)
case .custom(let payload):
return payload // unable to localize at runtime.
}
Expand Down Expand Up @@ -101,6 +108,8 @@ extension OrderStatusEnum: RawRepresentable {
self = .completed
case Keys.refunded:
self = .refunded
case Keys.trash:
self = .trash
default:
self = .custom(rawValue)
}
Expand All @@ -118,6 +127,7 @@ extension OrderStatusEnum: RawRepresentable {
case .cancelled: return Keys.cancelled
case .completed: return Keys.completed
case .refunded: return Keys.refunded
case .trash: return Keys.trash
case .custom(let payload): return payload
}
}
Expand All @@ -135,4 +145,5 @@ private enum Keys {
static let cancelled = "cancelled"
static let completed = "completed"
static let refunded = "refunded"
static let trash = "trash"
}
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

20.5
-----
- [*] Orders: Enabled viewing orders in trash. [https://github.com/woocommerce/woocommerce-ios/pull/13974]
- [*] Blaze: Schedule a reminder local notification asking to continue abandoned campaign creation flow. [https://github.com/woocommerce/woocommerce-ios/pull/13950]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import protocol WooFoundation.Analytics
///
@MainActor
final class LastOrdersDashboardCardViewModel: ObservableObject {
enum OrderStatusRow: Identifiable {
enum OrderStatusRow: Identifiable, Equatable {
case any
case autoDraft
case pending
Expand All @@ -17,6 +17,7 @@ final class LastOrdersDashboardCardViewModel: ObservableObject {
case cancelled
case refunded
case failed
case trash
case custom(String)

init(_ status: OrderStatusEnum?) {
Expand All @@ -42,6 +43,8 @@ final class LastOrdersDashboardCardViewModel: ObservableObject {
self = .completed
case .refunded:
self = .refunded
case .trash:
self = .trash
case .custom(let value):
self = .custom(value)
}
Expand All @@ -67,6 +70,8 @@ final class LastOrdersDashboardCardViewModel: ObservableObject {
return .completed
case .refunded:
return .refunded
case .trash:
return .trash
case .custom(let value):
return .custom(value)
}
Expand Down Expand Up @@ -226,6 +231,11 @@ private extension LastOrdersDashboardCardViewModel {
.map { OrderStatusEnum(rawValue: $0.slug) }
.map { OrderStatusRow($0) }
allStatuses = [.any] + remoteStatuses

/// manually add trash option if not present
if !allStatuses.contains(where: { $0 == .trash }) {
allStatuses.append(.trash)
}
}

@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ extension EditableOrderViewModel {
title = orderStatus.name ?? orderStatus.slug
color = {
switch orderStatus.status {
case .autoDraft, .pending, .cancelled, .refunded, .custom:
case .autoDraft, .pending, .cancelled, .refunded, .custom, .trash:
return .gray(.shade5)
case .onHold:
return .withColorStudio(.orange, shade: .shade5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import enum Yosemite.OrderStatusEnum
extension OrderStatusEnum {
var backgroundColor: UIColor {
switch self {
case .autoDraft, .pending, .cancelled, .refunded, .custom:
case .autoDraft, .pending, .cancelled, .refunded, .custom, .trash:
.gray(.shade5)
case .onHold:
.withColorStudio(.orange, shade: .shade5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ private extension OrderStatusFilterViewController {
break
}
}

/// manually add trash option if not present
if !rows.contains(where: { $0 == .trash }) {
rows.append(.trash)
}
}

func selectOrDelesectRow(_ row: Row) {
Expand Down Expand Up @@ -148,7 +153,7 @@ extension OrderStatusFilterViewController: UITableViewDelegate {
// MARK: - Cell configuration
//
private extension OrderStatusFilterViewController {
enum Row {
enum Row: Equatable {

// The order of the statuses declaration is according to the Order's lifecycle
// and it is used to determine the user facing display order using the synthesized allCases
Expand All @@ -160,6 +165,7 @@ private extension OrderStatusFilterViewController {
case cancelled
case refunded
case failed
case trash
case custom(OrderStatus)

var status: OrderStatusEnum? {
Expand All @@ -180,6 +186,8 @@ private extension OrderStatusFilterViewController {
return .completed
case .refunded:
return .refunded
case .trash:
return .trash
case .custom(let value):
return value.status
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ final class LastOrdersDashboardCardViewModelTests: XCTestCase {


@MainActor
func test_order_statuses_are_loaded_from_storage_when_available() async {
func test_order_statuses_are_loaded_from_storage_when_available_with_additional_any_and_trash_statuses() async {
// Given
let viewModel = LastOrdersDashboardCardViewModel(siteID: sampleSiteID,
stores: stores,
Expand All @@ -125,7 +125,7 @@ final class LastOrdersDashboardCardViewModelTests: XCTestCase {
.sorted()

// Then
XCTAssertEqual(viewModel.allStatuses.map { $0.id }, (["any"] + statusSlugs))
XCTAssertEqual(viewModel.allStatuses.map { $0.id }, (["any"] + statusSlugs + ["trash"]))
}

@MainActor
Expand Down