Skip to content

Conversation

@mindgraffiti
Copy link
Contributor

@mindgraffiti mindgraffiti commented Jul 23, 2018

Closes #75.

In this PR, an addOrderNote action has been added to Yosemite. The action triggers a post network request. On completion, if successful the new order note is inserted into core data.

The UI button Add a note displays a new modal view and is connected to the action. Upon successful completion, the order details view refreshes and displays the new order note.

  • verify the new unit test makes sense
  • suggest more unit tests if I missed any please?
  • verify the new unit test passes
  • test the Add a Note feature: select Add a Note row, write a new note for an order and tap "Add".
  • verify the new note loads on the Order Details screen

cc: @bummytime @jleandroperez

@mindgraffiti mindgraffiti self-assigned this Jul 23, 2018
@mindgraffiti mindgraffiti added the type: enhancement A request for an enhancement. label Jul 23, 2018
@mindgraffiti mindgraffiti added this to the External closed beta milestone Jul 23, 2018
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 26, 2018

1 Warning
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 Danger

Copy link
Contributor

@jleandroperez jleandroperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great @mindgraffiti !!! few incoming nipticky comments, please, let me know if anything!.


@objc func addButtonTapped() {
let indexPath = IndexPath(row: 0, section: 0)
guard let cell = tableView.cellForRow(at: indexPath) as? WriteCustomerNoteTableViewCell else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes here!!

  1. Instead of having the IndexPath for the TextView row, you can just do something like this:

WriteCustomerNoteTableViewCell.swift

class WriteCustomerNoteTableViewCell {
   var onTextChange: ((String) -> Void)?
}

extension WriteCustomerNoteTableViewCell : UITextViewDelegate: {
   func textViewDidChange() {
       onTextChange?(textView.text)
   }
}


@objc func addButtonTapped() {
let indexPath = IndexPath(row: 0, section: 0)
guard let cell = tableView.cellForRow(at: indexPath) as? WriteCustomerNoteTableViewCell else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Having the mechanism mentioned above would let you disable the add button, whenever there is no text (OR enable it when isEmpty != false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

target: self,
action: #selector(addButtonTapped))
rightBarButton.tintColor = .white
navigationItem.setRightBarButton(rightBarButton, animated: false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be neat if we could disable the Add button whenever there is no actual text entered.

(More details below in addButtonTapped!!)

}

let action = OrderNoteAction.addOrderNote(siteID: viewModel.order.siteID, orderID: viewModel.order.orderID, isCustomerNote: isCustomerNote, note: note) { [weak self] (orderNote, error) in
guard orderNote != nil else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should probably check on error rather than the note. (if let error = error { ... })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

//
extension AddANoteViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return sections.count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return sections[section].rows.count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@@ -0,0 +1,25 @@
import UIKit

class ToggleEmailCustomerTableViewCell: UITableViewCell {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can we rename this one to something like SwitchTableViewCell perhaps?.
  • The topLabel.text + bottomLabel.text setup should probably be done in setupEmailCustomerCell. That would effectively let you turn this one into a reusable cell (and not just for ToggleEmail)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

}

override func awakeFromNib() {
super.awakeFromNib()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please nuke this one, since it's not really needed! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

import UIKit
import Gridicons

class WriteCustomerNoteTableViewCell: UITableViewCell {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How aboooout... TextViewTableViewCell (or something like that?). Plus:

var iconImage: UIImage? {
    set {
        noteIconButton.setImage(newValue, for: .normal)
    }
    get  {
       return noteIconButton.image (...
    }

The goal is: turn this cell into a generic one (and not just for this specific viewController).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And you could also move this one, and the second new cell, over to ReusableViews perhaps?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

}

self?.upsertStoredOrderNotes(readOnlyOrderNotes: [note], orderID: orderID)
onCompletion(note, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should proooobably do an optimistic update here. @bummytime thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jleandroperez @mindgraffiti seems to make sense. Similar to the pattern here.

Copy link
Contributor Author

@mindgraffiti mindgraffiti Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jleandroperez @bummytime not sure how to apply optimistic insert here. Do these steps make sense?

  1. Create an OrderNote object with a fake noteID and upsert it.
  2. If POSTing the note fails, write a function that deletes the fake note by noteID
  3. If POSTing is successful, delete the fake note by noteID and upsert the new note from the response

Copy link
Contributor

@jleandroperez jleandroperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOVED this PR!!!. (As discussed over Slack!!):

  • First Responder is no longer getting dismissed, whenever the Note Type is switched
  • selectionStyle is set to .none in the two Cells
  • Updated the firstResponder behavior to automatically toggle upon viewWillAppear / viewWillDisappear.

:shipit:

@mindgraffiti
Copy link
Contributor Author

Thank you Jorge!

@mindgraffiti mindgraffiti merged commit acdb3fc into develop Jul 27, 2018
@mindgraffiti mindgraffiti deleted the feature/75-add-note branch July 27, 2018 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants