Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for cutoff score in ImportPeptideSearchDlg #2752

Merged
merged 5 commits into from
Nov 27, 2023

Conversation

bspratt
Copy link
Member

@bspratt bspratt commented Oct 16, 2023

No description provided.

@bspratt bspratt requested review from chambm and brendanx67 October 16, 2023 20:46
#region test_support

// For test purposes, lets us test error handling
public void SetCutoffControlText(string cutoffControlText)
Copy link
Member

Choose a reason for hiding this comment

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

If properties like CutOffScore are only supposed to be used by tests and not by other Skyline application code, then I wonder whether it should be a string that gets/sets textCutoff.Text. Other than that, PR looks good.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand. The user can only deal in strings, we have to convert strings like textCutoff to values like CutoffScore, and gracefully deal with users typing in strings that don't make sense. We're pretty good about that, but for whatever reason this particular control never got any such validation code. The problem has been lurking for at least ten years.

Copy link
Member

Choose a reason for hiding this comment

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

I meant we wouldn't need the somewhat awkward SetCutoffControlText if CutoffScore was a string that gets/sets the control's text directly instead of trying to parse it. Then test code would set the text, just like a user would.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Keep in mind that the test would have to think about L10N when trying to represent fractional values, though. Probably even more awkward.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, devs would have to remember to do the .ToString(CultureInfo.CurrentCulture) bit after the number (or use a helper function). Which I admit is easy to forget (and I have done so).

However the double CutoffScore is much closer to the way the rest of Skyline does this testing. The difference is things like transition settings UI use a nullable property like double? CutoffScore and test that when setting CutoffScore to null, it triggers the Resources.MessageBoxHelper_ValidateDecimalTextBox__0__must_contain_a_decimal_value error. Is there a reason not to use ControlUtil.ValidateDecimalTextBox here? Testing a null control value is probably close enough to an invalid value like "12%@$@": they both should generate the same error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I should use that more centralized code for consistency, will do.

@brendanx67
Copy link
Contributor

brendanx67 commented Oct 17, 2023 via email

@bspratt
Copy link
Member Author

bspratt commented Oct 17, 2023

I'll have to add some more centralized code for dealing with a decimal textbox that is allowed to be empty under some circumstances, as this one is.

@bspratt
Copy link
Member Author

bspratt commented Oct 17, 2023

Looks like it would be quite a lot of refactoring to centralize parsing of doubles - typical pattern is to use ValidateDecimalTextBox to verify that a text box can be understood as a double, then parse again later with a bare double.Parse(). So, a more L10N-tolerant handling of doubles is a nice idea but perhaps not worth the effort.

@chambm
Copy link
Member

chambm commented Oct 17, 2023

And handling it as an optional input seems tricky too with just a double?. Using null as "invalid input" means it can't also be used for "user left field empty".

@brendanx67
Copy link
Contributor

brendanx67 commented Oct 17, 2023 via email

Copy link
Contributor

@brendanx67 brendanx67 left a comment

Choose a reason for hiding this comment

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

Close, but I would prefer a little code clean-up to make it clearer that the standard pattern is being employed. Put the MessageBoxHelper in the NextPage() function and use it the set a private double? _cutoffScore.

@bspratt bspratt merged commit 746bce2 into master Nov 27, 2023
1 check failed
@bspratt bspratt deleted the Skyline/work/20231016_validate_cutoff_score branch November 27, 2023 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants