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

Using database for translations for cross-devices #2077

Merged

Conversation

pranshugupta54
Copy link
Member

@pranshugupta54 pranshugupta54 commented Jul 6, 2024

What kind of change does this PR introduce?

Feature: With this PR merge, now we will use the language from DB. So if you change the language in your profile, it will use that language on login (on any device)

Issue Number:

Fixes #2076

Did you add tests for your changes?

Yes

Snapshots/Videos:

N/A

If relevant, did you update the documentation?

NA

Summary

  • Checking language on login
  • When user changes the language in settings, POSTing it to the DB.

Does this PR introduce a breaking change?

No

Other information

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Added functionality to update the user's app language setting via a GraphQL mutation.
  • Improvements

    • Enhanced language dropdown to update user language setting in the backend before changing the app language.
    • Login page now sets the app language based on user profile settings from the backend.
    • Member detail page now properly reflects the app language selection.
  • Code Quality

    • Refactored imports and language setting logic to improve code maintainability.

Copy link
Contributor

coderabbitai bot commented Jul 6, 2024

Walkthrough

The recent changes enable storing user language preferences in the database instead of localStorage to support multiple devices. This includes updating GraphQL mutations (UPDATE_USER_MUTATION, LOGIN_MUTATION) to handle appLanguageCode, modifying the language dropdown to perform a GraphQL mutation when changing language, and aligning the language setting on login. Adjustments to the import order were made, and UI elements were updated to reflect new functionalities.

Changes

File Path Change Summary
src/GraphQl/Mutations/mutations.ts Added appLanguageCode parameter to UPDATE_USER_MUTATION and LOGIN_MUTATION.
src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx Included logic to update user language via GraphQL mutation in changeLanguage function. Imported necessary modules and hooks.
src/index.tsx Adjusted import order of i18n and added a reference to set Accept-Language header.
src/screens/LoginPage/LoginPage.tsx Added call to i18n.changeLanguage() with loginData.login.appUserProfile.appLanguageCode.
src/screens/MemberDetail/MemberDetail.tsx Updated <select> element to include value={formState.appLanguageCode} and removed static placeholder text.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant Server
    participant DB

    User->>UI: Change language from dropdown
    UI->>Server: GraphQL mutation with `appLanguageCode`
    Server->>DB: Update user language setting
    DB-->>Server: Acknowledge update
    Server-->>UI: Confirm language update
    UI->>i18n: Change language using `i18n.changeLanguage()`
Loading

Assessment against linked issues

Objective Addressed Explanation
Store language settings in the database instead of localStorage (#2076)
Implement frontend changes to utilize the updated GraphQL API for language settings (#2076)

Poem

In the land of code where languages switch,
We store it in the database, such a rich pitch.
No more local storage, for devices we care,
Now fluent in all, our app's debonair.
GraphQL mutations make the code just right,
A seamless user experience, day and night.
🎩🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jul 6, 2024

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 45efc65 and d9c07c9.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (5)
  • src/GraphQl/Mutations/mutations.ts (3 hunks)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx (1 hunks)
  • src/index.tsx (2 hunks)
  • src/screens/LoginPage/LoginPage.tsx (2 hunks)
  • src/screens/MemberDetail/MemberDetail.tsx (2 hunks)
Additional comments not posted (9)
src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx (3)

6-8: Imports look good.

The new imports for UPDATE_USER_MUTATION and useMutation are correctly added and necessary for the new functionality.


21-21: Retrieval of userId looks good.

The userId is correctly retrieved from local storage using getItem.


22-22: Usage of useMutation looks good.

The useMutation hook for UPDATE_USER_MUTATION is correctly used and necessary for updating the user's language setting.

src/index.tsx (2)

46-46: Import statement looks good.

The import statement for i18n is correctly modified.


50-55: Setting the Accept-Language header looks good.

The Accept-Language header is correctly set based on the user's language preference using i18n.language.

src/GraphQl/Mutations/mutations.ts (2)

Line range hint 100-114:
Update to UPDATE_USER_MUTATION looks good.

The mutation is correctly updated to include appLanguageCode in the variables and input data.


190-190: Update to LOGIN_MUTATION looks good.

The mutation is correctly updated to include appLanguageCode in the returned data.

src/screens/MemberDetail/MemberDetail.tsx (1)

502-502: Binding of selected language value looks good.

The <select> element correctly binds the selected language value to the form state using value={formState.appLanguageCode}.

src/screens/LoginPage/LoginPage.tsx (1)

294-294: LGTM! But verify appLanguageCode presence and validity.

The code change ensures that the application interface matches the user's language preference after login.

However, ensure that loginData.login.appUserProfile.appLanguageCode is always defined and valid.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d9c07c9 and e4192ad.

Files selected for processing (2)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx (1 hunks)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx
Additional comments not posted (5)
src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx (5)

10-12: Imports Approved.

The new imports for MockedProvider, UPDATE_USER_MUTATION, and StaticMockLink are necessary for mocking the GraphQL mutation and are correctly imported.


22-40: Mocks Approved.

The MOCKS array correctly simulates the GraphQL mutation for updating the user's language preference.


42-42: StaticMockLink Usage Approved.

The StaticMockLink correctly uses the MOCKS array and ensures the mocked data is used in the tests.


46-52: Test Case Approved.

The test case correctly verifies if the ChangeLanguageDropDown component renders properly.


Line range hint 80-124:
Test Cases Approved.

The test cases correctly verify the component's props, language cookie handling, and language change functionality.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 6, 2024
@pranshugupta54
Copy link
Member Author

Note:

Deleted src/components/UserPortal/Login/Login.tsx, because it's not used anywhere.
We are using src/screens/LoginPage/LoginPage.tsx only.

Copy link

codecov bot commented Jul 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.91%. Comparing base (45efc65) to head (66a6523).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2077      +/-   ##
===========================================
- Coverage    97.92%   97.91%   -0.01%     
===========================================
  Files          232      231       -1     
  Lines         6208     6195      -13     
  Branches      1791     1788       -3     
===========================================
- Hits          6079     6066      -13     
  Misses         118      118              
  Partials        11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e4192ad and 66a6523.

Files selected for processing (2)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx (1 hunks)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropDown.tsx
  • src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.test.tsx

@palisadoes palisadoes merged commit fcd3ea8 into PalisadoesFoundation:develop Jul 7, 2024
12 checks passed
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.

[Translations] Language to be stored in DB instead of localStorage
2 participants