Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Fix for "Disallow Empty Bug Reports" Issue #2615 #2676

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Fix for "Disallow Empty Bug Reports" Issue #2615 #2676

wants to merge 7 commits into from

Conversation

wayni208
Copy link
Contributor

@wayni208 wayni208 commented Mar 10, 2019

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.

Closes #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.
@wayni208
Copy link
Contributor Author

Hey I'm learning quite a bit about git lately. 😀

@Huddie Huddie added the 💤 awaiting review Pull Request is awaiting code reviews label Mar 10, 2019
Copy link
Collaborator

@Huddie Huddie left a comment

Choose a reason for hiding this comment

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

Some nits and suggestions! Looks great!

@@ -205,6 +213,20 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg
bodyField.inputAccessoryView = actions
}

func updateSubmitButtonState() {
if titleText == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe combine these 2 ifs with an or ( ||) or all three with a ternary. Something like

navigationItem.rightBarButtonItem?.isEnabled = ( titleText == nil || bodyText == nil ) ? false : true

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well the false : true is unnecessary, of course. Although you should then flip the result. 😊

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hahahahah! Yes correct on both points. Totally forget the ternary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I can change this around. How should I resubmit? I close and then do a new PR right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@wayni208 no need to close. Once you make a new commit to your branch it will update here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There we go! Thanks for the feedback and direction on that function. Such a more elegant way to get it done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome! Was about to say you don't have to reopen every time. 💯

@@ -213,11 +235,18 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg
return false
}

// MARK: UITextViewDelegatre
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Spelling - UITextViewDelegate

@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thoughts on rewording this alert? Maybe something kinder like:

Title: "Title Required" or "Issue requires title"
Body: "Please provide a title and try again"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, I like title option 2... and I like the body. Mind updating that, @wayni208?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before I resolve this and because I had made the change before you replied @BasThomas , are we good on the message as I've written it? Here are both:

        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
        }

Also

cancelAction_onCancel(
            texts: [titleText, bodyText],
            title: NSLocalizedString("Unsaved Changes", comment: "New Issue - Cancel w/ Unsaved Changes Title"),
            message: NSLocalizedString("Are you sure you want to discard this new issue? Your message will be lost.",
                                       comment: "New Issue - Cancel w/ Unsaved Changes Message")
        )

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good!

Spelling error. Change in wording when Squawk error  messages fire. Rewrote updateSubmitButtonState function to be more effective .
@@ -205,6 +213,10 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg
bodyField.inputAccessoryView = actions
}

func updateSubmitButtonState() {
navigationItem.rightBarButtonItem?.isEnabled = ( titleText == nil || bodyText == nil ) ? false : true
Copy link
Collaborator

@Huddie Huddie Mar 10, 2019

Choose a reason for hiding this comment

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

Like @BasThomas mentioned, you actually can just leave it as

navigationItem.rightBarButtonItem?.isEnabled = !(titleText == nil || bodyText == nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you did there. 😀

Further revised updateSubmitButtonState function
}

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I think this might be a bit confusing. Of course a good issue description is welcome, but not required. GitHub itself allows an empty body; I think we shouldn't fight that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about we just throw up an "Are you sure you want to submit this issue with no description?" confirmation before send?

#2615

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BasThomas @Huddie

I've made a few changes and reverted back to the original behavior where it would turn on the submit button once the titleField had changes. I've also added a confirmation dialogue notifying the user they have no description text and asking if they still want to submit or return to then form to add one.

I had to do a funky deal to get the dialogue correct. I split the onSend function in two because of the @objc function call in the accessibility button function and I needed another function to call on if the user decided to go ahead with the submit. I'm pretty certain this could have been done an easier way so please take a look and give me some direction if there is a better way to implement this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest I'm still in favor of allowing an empty description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BasThomas as in not popping an alert before sending an empty description?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exactly!

@@ -205,6 +213,10 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg
bodyField.inputAccessoryView = actions
}

func updateSubmitButtonState() {
navigationItem.rightBarButtonItem?.isEnabled = !( titleText == nil || bodyText == nil )
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should split this up a bit, with the goal of making it easier to read (and again, not requiring a body).

What do you think about the following?

let hasTitleText = titleText != nil
let isTitleTextEmpty = titleText?.isEmpty == true // This would be additional. We could even check for whitespace only in the future if we want to.
navigationItem.rightBarButtonItem?.isEnabled = hasTitleText && isTitleTextEmpty == 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.

Higher up our titleText variable is checking for empty and whitespace.

private var titleText: String? {
        guard let raw = titleField.text?.trimmingCharacters(in: .whitespacesAndNewlines) else { return nil }
        if raw.isEmpty { return nil }
        return raw
}

I think the best option would be to revert to the original. If we are doing away with the UITextViewDelegate and not checking bodyField to turn on the Submit button we can get rid of that function completely.

@IBAction func titleFieldEditingChanged(_ sender: Any) {
        navigationItem.rightBarButtonItem?.isEnabled = titleText != nil
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I missed that. Go ahead.

@@ -213,11 +225,18 @@ 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome you thought about the header docs! If we drop the body requirement though, this should be updated.

@@ -205,6 +213,10 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg
bodyField.inputAccessoryView = actions
}

func updateSubmitButtonState() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you like to write a test for this? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do away with that function as I mentioned. But if we don't, I sure will!

Copy link
Contributor Author

@wayni208 wayni208 Mar 11, 2019

Choose a reason for hiding this comment

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

I'm concerned about having split that onSend function in two and if I need to write a test for it. Also concerned about writing the test. I couldn't see anywhere where we are currently testing this portion of the code. I'm unfamiliar with tests in general so if you could give me some direction on this I would appreciate it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll get back to you on this one once I have a bit more time. Let's leave it for now; it's OK :)

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.
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.
Copy link
Collaborator

@Huddie Huddie left a comment

Choose a reason for hiding this comment

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

Few changes. Getting there!

Classes/New Issue/NewIssueTableViewController.swift Outdated Show resolved Hide resolved
Classes/New Issue/NewIssueTableViewController.swift Outdated Show resolved Hide resolved
Classes/New Issue/NewIssueTableViewController.swift Outdated Show resolved Hide resolved
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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: indent

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just do .alert it will infer the type

Classes/New Issue/NewIssueTableViewController.swift Outdated Show resolved Hide resolved
@Huddie Huddie added 😴 awaiting changes Changes requested, waiting on author to update and removed 💤 awaiting review Pull Request is awaiting code reviews labels Mar 11, 2019
Cleaned up func onSend to remove redundancies
@Huddie Huddie added 💤 awaiting review Pull Request is awaiting code reviews and removed 😴 awaiting changes Changes requested, waiting on author to update labels Mar 11, 2019
} 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() }))
Copy link
Collaborator

@BasThomas BasThomas Mar 12, 2019

Choose a reason for hiding this comment

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

The indentation here is still a bit off.

(You can use ⌃+I to reindent a selection)

onSend method only guards against an empty titleField. If empty, calls Squawk.showIssueError to properly display error message in the bodyField above the keyboard.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💤 awaiting review Pull Request is awaiting code reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants