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

feat:Added functionality to retrieve and save GitHub token (#812) #839

Merged
merged 10 commits into from
Aug 3, 2024

Conversation

wblxxx
Copy link
Contributor

@wblxxx wblxxx commented Jul 21, 2024

Brief Information

This pull request is in the type of (more info about types):

  • build
  • ci
  • docs
  • feat
  • fix
  • perf
  • refactor
  • test

Related issues (GitHub tokens):

Details

Recently, there has been a #773 (comment) in the community about GitHub Tokens. In fact, HyperCRX had previously introduced GitHub Tokens to increase the number of requests made to GitHub, as seen in #100. However, in #574, we removed it since there was no longer a frequent need to access the GitHub API.

Considering that HyperCRX may need to frequently access the GitHub API in the future, we need to reintroduce GitHub Tokens with the following specific requirements:

Provide a UI interface allowing users to input their GitHub Tokens.
Securely store user's Tokens.
Encapsulate a network request method that uses the GitHub Token, which will be called by other new features needing to access the GitHub API in the future.

Checklist

Others

Copy link
Collaborator

@wxharry wxharry left a comment

Choose a reason for hiding this comment

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

Nice work. We are close. Here are what we can do to improve this branch.

  1. Please look into comments and remove or update what are needed to.
  2. We need to use English within the project, so please update all messages to English and use i18next for supporting other languages. reference to [OSS101] Task 1: Refactor the existing multiple languages feature by adopting a third i18n library #805
  3. Let's move the save button to the same line of the token input form. When user click on save, the input form would turn into a text and show only characters at the beginning and the end, hide the others with * and the save button becomes a edit button.
image
  1. For alerts, we should use user-friendly popup from our ui library. For example, message from antd. Looks like alerts block interactions with browser until we confirm.

  2. On test token, can we use the token in the input form? It is intuitive to see the token there and click to test if it is valid. let me know what you think.

cc @HalloMelon for UI changes.

src/api/githubApi.ts Outdated Show resolved Hide resolved
src/api/githubApi.ts Outdated Show resolved Hide resolved
src/pages/Options/GitHubToken.tsx Outdated Show resolved Hide resolved
src/pages/Options/GitHubToken.tsx Outdated Show resolved Hide resolved
src/pages/Options/GitHubToken.tsx Outdated Show resolved Hide resolved
src/pages/Options/Options.tsx Outdated Show resolved Hide resolved
src/api/githubApi.ts Outdated Show resolved Hide resolved
Signed-off-by: wblx <904653630@qq.com>
@wblxxx
Copy link
Contributor Author

wblxxx commented Jul 29, 2024

Sorry for the delay in making the changes until today. Thank you for your diligent review. I have resolved all the issues in the latest version. Additionally, using the token in the input form is intuitive and user-friendly, as it enables immediate feedback on the token's validity, which I have adopted. If there are any further issues, please continue to correct me.

@wblxxx wblxxx requested a review from wxharry July 29, 2024 08:28
Signed-off-by: wblx <904653630@qq.com>
Copy link
Collaborator

@wxharry wxharry left a comment

Choose a reason for hiding this comment

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

Almost there! Some minor enhancements are needed before we merge it. The biggest issue it that I can't see the message, not sure what's happend. I didn't take a close look at the code. Let me know if it works for you or you need more info from me.

src/helpers/githubApi.ts Outdated Show resolved Hide resolved
src/helpers/githubApi.ts Outdated Show resolved Hide resolved
src/helpers/githubApi.ts Outdated Show resolved Hide resolved
src/pages/Options/components/GitHubToken.tsx Outdated Show resolved Hide resolved
src/helpers/githubApi.ts Outdated Show resolved Hide resolved
@wxharry
Copy link
Collaborator

wxharry commented Jul 30, 2024

Almost there! Some minor enhancements are needed before we merge it. The biggest issue it that I can't see the message, not sure what's happend. I didn't take a close at the code. Let me know if it works for you or you need more info from me.

I think I figured that out. The token won't be valid until I click save. But in the code, I can see that we are using token from the githubRequest as part of input.

Comment on lines 22 to 26
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is causing the bug. options has the same thing as headers, they are duplicate. I think we can just keep ...options and remove the rest.

Signed-off-by: wblx <904653630@qq.com>
Signed-off-by: wblx <904653630@qq.com>
@wblxxx
Copy link
Contributor Author

wblxxx commented Jul 30, 2024

Your suggestion makes a lot of sense. I appreciate your effort in reviewing the new version.

@wblxxx
Copy link
Contributor Author

wblxxx commented Jul 30, 2024

I simplified the githubApi.ts and moved the decision logic to GitHubToken.tsx.By the way,if we are only using githubToken to get the token from localStorage, we can directly use localStorage.getItem('github_token') ,the previous approach might reduce the number of accesses to localStorage in scenarios where githubRequest is called frequently, thereby improving performance.

@wblxxx wblxxx requested a review from wxharry July 30, 2024 06:47
@wxharry
Copy link
Collaborator

wxharry commented Jul 31, 2024

This is causing the bug. options has the same thing as headers, they are duplicate. I think we can just keep ...options and remove the rest.

Did you solve this? I don't get any response if I set the headers twice. Removing duplicate options works for me but the message is still not showing. Nothing is showing in the console. Do you have any ideas?

@wblxxx
Copy link
Contributor Author

wblxxx commented Jul 31, 2024

This is causing the bug. options has the same thing as headers, they are duplicate. I think we can just keep ...options and remove the rest.

Did you solve this? I don't get any response if I set the headers twice. Removing duplicate options works for me but the message is still not showing. Nothing is showing in the console. Do you have any ideas?

This is so strange. The day before yesterday, everything was normal when I was using and uploading the code. Yesterday, there were no message when I first clicked, but during the process of modifying the code, it naturally recovered, and everything remained normal for several hours after uploading. Just now, there were no message when I first clicked, but after having a meal, it was fine. I'm thinking about it.

Signed-off-by: wblx <904653630@qq.com>
@wblxxx
Copy link
Contributor Author

wblxxx commented Jul 31, 2024

This is causing the bug. options has the same thing as headers, they are duplicate. I think we can just keep ...options and remove the rest.

Did you solve this? I don't get any response if I set the headers twice. Removing duplicate options works for me but the message is still not showing. Nothing is showing in the console. Do you have any ideas?

I suspect that the previous fixed position of the message pop-up might have caused it to be invisible in some cases. I have adjusted it to dynamically calculate the position of the message. However, since it has always run successfully on my side, I cannot determine if the bug still exists. Please test it and provide feedback promptly.
iShot_2024-07-31_15 13 29

@wblxxx
Copy link
Contributor Author

wblxxx commented Aug 1, 2024

I checked today, and the issue didn't happen again.

@wxharry
Copy link
Collaborator

wxharry commented Aug 1, 2024

I suspect that the previous fixed position of the message pop-up might have caused it to be invisible in some cases. I have adjusted it to dynamically calculate the position of the message. However, since it has always run successfully on my side, I cannot determine if the bug still exists. Please test it and provide feedback promptly. iShot_2024-07-31_15 13 29

Would it be easier to move it to the top of the page? because messages usually appear at the top by default. This is not a change request, you can keep it this way if that could cause the message invisible issue.

Also, did we figure out why we have duplicate options here? #839 (comment)

Signed-off-by: wblx <904653630@qq.com>
@wblxxx
Copy link
Contributor Author

wblxxx commented Aug 1, 2024

I suspect that the previous fixed position of the message pop-up might have caused it to be invisible in some cases. I have adjusted it to dynamically calculate the position of the message. However, since it has always run successfully on my side, I cannot determine if the bug still exists. Please test it and provide feedback promptly. iShot_2024-07-31_15 13 29

Would it be easier to move it to the top of the page? because messages usually appear at the top by default. This is not a change request, you can keep it this way if that could cause the message invisible issue.

Also, did we figure out why we have duplicate options here? #839 (comment)

By default, the response message appears at the top, but at that time, the user's attention is focused on the GitHubToken component area. If it appears at the top, they might not notice it, and shifting their gaze to focus on the content and then back is also not user-friendly. Therefore, I think the current interaction is better. Additionally, if our function is only to pass in the GitHub token and does not need to retain other request configurations or header information, then ...options and ...options.headers are indeed redundant. The code can be simplified, and I have made the modifications.

@wxharry
Copy link
Collaborator

wxharry commented Aug 2, 2024

LGTM. Thanks for your efforts! Looks like the branch needs formatting. Please run yarn run prettier.

@wblxxx
Copy link
Contributor Author

wblxxx commented Aug 2, 2024

LGTM. Thanks for your efforts! Looks like the branch needs formatting. Please run yarn run prettier.

I have always used Prettier to check the code format, and there are no issues when checking locally. The PR is also fully synchronized, so I don't know where the problem is.
iShot_2024-08-02_14 25 53
iShot_2024-08-02_14 28 50

@wxharry
Copy link
Collaborator

wxharry commented Aug 3, 2024

I have always used Prettier to check the code format, and there are no issues when checking locally. The PR is also fully synchronized, so I don't know where the problem is. iShot_2024-08-02_14 25 53 iShot_2024-08-02_14 28 50

This is weird! My prettier gives three files that need to be fixed. Do you mind I adding those changes to this branch?

image

@wblxxx
Copy link
Contributor Author

wblxxx commented Aug 3, 2024

I have always used Prettier to check the code format, and there are no issues when checking locally. The PR is also fully synchronized, so I don't know where the problem is. iShot_2024-08-02_14 25 53 iShot_2024-08-02_14 28 50

This is weird! My prettier gives three files that need to be fixed. Do you mind I adding those changes to this branch?

image

It looks like the versions are different, but of course, it's okay.

Signed-off-by: Harry <xiaohanwu12@gmail.com>
@wxharry wxharry merged commit 3b23005 into hypertrons:master Aug 3, 2024
2 checks passed
wangyantong2000 pushed a commit to wangyantong2000/hypertrons-crx that referenced this pull request Aug 22, 2024
…s#839)

* feat:Added functionality to retrieve and save GitHub token (hypertrons#812)

Signed-off-by: wblx <904653630@qq.com>

* solved all the problems

Signed-off-by: wblx <904653630@qq.com>

* sync

* Resolve inconsistent margins

Signed-off-by: wblx <904653630@qq.com>

* response problem

Signed-off-by: wblx <904653630@qq.com>

* duplicated options

Signed-off-by: wblx <904653630@qq.com>

* chore: run prettier to format

Signed-off-by: Harry <xiaohanwu12@gmail.com>

---------

Signed-off-by: wblx <904653630@qq.com>
Signed-off-by: Harry <xiaohanwu12@gmail.com>
wangyantong2000 added a commit that referenced this pull request Aug 27, 2024
* replace with OSGraph

* replace with OSGraph

* fix osgraph

* fix OSGraph

* fix OSGraph

* feat:Added functionality to retrieve and save GitHub token (#839)

* feat:Added functionality to retrieve and save GitHub token (#812)

Signed-off-by: wblx <904653630@qq.com>

* solved all the problems

Signed-off-by: wblx <904653630@qq.com>

* sync

* Resolve inconsistent margins

Signed-off-by: wblx <904653630@qq.com>

* response problem

Signed-off-by: wblx <904653630@qq.com>

* duplicated options

Signed-off-by: wblx <904653630@qq.com>

* chore: run prettier to format

Signed-off-by: Harry <xiaohanwu12@gmail.com>

---------

Signed-off-by: wblx <904653630@qq.com>
Signed-off-by: Harry <xiaohanwu12@gmail.com>

* Update the info about ”GitHub Token Configuration“ (#858)

* update the info in the "GitHub Token Configuration"

* update the info about token

* fix: modify the URL link of the webpage

* fix: modify the URL link of the webpage

* fix: modify page judgment criteria

* fix: modify the URL link of the webpage

fix: modify the URL link of the webpage

fix: modify page judgment criteria

fix: modify page judgment criteria

fix: reserved digits for the length of the contributor bar (#861)

fix: Perceptor tab missing icon (#863)

fix: Perceptor tab is not selected after refreshing (#864)

fix
fix

* code optimization

* style optimization

* modify the jump method

---------

Signed-off-by: wblx <904653630@qq.com>
Signed-off-by: Harry <xiaohanwu12@gmail.com>
Co-authored-by: Sylvan <60059315+wblxxx@users.noreply.github.com>
Co-authored-by: Scarlett Zhao <79428895+HalloMelon@users.noreply.github.com>
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