From a2505e1e494c5e0fbd4ef607479b977b38f0e415 Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Sat, 9 Mar 2019 21:22:18 -0600 Subject: [PATCH 1/7] Fix for "Disallow Empty Bug Reports" Issue #2615 Added new function in Squawk+GitHawk.swift, showIssueError, to handle error reporting through Squawk. The previous handling would display the error beneath the keyboard, on this form, and not be seen. Not that this should ever be seen. Added a function in NewIssueTableViewController.swift that checks both the UITextField and the UITextView for content before enabling the Submit button. After the Submit button is enabled and used, we will check once again to verify content, throwing visible errors via Squawk in the TextView if no text is present, before sending. --- .../NewIssueTableViewController.swift | 39 ++++++++++++++++--- Classes/Systems/Squawk+GitHawk.swift | 5 +++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index 343f903e3..e6f3997f7 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -44,7 +44,7 @@ protocol NewIssueTableViewControllerDelegate: class { func didDismissAfterCreatingIssue(model: IssueDetailsModel) } -final class NewIssueTableViewController: UITableViewController, UITextFieldDelegate { +final class NewIssueTableViewController: UITableViewController, UITextFieldDelegate, UITextViewDelegate { weak var delegate: NewIssueTableViewControllerDelegate? @@ -103,6 +103,9 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg titleField.delegate = self titleField.font = Styles.Text.body.preferredFont + // Setup the description textView to report if it has been edited + bodyField.delegate = self + // Setup markdown input view bodyField.githawkConfigure(inset: false) setupInputView() @@ -141,7 +144,12 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg /// Attempts to sends the current forms information to GitHub, on success will redirect the user to the new issue @objc func onSend() { guard let titleText = titleText else { - Squawk.showError(message: NSLocalizedString("You must provide a title!", comment: "Invalid title when sending new issue")) + Squawk.showIssueError(message: NSLocalizedString("You must provide a title!", comment: "Invalid title when sending new issue"), view: bodyField) + return + } + + guard let bodyText = bodyText else { + Squawk.showIssueError(message: NSLocalizedString("You must provide an issue description!", comment: "Invalid description when sending new issue"), view: bodyField) return } @@ -155,7 +163,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg owner: owner, repo: repo, title: titleText, - body: (bodyText ?? "") + signature) + body: bodyText + signature) ) { [weak self] result in guard let strongSelf = self else { return } strongSelf.setRightBarItemIdle() @@ -205,6 +213,20 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg bodyField.inputAccessoryView = actions } + func updateSubmitButtonState() { + if titleText == nil { + navigationItem.rightBarButtonItem?.isEnabled = false + return + } + + if bodyText == nil { + navigationItem.rightBarButtonItem?.isEnabled = false + return + } + + navigationItem.rightBarButtonItem?.isEnabled = true + } + // MARK: UITextFieldDelegate /// Called when the user taps return on the title field, moves their cursor to the body @@ -213,11 +235,18 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg return false } + // MARK: UITextViewDelegatre + + /// Called when editing changed on the body field, enable/disable submit button based on title and body + func textViewDidChange(_ bodyField: UITextView) { + updateSubmitButtonState() + } + // MARK: Actions - /// Called when editing changed on the title field, enable/disable submit button based on title text + /// Called when editing changed on the title field, enable/disable submit button based on title and body @IBAction func titleFieldEditingChanged(_ sender: Any) { - navigationItem.rightBarButtonItem?.isEnabled = titleText != nil + updateSubmitButtonState() } } diff --git a/Classes/Systems/Squawk+GitHawk.swift b/Classes/Systems/Squawk+GitHawk.swift index 2eb5f9f6a..9968a09af 100644 --- a/Classes/Systems/Squawk+GitHawk.swift +++ b/Classes/Systems/Squawk+GitHawk.swift @@ -83,4 +83,9 @@ extension Squawk { triggerHaptic() } + static func showIssueError(message: String, view: UIView?) { + Squawk.shared.show(in: view, config: errorConfig(text: message)) + triggerHaptic() + } + } From a8137a83ac93751bd1f7d6eeda2d171cbc188b52 Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Sat, 9 Mar 2019 22:10:55 -0600 Subject: [PATCH 2/7] Fix for "Disallow Empty Bug Reports" Issue #2615 Spelling error. Change in wording when Squawk error messages fire. Rewrote updateSubmitButtonState function to be more effective . --- .../NewIssueTableViewController.swift | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index e6f3997f7..fa313039d 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -144,12 +144,12 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg /// Attempts to sends the current forms information to GitHub, on success will redirect the user to the new issue @objc func onSend() { guard let titleText = titleText else { - Squawk.showIssueError(message: NSLocalizedString("You must provide a title!", comment: "Invalid title when sending new issue"), view: bodyField) + Squawk.showIssueError(message: NSLocalizedString("An issue title is required. Please add a title and try again.", comment: "Invalid title when sending new issue"), view: bodyField) return } guard let bodyText = bodyText else { - Squawk.showIssueError(message: NSLocalizedString("You must provide an issue description!", comment: "Invalid description when sending new issue"), view: bodyField) + Squawk.showIssueError(message: NSLocalizedString("Please provide as much of a detailed description possible and try again.", comment: "Invalid description when sending new issue"), view: bodyField) return } @@ -214,19 +214,9 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg } func updateSubmitButtonState() { - if titleText == nil { - navigationItem.rightBarButtonItem?.isEnabled = false - return - } - - if bodyText == nil { - navigationItem.rightBarButtonItem?.isEnabled = false - return - } - - navigationItem.rightBarButtonItem?.isEnabled = true + navigationItem.rightBarButtonItem?.isEnabled = ( titleText == nil || bodyText == nil ) ? false : true } - + // MARK: UITextFieldDelegate /// Called when the user taps return on the title field, moves their cursor to the body @@ -235,7 +225,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg return false } - // MARK: UITextViewDelegatre + // MARK: UITextViewDelegate /// Called when editing changed on the body field, enable/disable submit button based on title and body func textViewDidChange(_ bodyField: UITextView) { From bceb428e8a42800f6e64a6ae2cd20783ee5c889a Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Sat, 9 Mar 2019 23:09:13 -0600 Subject: [PATCH 3/7] Fix for "Disallow Empty Bug Reports" Issue #2615 Further revised updateSubmitButtonState function --- Classes/New Issue/NewIssueTableViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index fa313039d..b8856ecb7 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -214,7 +214,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg } func updateSubmitButtonState() { - navigationItem.rightBarButtonItem?.isEnabled = ( titleText == nil || bodyText == nil ) ? false : true + navigationItem.rightBarButtonItem?.isEnabled = !( titleText == nil || bodyText == nil ) } // MARK: UITextFieldDelegate From d78d5048fa35d7558756b13e054f1f81d59f8aeb Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Sun, 10 Mar 2019 18:25:58 -0600 Subject: [PATCH 4/7] Fix for "Disallow Empty Bug Reports" Issue #2615 Reverted to original code for function titleFieldEditingChanged. Removed textViewDelegate and updateSubmitButtonState function which watched both titleField and bodyField for content before enabling the Submit button. Split onSend function in two separate functions, onSend and finishSend. onSend now looks for content in bodyField and if none is found instantiates an IAAlertController to notify the user that they are missing a description and giving them the option to send it anyway or return to the form and add one. finishSend completes the send. --- .../NewIssueTableViewController.swift | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index b8856ecb7..33c38a8fc 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -44,7 +44,7 @@ protocol NewIssueTableViewControllerDelegate: class { func didDismissAfterCreatingIssue(model: IssueDetailsModel) } -final class NewIssueTableViewController: UITableViewController, UITextFieldDelegate, UITextViewDelegate { +final class NewIssueTableViewController: UITableViewController, UITextFieldDelegate { weak var delegate: NewIssueTableViewControllerDelegate? @@ -103,9 +103,6 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg titleField.delegate = self titleField.font = Styles.Text.body.preferredFont - // Setup the description textView to report if it has been edited - bodyField.delegate = self - // Setup markdown input view bodyField.githawkConfigure(inset: false) setupInputView() @@ -143,13 +140,26 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg /// Attempts to sends the current forms information to GitHub, on success will redirect the user to the new issue @objc func onSend() { - guard let titleText = titleText else { - Squawk.showIssueError(message: NSLocalizedString("An issue title is required. Please add a title and try again.", comment: "Invalid title when sending new issue"), view: bodyField) - return + if let bodyText = bodyText { + self.finishSend() + } else { + let submitAlert = UIAlertController(title: "Please Provide Description", message: "Are you certain you want to submit this issue without a description?", preferredStyle: UIAlertControllerStyle.alert) + + submitAlert.addAction(UIAlertAction(title: "Submit", style: .default, handler: { (action: UIAlertAction!) in + self.finishSend() + })) + + submitAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in + self.viewDidLoad() + })) + + present(submitAlert, animated: true, completion: nil) } - guard let bodyText = bodyText else { - Squawk.showIssueError(message: NSLocalizedString("Please provide as much of a detailed description possible and try again.", comment: "Invalid description when sending new issue"), view: bodyField) + } + func finishSend() { + guard let titleText = titleText else { + Squawk.showIssueError(message: NSLocalizedString("An issue title is required. Please add a title and try again.", comment: "Invalid title when sending new issue"), view: bodyField) return } @@ -163,7 +173,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg owner: owner, repo: repo, title: titleText, - body: bodyText + signature) + body: (bodyText ?? "") + signature) ) { [weak self] result in guard let strongSelf = self else { return } strongSelf.setRightBarItemIdle() @@ -213,11 +223,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg bodyField.inputAccessoryView = actions } - func updateSubmitButtonState() { - navigationItem.rightBarButtonItem?.isEnabled = !( titleText == nil || bodyText == nil ) - } - - // MARK: UITextFieldDelegate + // MARK: UITextFieldDelegate /// Called when the user taps return on the title field, moves their cursor to the body func textFieldShouldReturn(_ textField: UITextField) -> Bool { @@ -225,18 +231,11 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg return false } - // MARK: UITextViewDelegate - - /// Called when editing changed on the body field, enable/disable submit button based on title and body - func textViewDidChange(_ bodyField: UITextView) { - updateSubmitButtonState() - } - // MARK: Actions /// Called when editing changed on the title field, enable/disable submit button based on title and body @IBAction func titleFieldEditingChanged(_ sender: Any) { - updateSubmitButtonState() + navigationItem.rightBarButtonItem?.isEnabled = titleText != nil } } From a43a06f4080c9a104a303a51d5631ed957406e92 Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Sun, 10 Mar 2019 18:39:07 -0600 Subject: [PATCH 5/7] Fix for "Disallow Empty Bug Reports" Issue #2615 Reverted to original code for function titleFieldEditingChanged. Removed textViewDelegate and updateSubmitButtonState function which watched both titleField and bodyField for content before enabling the Submit button. Split onSend function in two separate functions, onSend and finishSend. onSend now looks for content in bodyField and if none is found instantiates an IAAlertController to notify the user that they are missing a description and giving them the option to send it anyway or return to the form and add one. finishSend completes the send. --- Classes/New Issue/NewIssueTableViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index 33c38a8fc..5c3de683d 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -150,7 +150,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg })) submitAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in - self.viewDidLoad() + submitAlert .dismiss(animated: true, completion: nil) })) present(submitAlert, animated: true, completion: nil) From 26bdaff7d94ff0ad56a5303c9c6d2d2d0ff8d1b8 Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Sun, 10 Mar 2019 23:45:34 -0600 Subject: [PATCH 6/7] Fix for "Disallow Empty Bug Reports" Issue #2615 Cleaned up func onSend to remove redundancies --- .../New Issue/NewIssueTableViewController.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index 5c3de683d..44243c683 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -141,22 +141,18 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg /// Attempts to sends the current forms information to GitHub, on success will redirect the user to the new issue @objc func onSend() { if let bodyText = bodyText { - self.finishSend() + finishSend() } else { - let submitAlert = UIAlertController(title: "Please Provide Description", message: "Are you certain you want to submit this issue without a description?", preferredStyle: UIAlertControllerStyle.alert) + let submitAlert = UIAlertController(title: "Please Provide Description", message: "Are you certain you want to submit this issue without a description?", preferredStyle: .alert) - submitAlert.addAction(UIAlertAction(title: "Submit", style: .default, handler: { (action: UIAlertAction!) in - self.finishSend() - })) + submitAlert.addAction(UIAlertAction(title: "Submit", style: .default, handler: { _ in self.finishSend() })) + submitAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel)) - submitAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in - submitAlert .dismiss(animated: true, completion: nil) - })) - - present(submitAlert, animated: true, completion: nil) + present(submitAlert, animated: true) } } + func finishSend() { guard let titleText = titleText else { Squawk.showIssueError(message: NSLocalizedString("An issue title is required. Please add a title and try again.", comment: "Invalid title when sending new issue"), view: bodyField) From 3a162975fb67d1249cd50db4b7f18e82afe18384 Mon Sep 17 00:00:00 2001 From: Wayne Nihart Date: Tue, 12 Mar 2019 16:08:06 -0600 Subject: [PATCH 7/7] Fix for "Disallow Empty Bug Reports" Issue #2615 onSend method only guards against an empty titleField. If empty, calls Squawk.showIssueError to properly display error message in the bodyField above the keyboard. --- .../New Issue/NewIssueTableViewController.swift | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Classes/New Issue/NewIssueTableViewController.swift b/Classes/New Issue/NewIssueTableViewController.swift index 44243c683..37dcb3597 100644 --- a/Classes/New Issue/NewIssueTableViewController.swift +++ b/Classes/New Issue/NewIssueTableViewController.swift @@ -140,20 +140,7 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg /// Attempts to sends the current forms information to GitHub, on success will redirect the user to the new issue @objc func onSend() { - if let bodyText = bodyText { - finishSend() - } else { - let submitAlert = UIAlertController(title: "Please Provide Description", message: "Are you certain you want to submit this issue without a description?", preferredStyle: .alert) - - submitAlert.addAction(UIAlertAction(title: "Submit", style: .default, handler: { _ in self.finishSend() })) - submitAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel)) - - present(submitAlert, animated: true) - } - - } - - func finishSend() { + guard let titleText = titleText else { Squawk.showIssueError(message: NSLocalizedString("An issue title is required. Please add a title and try again.", comment: "Invalid title when sending new issue"), view: bodyField) return