@@ -8,7 +8,7 @@ import SafariServices
88
99// MARK: - OrderDetailsViewController: Displays the details for a given Order.
1010//
11- class OrderDetailsViewController : UIViewController {
11+ final class OrderDetailsViewController : UIViewController {
1212
1313 /// Main TableView.
1414 ///
@@ -82,6 +82,11 @@ class OrderDetailsViewController: UIViewController {
8282 return trackingResultsController. fetchedObjects
8383 }
8484
85+ /// Indicates if we consider the shipment tracking plugin as reachable
86+ /// https://github.com/woocommerce/woocommerce-ios/issues/852#issuecomment-482308373
87+ ///
88+ private var trackingIsReachable : Bool = false
89+
8590 /// Order statuses list
8691 ///
8792 private var currentSiteStatuses : [ OrderStatus ] {
@@ -109,7 +114,18 @@ class OrderDetailsViewController: UIViewController {
109114 override func viewWillAppear( _ animated: Bool ) {
110115 super. viewWillAppear ( animated)
111116 syncNotes ( )
112- syncTracking ( )
117+ syncTrackingsHiddingAddButtonIfNecessary ( )
118+ }
119+
120+ private func syncTrackingsHiddingAddButtonIfNecessary( ) {
121+ syncTracking { [ weak self] error in
122+ if error == nil {
123+ self ? . trackingIsReachable = true
124+ }
125+
126+ self ? . reloadSections ( )
127+ self ? . tableView. reloadData ( )
128+ }
113129 }
114130}
115131
@@ -297,12 +313,25 @@ private extension OrderDetailsViewController {
297313 return Section ( title: Title . tracking, rows: rows)
298314 } ( )
299315
316+ let addTracking : Section ? = {
317+ // Hide the section if the shipment
318+ // tracking plugin is not installed
319+ guard trackingIsReachable else {
320+ return nil
321+ }
322+
323+ let title = orderTracking. count == 0 ? NSLocalizedString ( " Optional Tracking Information " , comment: " " ) : nil
324+ let row = Row . trackingAdd
325+
326+ return Section ( title: title, rightTitle: nil , rows: [ row] )
327+ } ( )
328+
300329 let notes : Section = {
301330 let rows = [ . addOrderNote] + Array( repeating: Row . orderNote, count: orderNotes. count)
302331 return Section ( title: Title . notes, rows: rows)
303332 } ( )
304333
305- sections = [ summary, products, customerNote, customerInformation, payment, tracking, notes] . compactMap { $0 }
334+ sections = [ summary, products, customerNote, customerInformation, payment, tracking, addTracking , notes] . compactMap { $0 }
306335 }
307336}
308337
@@ -374,7 +403,7 @@ private extension OrderDetailsViewController {
374403 configureShippingAddress ( cell: cell)
375404 case let cell as CustomerNoteTableViewCell :
376405 configureCustomerNote ( cell: cell)
377- case let cell as LeftImageTableViewCell :
406+ case let cell as LeftImageTableViewCell where row == . addOrderNote :
378407 configureNewNote ( cell: cell)
379408 case let cell as OrderNoteTableViewCell :
380409 configureOrderNote ( cell: cell, at: indexPath)
@@ -384,6 +413,8 @@ private extension OrderDetailsViewController {
384413 configureProductList ( cell: cell)
385414 case let cell as OrderTrackingTableViewCell :
386415 configureTracking ( cell: cell, at: indexPath)
416+ case let cell as LeftImageTableViewCell where row == . trackingAdd:
417+ configureNewTracking ( cell: cell)
387418 case let cell as SummaryTableViewCell :
388419 configureSummary ( cell: cell)
389420 default :
@@ -573,6 +604,23 @@ private extension OrderDetailsViewController {
573604 }
574605 }
575606
607+ func configureNewTracking( cell: LeftImageTableViewCell ) {
608+ let cellTextContent = NSLocalizedString ( " Add Tracking " , comment: " Add Tracking row label " )
609+ cell. leftImage = . addOutlineImage
610+ cell. labelText = cellTextContent
611+
612+ cell. accessibilityTraits = . button
613+ cell. accessibilityLabel = NSLocalizedString (
614+ " Add a tracking button " ,
615+ comment: " Accessibility label for the 'Add a tracking' button "
616+ )
617+
618+ cell. accessibilityHint = NSLocalizedString (
619+ " Adds tracking to an order. " ,
620+ comment: " VoiceOver accessibility hint, informing the user that the button can be used to add tracking to an order. Should end with a period. "
621+ )
622+ }
623+
576624 func configureShippingAddress( cell: CustomerInfoTableViewCell ) {
577625 let shippingAddress = viewModel. order. shippingAddress
578626
@@ -757,11 +805,6 @@ extension OrderDetailsViewController: UITableViewDataSource {
757805 }
758806
759807 func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
760- if sections [ section] . title == nil {
761- // iOS 11 table bug. Must return a tiny value to collapse `nil` or `empty` section headers.
762- return . leastNonzeroMagnitude
763- }
764-
765808 return UITableView . automaticDimension
766809 }
767810
@@ -822,6 +865,7 @@ extension OrderDetailsViewController: UITableViewDelegate {
822865 tableView. deselectRow ( at: indexPath, animated: true )
823866
824867 switch sections [ indexPath. section] . rows [ indexPath. row] {
868+
825869 case . addOrderNote:
826870 WooAnalytics . shared. track ( . orderDetailAddNoteButtonTapped)
827871
@@ -830,6 +874,15 @@ extension OrderDetailsViewController: UITableViewDelegate {
830874
831875 let navController = WooNavigationController ( rootViewController: newNoteViewController)
832876 present ( navController, animated: true , completion: nil )
877+
878+ case . trackingAdd:
879+ WooAnalytics . shared. track ( . orderDetailAddTrackingButtonTapped)
880+
881+ let addTrackingViewModel = AddTrackingViewModel ( order: viewModel. order)
882+ let addTracking = ManualTrackingViewController ( viewModel: addTrackingViewModel)
883+ let navController = WooNavigationController ( rootViewController: addTracking)
884+ present ( navController, animated: true , completion: nil )
885+
833886 case . productDetails:
834887 WooAnalytics . shared. track ( . orderDetailProductDetailTapped)
835888 performSegue ( withIdentifier: Constants . productDetailsSegue, sender: nil )
@@ -1232,6 +1285,7 @@ private extension OrderDetailsViewController {
12321285 case productList
12331286 case productDetails
12341287 case tracking
1288+ case trackingAdd
12351289 case customerNote
12361290 case shippingAddress
12371291 case billingAddress
@@ -1251,6 +1305,8 @@ private extension OrderDetailsViewController {
12511305 return BasicTableViewCell . reuseIdentifier
12521306 case . tracking:
12531307 return OrderTrackingTableViewCell . reuseIdentifier
1308+ case . trackingAdd:
1309+ return LeftImageTableViewCell . reuseIdentifier
12541310 case . customerNote:
12551311 return CustomerNoteTableViewCell . reuseIdentifier
12561312 case . shippingAddress:
0 commit comments