Skip to content

Commit 5e43268

Browse files
authored
Merge pull request #7350 from woocommerce/issue/7340-swipe-action
Bulk Order Actions: Add Swipe Actions To Order Cell
2 parents 413c56c + 78c2774 commit 5e43268

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

WooCommerce/Classes/ViewRelated/Orders/OrderListViewController.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,28 @@ extension OrderListViewController: UITableViewDelegate {
635635
func scrollViewDidScroll(_ scrollView: UIScrollView) {
636636
delegate?.orderListScrollViewDidScroll(scrollView)
637637
}
638+
639+
/// Provide an implementation to show cell swipe actions. Return `nil` to provide no action.
640+
///
641+
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
642+
/// Fetch the order view model and make sure the order is not marked as completed before proceeding.
643+
///
644+
guard let objectID = dataSource.itemIdentifier(for: indexPath),
645+
let cellViewModel = viewModel.cellViewModel(withID: objectID),
646+
cellViewModel.status != .completed else {
647+
return nil
648+
}
649+
650+
let markAsCompletedAction = UIContextualAction(style: .normal, title: Localization.markCompleted, handler: { _, _, completionHandler in
651+
print("Mark as completed triggered...")
652+
// TODO: Fire real action
653+
completionHandler(true) // Tells the table that the action was performed and forces it to go back to its original state (un-swiped)
654+
})
655+
markAsCompletedAction.backgroundColor = .brand
656+
markAsCompletedAction.image = .checkmarkImage
657+
658+
return UISwipeActionsConfiguration(actions: [markAsCompletedAction])
659+
}
638660
}
639661

640662
// MARK: - Finite State Machine Management
@@ -743,6 +765,8 @@ private extension OrderListViewController {
743765
comment: "Message for empty Orders filtered results. The %@ is a placeholder for the filters entered by the user.")
744766
static let clearButton = NSLocalizedString("Clear Filters",
745767
comment: "Action to remove filters orders on the placeholder overlay when no orders match the filter on the Order List")
768+
769+
static let markCompleted = NSLocalizedString("Mark Completed", comment: "Title for the swipe order action to mark it as completed")
746770
}
747771

748772
enum Settings {

0 commit comments

Comments
 (0)