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

Merged
merged 5 commits into from
Jan 14, 2025
Merged

Add ID to validation_issue #10521

merged 5 commits into from
Jan 14, 2025

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.

lib/results_validators/persons_validator.rb Show resolved Hide resolved
@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 3 times, most recently from 0a39b98 to 188fb17 Compare January 9, 2025 06:31
@danieljames-dj danieljames-dj marked this pull request as ready for review January 9, 2025 06:31
Copy link
Member

@gregorbg gregorbg left a comment

Choose a reason for hiding this comment

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

The structure and concept is totally fine by me. I haven't reviewed all individual copy-paste operations though, perhaps a second WRT member could make sure you haven't accidentally swapped any validation messages?

@danieljames-dj
Copy link
Member Author

The structure and concept is totally fine by me. I haven't reviewed all individual copy-paste operations though, perhaps a second WRT member could make sure you haven't accidentally swapped any validation messages?

Sure, I'll ask WRT to do it.

@danieljames-dj
Copy link
Member Author

@thewca-bot deploy staging

@gregorbg gregorbg merged commit 1c2629d into thewca:main Jan 14, 2025
2 checks passed
@danieljames-dj danieljames-dj deleted the validation_id branch January 14, 2025 12:16
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