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 ID to validation_issue #10521

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

danieljames-dj
Copy link
Member

Currently there is no identifier for validation issue, this PR aims in adding ID so that this will help in many future features.

@danieljames-dj danieljames-dj marked this pull request as draft January 3, 2025 13:52
@@ -46,17 +46,17 @@ def self.dob_validations(dob, competition_id = nil, name = nil)

# Check if DOB is January 1
if dob.month == 1 && dob.day == 1
validation_issues << ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, name: name)
validation_issues << ValidationWarning.new(:dob_jan_one, :persons, competition_id, DOB_0101_WARNING, name: name)
Copy link
Member Author

Choose a reason for hiding this comment

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

@gregorbg This is my initial plan for adding IDs. I think it will be better if the IDs are fetched from an enum-like object instead of directly adding the ID here. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Well, what exactly are you suggesting? I mean, the idea sounds nice, so what kind of "enum-like" structure are you thinking about?

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've implemented that - I feel that is more easier than typing. Can you please check the implementation now? Can I go ahead with the same for all definitions or do you have any feedbacks before making change in other definitions?

Comment on lines 13 to 15
VALIDATION_TYPES = VALIDATION_TYPES_KEYS.each_with_object({}) do |key, hash|
hash[key] = key.to_s
end.freeze
Copy link
Member

Choose a reason for hiding this comment

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

I am definitely sure that I told you this trick before, but I'll tell you again:
my_list.index_with { |list_elem| list_elem.to_s } or even shorter my_list.index_with(&:to_s)

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 remember you said the trick, but I didn't remembered it from top of my head so just went ahead with copilot suggestion for time being. Truly I had plan to optimize it later.

Thanks for giving the shorthand again, I've added them now.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... I get what you're going for, and I like the "type safety" kinda idea behind your approach.
However the actual implementation is extremely verbose. Basically you have to spell out a meaningless ValidationIssue::VALIDATION_TYPES every time you build a validation.

(And the "turn the array of keys into a hash that holds its own keys as values" also feels somewhat awkward. Again, I totally get your idea, but the implentation is a bit cumbersome to use)

Copy link
Member

Choose a reason for hiding this comment

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

Did you try consulting ChatGPT (or Copilot or Gemini or whatever) for some ideas?

From the top of my head (haven't thought this through in detail, just spontaneous) you could try passing only the :dob_jan_one constant as a parameter, and have the initialize method in the validation warning check whether that's actually a valid "type". Our test suite would then catch any use-cases with an invalid argument

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 checked with gemini, but didn't get anything good. Your idea actually looks better. I've implemented that now.

@danieljames-dj
Copy link
Member Author

@gregorbg Can you please let me know if this aligns with what we discussed? If yes, can I go ahead with making these changes in the other initializations?

lib/results_validators/persons_validator.rb Outdated Show resolved Hide resolved
lib/results_validators/validation_issue.rb Outdated Show resolved Hide resolved
@@ -18,7 +19,7 @@ function EditPersonValidations({ ticketDetails }) {
if (error) return <Errored />;

return validators.dob.map((validator) => (
<Message warning>{validator.message}</Message>
<Message warning>{I18n.t(`validators.person.${validator.id}`)}</Message>
Copy link
Member

Choose a reason for hiding this comment

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

This will not fill the i18n keys correctly, I'm afraid

Copy link
Member

Choose a reason for hiding this comment

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

I.e. the message will look like "The date of birth of [missing 'name' param] is on January 1st"

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, actually the same error is there in production as well. Since this is internal to WRT, I thought of adjusting with this error because knowing 'something is wrong' is better than knowing nothing.

TBH I didn't spend time to check if name can be populated here. I guess it should be possible through ticketDetails. I'll explore if that is possible.

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 just checked and WCA ID is available. For now I have added WCA ID. But I feel this fix should be separate PR, I'll do that later. For now I've added it in this PR, will change later.

@kind = kind
@args = message_args
@competition_id = competition_id
end

def to_s
format(@message, @args)
I18n.t("validators.person.#{@id}", **@args)
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to include @kind in this message instead of hard-coding person

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yes, changed.

@danieljames-dj danieljames-dj force-pushed the validation_id branch 2 times, most recently from 6590b3e to 0a39b98 Compare January 9, 2025 06:00
@danieljames-dj danieljames-dj marked this pull request as ready for review January 9, 2025 06:31
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.

2 participants