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

Modified edit-person script to accept WCA ID via query param and search option in country picker #8975

Merged
merged 5 commits into from
Mar 4, 2024

Conversation

danieljames-dj
Copy link
Member

No description provided.

@@ -0,0 +1,30 @@
import { useEffect, useState } from 'react';

function getQueryParamsFromBrowserUrl() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use Object.fromEntries here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow that's easier, changed.


useEffect(() => {
const searchParams = new URLSearchParams(queryParams).toString();
if (window.location.search !== searchParams) {
Copy link
Member

Choose a reason for hiding this comment

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

!== checks for referential equality. Since you are creating a new URLSearchParams object directly above, I feel like this comparison always yields true because they can by defintion never be the same.

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'm acutually converting it to string, but looks like window.location.search is having a prefix '?' when there is at least one param. I've handled that case as well. Now it's working fine I guess.

Copy link
Member

Choose a reason for hiding this comment

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

This approach looks like code duplication. I feel like we've dealt with this private attribute notion before, can you find a way to re-use the existing code?

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 tried, but couldn't find any way. The other place where it is used is in api_controller and there the result can be of any model - person or user or something else. Here, I want just the person model. The only way I can think of re-using is moving the check current_user && current_user.can_admin_results? to serializable_hash, which I think will make the serializable_hash more complex. Do you have any idea?

@danieljames-dj danieljames-dj changed the title Modified edit-person script to accept WCA ID via query param Modified edit-person script to accept WCA ID via query param and search option in country picker Mar 2, 2024
@danieljames-dj
Copy link
Member Author

Added search option in country picker as selecting country is tough now

{
person: person.serializable_hash(only: [:wca_id, :name, :url, :gender, :country_iso2, :delegate_status, :teams, :avatar]),
person: person.serializable_hash(only: [:wca_id, :name, :url, :gender, :country_iso2, :delegate_status, :teams, :avatar, private_attributes].flatten),
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 this should be person.serializable_hash(only: [...], private_attributes: [...]) so that the existing code in person.rb can pick it up.

Comment on lines 20 to 25
function updateQueryParam(key, value) {
setQueryParams({
...queryParams,
[key]: value,
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Should this be wrapped in useCallback?

@danieljames-dj danieljames-dj merged commit b0a7c5c into thewca:master Mar 4, 2024
1 check passed
@danieljames-dj danieljames-dj deleted the edit-person-fix branch March 4, 2024 19:30
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.

None yet

2 participants