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/recoil integrations #99

Merged
merged 15 commits into from
Sep 5, 2024
Merged

Conversation

shamoilattaar-wednesday
Copy link
Collaborator

@shamoilattaar-wednesday shamoilattaar-wednesday commented Sep 4, 2024

Ticket Link


Related Links


Description


Steps to Reproduce / Test


GIF's


Summary by CodeRabbit

  • New Features

    • Transitioned state management from Redux to Recoil for improved flexibility and simplicity.
    • Introduced new Recoil state management files for user data and app state.
  • Bug Fixes

    • Enhanced error handling and asynchronous behavior in the user service API calls.
  • Documentation

    • Updated ESLint configurations to improve code quality checks.
  • Chores

    • Updated project dependencies for improved compatibility and performance.
    • Modified GitHub Actions workflow to accommodate multiple branches and standardize linting command.
  • Tests

    • Refactored test suites to align with the new Recoil state management approach and enhance clarity.

Copy link

coderabbitai bot commented Sep 4, 2024

Warning

Rate limit exceeded

@shamoilattaar-wednesday has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 7 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between a49059b and 732b82a.

Walkthrough

The changes involve a transition from Redux to Recoil for state management across various components in the application. ESLint configurations have been updated, testing utilities modified, and dependencies in package.json adjusted. The internationalization logic has been simplified, and the API client has been refactored to use axios instead of apisauce. Additionally, several test files have been restructured to align with these updates.

Changes

File(s) Change Summary
.eslintignore Added entries to ignore web-build/**, webpack.config.js, and growthbook.js.
.eslintrc.js Adjusted complexity rule from 2 to 4; added rule to disable throwing exceptions in functional programming.
app/app.js Removed Redux setup; integrated Recoil for state management.
app/components/atoms/LanguageProvider/tests/index.test.js Restructured tests for LanguageProvider and ConnectedLanguageProvider, removing commented code.
app/i18n.js Removed constants and functions related to internationalization, simplifying the logic.
app/i18n.test.js Updated tests to focus on i18next configuration, removed tests for formatTranslationMessages.
app/navigators/appNavigator.js Added screenOptions to hide headers for all screens in the navigator.
app/scenes/ExampleScreen/index.js Transitioned from Redux to Recoil, modifying state management and rendering logic.
app/scenes/ExampleScreen/recoilState.js Introduced Recoil state management with defined atoms and selectors for user data.
app/scenes/RootScreen/index.js Transitioned to Recoil, removing Redux dependencies and props.
app/services/userService.js Refactored getUser function to be asynchronous, improving error handling.
app/utils/apiUtils.js Replaced apisauce with axios for API client creation and management.
package.json Updated scripts and dependencies, including downgrading apisauce and upgrading expo-crypto.
ios/reactnativetemplatews.xcodeproj/project.pbxproj Modified build phases in Xcode project configuration.
app/utils/testUtils.js Replaced Redux Provider with RecoilRoot for testing utilities.
.github/workflows/build.yml Updated branch specifications and changed linting command from npm to yarn.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Recoil
    participant API

    App->>Recoil: Initialize state
    Recoil->>API: Fetch user data
    API-->>Recoil: Return user data
    Recoil-->>App: Update state
    App->>App: Render UI with user data
Loading

🐰 In the meadow, I hop with glee,
New changes sprout like leaves on a tree!
From Redux to Recoil, a leap so bright,
Testing and coding feel just right!
With every update, my heart takes flight,
Hooray for the changes, what a delight! 🌼✨


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

@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: 2

Outside diff range, codebase verification and nitpick comments (2)
app/services/tests/userService.test.js (1)

2-2: Incomplete Transition from getApiClient to generateApiClient.

The transition from getApiClient to generateApiClient is incomplete. While the test file app/services/tests/userService.test.js correctly uses generateApiClient, the getApiClient function is still present and used in other parts of the codebase, such as app/utils/apiUtils.js and app/services/userService.js. Further updates are needed to ensure consistency across the codebase.

  • app/utils/apiUtils.js: getApiClient is still defined.
  • app/services/userService.js: getApiClient is still used.
Analysis chain

Verify the usage of generateApiClient in the codebase.

Ensure that all usages of getApiClient have been replaced with generateApiClient and the function is being used correctly.

Run the following script to verify the usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `getApiClient` have been replaced with `generateApiClient`.

# Test 1: Search for usages of `getApiClient`. Expect: No occurrences.
rg --type js $'getApiClient'

# Test 2: Search for usages of `generateApiClient`. Expect: Only correct usages.
rg --type js -A 5 $'generateApiClient'

Length of output: 1840

package.json (1)

8-8: Jest configuration file is missing in the project root.

The jest.config.js file is not present in the project root directory. Please verify if the configuration file is located elsewhere or ensure that using Jest's default configuration is intentional and suitable for the project.

  • Consider checking other directories for the jest.config.js file.
  • Ensure that the project does not rely on specific Jest configurations that are missing.
Analysis chain

Verify the presence of the Jest configuration file.

The --config=jest.config.js option has been removed from the test script, assuming that the jest.config.js file is present in the project root directory.

Run the following script to verify the presence of the jest.config.js file:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of the Jest configuration file.

# Test: Check if the `jest.config.js` file exists in the project root. Expect: The file to be present.
if [ -f "jest.config.js" ]; then
  echo "The jest.config.js file exists in the project root."
else
  echo "The jest.config.js file does not exist in the project root."
fi

Length of output: 156

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9c4aa4d and 5d92faa.

Files ignored due to path filters (11)
  • app/assets/images/wednesday-logo-old.png is excluded by !**/*.png
  • app/assets/images/wednesday-logo.png is excluded by !**/*.png
  • app/assets/images/wednesday-logo.svg is excluded by !**/*.svg
  • app/components/atoms/Container/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/components/molecules/CharacterWithQuote/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/components/molecules/LogoWithInstructions/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/components/organisms/SimpsonsLoveWednesday/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/scenes/RootScreen/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/scenes/SplashScreen/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • ios/Podfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (22)
  • .eslintignore (1 hunks)
  • .eslintrc.js (2 hunks)
  • app/app.js (1 hunks)
  • app/components/atoms/LanguageProvider/tests/index.test.js (1 hunks)
  • app/i18n.js (2 hunks)
  • app/i18n.test.js (3 hunks)
  • app/navigators/appNavigator.js (1 hunks)
  • app/scenes/ExampleScreen/index.js (2 hunks)
  • app/scenes/ExampleScreen/recoilState.js (1 hunks)
  • app/scenes/ExampleScreen/tests/index.test.js (1 hunks)
  • app/scenes/ExampleScreen/tests/recoilState.test.js (1 hunks)
  • app/scenes/RootScreen/index.js (1 hunks)
  • app/scenes/RootScreen/recoilState.js (1 hunks)
  • app/scenes/RootScreen/tests/index.test.js (1 hunks)
  • app/services/tests/userService.test.js (2 hunks)
  • app/services/userService.js (1 hunks)
  • app/utils/apiUtils.js (1 hunks)
  • app/utils/errors.js (1 hunks)
  • app/utils/testUtils.js (1 hunks)
  • ios/reactnativetemplatews.xcodeproj/project.pbxproj (4 hunks)
  • package.json (5 hunks)
  • web-build/register-service-worker.js (1 hunks)
Files skipped from review due to trivial changes (4)
  • app/components/atoms/LanguageProvider/tests/index.test.js
  • app/scenes/RootScreen/recoilState.js
  • app/utils/errors.js
  • web-build/register-service-worker.js
Additional comments not posted (62)
.eslintignore (3)

6-6: LGTM!

The change to exclude the web-build directory from linting is appropriate.


16-16: LGTM!

The change to exclude the webpack.config.js file from linting is appropriate.


14-14: Verify the exclusion of growthbook.js from linting.

Please provide more context on what the growthbook.js file contains and why it needs to be excluded from linting.

Run the following script to verify the contents of the file:

app/app.js (2)

7-7: LGTM!

The code changes are approved.


10-16: LGTM!

The code changes are approved.

app/services/userService.js (4)

4-14: LGTM! The refactor improves the API client initialization process.

The introduction of the createApiClient and getApiClient functions enhances the control flow and error handling for the API client initialization process.

  • The use of asynchronous functions allows for better management of the asynchronous nature of the API client generation.
  • The getApiClient function ensures that the API client is initialized only once, preventing unnecessary re-initializations.
  • The error handling in the getApiClient function catches and propagates any errors that may occur during the initialization process.
  • The use of lodash's set function provides a more robust way to assign the client instance.

Overall, these changes improve the reliability and maintainability of the API client initialization process.


15-15: LGTM!

The client object declaration with the apiClient property initialized to null is appropriate for storing the API client instance and allowing the getApiClient function to check the initialization status.


16-23: LGTM! The refactor improves the getUser function.

The refactor of the getUser function to be an asynchronous function is a significant improvement:

  • Making the function asynchronous aligns with the asynchronous nature of making API requests, allowing for better handling of the request lifecycle.
  • Using the getApiClient function ensures that the API client is properly initialized before making the request, preventing potential issues related to uninitialized clients.
  • The error handling in the function catches and propagates any errors that may occur during the API request, enhancing the reliability and error management of the function.

Overall, these changes make the getUser function more robust, maintainable, and aligned with best practices for handling asynchronous operations.


2-3: LGTM!

The import of the set function from the lodash library is necessary for its usage in the getApiClient function to assign the API client instance to the client.apiClient property.

app/scenes/RootScreen/index.js (5)

1-3: LGTM!

The import statements are consistent with the transition from Redux to Recoil for state management.


8-23: LGTM!

The RootScreen component has been correctly refactored to use Recoil for state management. The side effect is correctly implemented and handles the navigation based on the app state. The AppNavigator component is correctly rendered without the need for setTopLevelNavigator.


25-25: LGTM!

The export statement is consistent with the removal of Redux from the component.


26-26: LGTM!

The test export statement is correctly implemented and allows the component to be imported in test files.


1-26: LGTM!

The file has been thoroughly reviewed and all the code changes are consistent with the transition from Redux to Recoil for state management. There are no additional comments or concerns.

app/utils/testUtils.js (4)

4-5: LGTM!

The code changes are approved.


13-16: LGTM!

The code changes are approved.


19-24: LGTM!

The code changes are approved.


8-11: Also applies to: 26-26

app/i18n.js (1)

Line range hint 16-22: Verify if the hardcoded 'en' language is intended.

The languageDetector object always returns 'en' as the detected language. This may be intentional if the application only supports English. However, if you need to support multiple languages, consider implementing actual language detection logic.

Here's a script to verify if the hardcoded 'en' language is used consistently throughout the codebase:

If you need to implement actual language detection, you can use libraries like i18next-browser-languagedetector or write custom logic based on the user's browser language or stored preferences.

Verification successful

Hardcoded 'en' Language is Consistent and Intentional

The hardcoded 'en' language in the languageDetector object is used consistently throughout the codebase, particularly in the i18n setup. This suggests that the application is currently configured to support only English, and the implementation aligns with this configuration. If you plan to support additional languages in the future, consider implementing dynamic language detection logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the hardcoded 'en' language is used consistently.

# Test: Search for usage of other language codes. Expect: No occurrences.
rg --type js $'[\'"](?!en)[a-z]{2}[\'"]\s*:'

# Test: Search for 'en' language usage. Expect: Occurrences only in i18n setup.
rg --type js --stats $'[\'"]en[\'"]\s*:'

Length of output: 487


Script:

#!/bin/bash
# Description: Verify if the hardcoded 'en' language is used consistently.

# Test: Search for usage of language codes other than 'en'. Expect: No occurrences.
rg --type js --pcre2 '\b(?!en\b)[a-z]{2}\b'

# Test: Search for 'en' language usage. Expect: Occurrences only in i18n setup.
rg --type js --pcre2 '\ben\b'

Length of output: 19286

app/navigators/appNavigator.js (1)

16-19: LGTM!

The changes to the Stack.Navigator component configuration are approved:

  • The addition of the screenOptions prop to hide the header for all screens is a valid UI enhancement that provides a cleaner navigation experience.
  • The initialRouteName prop remains correctly set to "SplashScreen" to ensure the navigation flow starts from the same screen as before.
app/services/tests/userService.test.js (1)

5-20: LGTM!

The jest.mock implementation looks good. It simplifies the test by directly mocking the API response, which improves maintainability and reduces complexity.

app/scenes/ExampleScreen/recoilState.js (4)

1-3: LGTM!

The imports are correctly defined and follow the application's import conventions.


5-27: LGTM!

The Recoil atoms are correctly defined with unique keys and appropriate default values.


1-43: LGTM!

The code is consistent with the rest of the codebase and follows the established conventions for defining Recoil atoms and selectors, using the application's utility functions and error messages.


1-43: LGTM!

The code is well-structured, modular, and reusable, following best practices for defining Recoil atoms and selectors. Each atom and selector has a specific purpose, making the code maintainable and easy to understand.

app/i18n.test.js (2)

3-3: LGTM!

The code changes are approved.


27-27: LGTM!

Setting debug to false is appropriate for a production-ready configuration.

app/utils/apiUtils.js (5)

3-9: LGTM!

The code changes are approved.


16-17: LGTM!

The code changes are approved.


22-26: LGTM!

The code changes are approved.


32-79: LGTM!

The code changes are approved.


Line range hint 1-81: LGTM!

The code changes in the entire file are approved.

app/scenes/RootScreen/tests/index.test.js (5)

15-19: LGTM!

The test case is correctly implemented and ensures that the component renders without errors and matches the expected snapshot.


21-30: LGTM!

The test case is correctly implemented and ensures that the expected components are rendered within the RootScreen.


32-42: LGTM!

The test case is correctly implemented and ensures that navigateAndReset is called with the correct argument when the app state is falsy.


44-51: LGTM!

The test case is correctly implemented and ensures that navigateAndReset is not called when the app state is truthy.


53-72: LGTM!

The test case is correctly implemented and ensures that the component handles changes to the app state correctly by calling or not calling navigateAndReset based on the truthiness of the app state.

app/scenes/ExampleScreen/index.js (5)

1-7: LGTM!

The code changes are approved.


13-15: LGTM!

The code changes are approved.


38-55: LGTM!

The code changes are approved. The refactor enhances the component's clarity and reduces its dependency on Redux.


59-79: LGTM!

The code changes are approved. The updated rendering logic simplifies the display of loading indicators and user data.


84-84: LGTM!

The code changes are approved. The updated export streamlines the code.

app/scenes/ExampleScreen/tests/index.test.js (5)

2-9: LGTM!

The imports are correctly set up for testing with Recoil.


11-16: LGTM!

Mocking the Recoil hooks is a good practice for controlling their behavior during tests.


23-29: LGTM!

Setting up the mock implementations in the beforeEach block is a good practice to ensure a clean state for each test case.


31-33: LGTM!

Clearing the mocks in the afterEach block is a good practice to prevent any state leakage between test cases.


35-105: LGTM!

The test cases comprehensively cover the component's behavior and interaction with Recoil state management. The use of mocked Recoil hooks allows for accurate simulation of different states during tests. The test cases are well-structured and cover various scenarios such as loading state, successful data fetching, error handling, and user interactions.

.eslintrc.js (2)

149-149: Provide rationale for disabling the 'fp/no-throw' rule.

Disabling the 'fp/no-throw' rule is a significant change that deviates from functional programming best practices. Can you please provide more information about the motivation behind this change and its potential impact on the codebase?

Some questions to consider:

  • What are the specific scenarios where throwing exceptions is necessary?
  • How will this change affect the overall error handling strategy in the codebase?
  • Are there alternative approaches that align better with functional programming principles?

Answering these questions will help in understanding the implications of this change and determining the best path forward.


122-122: Complexity rule threshold increased. Ensure code remains maintainable.

Increasing the complexity rule threshold from 2 to 4 is reasonable for a large codebase. However, it's important to ensure the code remains maintainable and readable.

To ensure the increased complexity threshold doesn't lead to unmaintainable code, run the following script to identify functions with a complexity greater than 3:

Verification successful

Complexity threshold increase verified successfully.

The increase in the complexity threshold to 4 does not currently lead to any functions exceeding this limit. The codebase remains maintainable with the current complexity levels.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Identify functions with a complexity greater than 3.

# Test: Search for functions with a complexity greater than 3. Expect: No results.
ast-grep --lang javascript --pattern $'function $_($$$) {
  $$$
}' | awk 'BEGIN{count=0} /^function/ {count++} /^}/ {if (count > 3) print; count=0}'

Length of output: 149


Script:

#!/bin/bash
# Description: Identify functions with a complexity greater than 3 by counting decision points.

# Test: Search for functions with a complexity greater than 3. Expect: No results.
ast-grep --lang javascript --pattern $'function $_($$$) {
  $$$
}' --json | jq -r '.captures[].text' | while read -r function; do
  complexity=$(echo "$function" | grep -oE 'if|for|while|switch|case|catch' | wc -l)
  if [ "$complexity" -gt 3 ]; then
    echo "Function with complexity $complexity: $function"
  fi
done

Length of output: 190


Script:

#!/bin/bash
# Description: Output the raw JSON from ast-grep to understand its structure.

# Test: Output the raw JSON from ast-grep. Expect: JSON structure.
ast-grep --lang javascript --pattern $'function $_($$$) {
  $$$
}' --json

Length of output: 9873


Script:

#!/bin/bash
# Description: Identify functions with a complexity greater than 3 by counting decision points.

# Test: Search for functions with a complexity greater than 3. Expect: No results.
ast-grep --lang javascript --pattern $'function $_($$$) {
  $$$
}' --json | jq -c '.[]' | while read -r function; do
  text=$(echo "$function" | jq -r '.text')
  complexity=$(echo "$text" | grep -oE 'if|for|while|switch|case|catch' | wc -l)
  if [ "$complexity" -gt 3 ]; then
    echo "Function with complexity $complexity: $text"
  fi
done

Length of output: 15776

app/scenes/ExampleScreen/tests/recoilState.test.js (5)

41-65: LGTM!

The test suite for the userState atom is approved.


67-91: LGTM!

The test suite for the userIsLoadingState atom is approved.


93-117: LGTM!

The test suite for the userErrorMessageState atom is approved.


119-143: LGTM!

The test suite for the fetchTriggerState atom is approved.


145-181: LGTM!

The test suite for the fetchUserSelector selector is approved.

package.json (5)

11-11: LGTM!

The change to use a dedicated .eslintignore file for specifying the files and directories to be ignored by ESLint is a good practice. It promotes better separation of concerns and maintainability of the linting configuration.


49-49: Clarify the reason for downgrading the apisauce dependency.

The version of the apisauce dependency has been downgraded from ^3.0.1 to ^2.1.6. While downgrading dependencies can be necessary to ensure compatibility or address issues, it's important to consider the potential drawbacks, such as missing out on newer features, bug fixes, and performance improvements.

Please provide the rationale behind the downgrade and ensure that it does not introduce any compatibility issues or vulnerabilities.


61-61: LGTM, but verify compatibility.

Upgrading the expo-crypto dependency to version ^13.0.2 is a good practice to leverage the latest features, bug fixes, and performance improvements.

Please ensure that the upgraded version is compatible with the rest of the project dependencies and does not introduce any breaking changes.


72-72: LGTM, but verify usage.

The addition of the nanoid dependency with version 3.3.5 is approved.

Please ensure that the nanoid library is being used appropriately in the project and that it aligns with the project's requirements for generating unique identifiers.


94-94: Clarify the reason for changing the version specifier of styled-components.

The version of the styled-components dependency has been changed from ^6.1.8 to ~5.3.0, indicating a preference for stability and avoiding potential breaking changes in newer minor versions.

Please provide the rationale behind this change and ensure that using an older version of styled-components does not introduce any issues or limitations in the project.

ios/reactnativetemplatews.xcodeproj/project.pbxproj (3)

147-147: Approved: Enhanced build phase configuration and Expo integration.

The changes to the [Expo] Configure project build phase are beneficial for the following reasons:

  1. The addition of properties like alwaysOutOfDate, inputFileListPaths, and outputFileListPaths allows for more granular control over the build process, such as specifying input and output file lists.

  2. The updated shell script ensures that Expo modules are properly configured during the build process, improving the reliability and functionality of the Expo integration.

These enhancements streamline the build process and provide better integration with Expo modules.

Also applies to: 289-307


247-260: Approved: Integration with Sentry for enhanced debugging capabilities.

The addition of the Upload Debug Symbols to Sentry build phase is a valuable enhancement to the project's debugging capabilities. By uploading debug symbols to Sentry, the following benefits are achieved:

  1. Better symbolication of crash reports: With the debug symbols available, Sentry can provide more accurate and meaningful stack traces for crash reports, making it easier to identify and diagnose issues.

  2. Improved debugging experience: The integration with Sentry allows for centralized error tracking and monitoring, enabling developers to proactively identify and resolve bugs and crashes.

This integration strengthens the project's ability to detect and fix issues efficiently, leading to a more stable and reliable application.


308-324: Approved: Improved framework embedding process.

The changes to the [CP] Embed Pods Frameworks build phase are beneficial for the following reasons:

  1. The inclusion of specific input and output paths ensures that the necessary frameworks, such as the Hermes engine framework, are properly embedded in the application bundle.

  2. The modifications indicate a more comprehensive handling of framework embedding during the build process, reducing the chances of missing or incorrectly embedded frameworks.

These improvements contribute to a more reliable and efficient build process, ensuring that the required frameworks are correctly included in the application.

Comment on lines 29 to 43
// Selector to fetch user data
export const fetchUserSelector = selector({
key: 'fetchUserSelector',
get: async ({ get }) => {
get(fetchTriggerState); // Read the trigger state to force re-fetch

const response = await getUser();

if (!response.ok) {
throw new Error(Errors.USER_FETCH_ERROR);
}
const { data } = response;
return data[0];
}
});
Copy link

Choose a reason for hiding this comment

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

Consider adding error handling and data validation for the fetchUserSelector.

The fetchUserSelector assumes that the user data is always present in the first item of the data array, which might not always be the case. Consider adding error handling and data validation to handle scenarios where the data array is empty or the expected data structure is not returned.

Here's an example of how you can improve the error handling and data validation:

export const fetchUserSelector = selector({
  key: 'fetchUserSelector',
  get: async ({ get }) => {
    get(fetchTriggerState); // Read the trigger state to force re-fetch

    const response = await getUser();

    if (!response.ok) {
      throw new Error(Errors.USER_FETCH_ERROR);
    }
    const { data } = response;
+   if (!Array.isArray(data) || data.length === 0) {
+     throw new Error(Errors.USER_DATA_INVALID);
+   }
-   return data[0];
+   return data[0] || null;
  }
});

This way, the selector will throw an error if the data is not an array or if it's empty. It will also return null if the first item of the data array is not present, instead of potentially returning undefined.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Selector to fetch user data
export const fetchUserSelector = selector({
key: 'fetchUserSelector',
get: async ({ get }) => {
get(fetchTriggerState); // Read the trigger state to force re-fetch
const response = await getUser();
if (!response.ok) {
throw new Error(Errors.USER_FETCH_ERROR);
}
const { data } = response;
return data[0];
}
});
// Selector to fetch user data
export const fetchUserSelector = selector({
key: 'fetchUserSelector',
get: async ({ get }) => {
get(fetchTriggerState); // Read the trigger state to force re-fetch
const response = await getUser();
if (!response.ok) {
throw new Error(Errors.USER_FETCH_ERROR);
}
const { data } = response;
if (!Array.isArray(data) || data.length === 0) {
throw new Error(Errors.USER_DATA_INVALID);
}
return data[0] || null;
}
});

@@ -145,7 +145,8 @@ module.exports = {
}
],
'fp/no-nil': 0,
'fp/no-unused-expression': 0
'fp/no-unused-expression': 0,
Copy link

Choose a reason for hiding this comment

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

Avoid disabling the 'fp/no-unused-expression' rule.

Disabling the 'fp/no-unused-expression' rule is not recommended as it can lead to unintended side effects and make the code harder to reason about. Please consider enabling this rule to enforce better functional programming practices.

Apply this diff to enable the rule:

-    'fp/no-unused-expression': 0,
+    'fp/no-unused-expression': 'error',
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'fp/no-unused-expression': 0,
'fp/no-unused-expression': 'error',

Copy link

github-actions bot commented Sep 4, 2024

Coverage report

Statements coverage not met for global: expected >=80%, but got 79.64071856287424%

St.
Category Percentage Covered / Total
🟡 Statements
79.64% (-6.01% 🔻)
133/167
🔴 Branches
47.83% (-25.34% 🔻)
11/23
🟡 Functions
67.86% (-11.21% 🔻)
38/56
🟢 Lines
80.95% (-4.55% 🔻)
119/147
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢 utils/errors.js 100% 100% 100% 100%
🟢
... / recoilState.js
100% 100% 100% 100%
🟢
... / logo.png
100% 100% 100% 100%
🟢
... / wednesday-logo-new.png
100% 100% 100% 100%
🟢 utils/constants.js 100% 100% 100% 100%
🟢
... / recoilState.js
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴 utils/apiUtils.js
13.79% (-69.54% 🔻)
0% (-60% 🔻)
0% (-85.71% 🔻)
14.81% (-67.79% 🔻)
🟢
... / userService.js
85.71% (-14.29% 🔻)
50% (-50% 🔻)
100%
84.62% (-15.38% 🔻)
🟢 utils/common.js
80% (-20% 🔻)
75% (-25% 🔻)
100%
80% (-20% 🔻)
🟢 utils/testUtils.js
55.56% (-44.44% 🔻)
100%
20% (-80% 🔻)
83.33% (-16.67% 🔻)
🟢 i18n.js
100% (+6.25% 🔼)
100% (+50% 🔼)
33.33% (-6.67% 🔻)
100% (+6.25% 🔼)

Test suite run success

47 tests passing in 17 suites.

Report generated by 🧪jest coverage report action from 732b82a

Copy link

@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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5d92faa and e776e91.

Files selected for processing (1)
  • .github/workflows/build.yml (2 hunks)
Additional comments not posted (3)
.github/workflows/build.yml (3)

4-4: LGTM!

The code changes are approved.


6-6: LGTM!

The code changes are approved.


16-16: LGTM!

The code changes are approved.

app/app.js Outdated
import 'react-native-gesture-handler';
const { store, persistor } = createStore();
import { RecoilRoot } from 'recoil';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the import order here

import { render } from '@testing-library/react-native';
import T from '@atoms/T';
import { renderWithI18next } from '@utils/testUtils';
import { Text } from 'react-native';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the import order here

import T from '@atoms/T';
import { renderWithI18next } from '@utils/testUtils';
import { Text } from 'react-native';
import ConnectedLanguageProvider, { LanguageProvider } from '../index';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please check this

@@ -38,56 +28,58 @@ const CustomButtonParentView = styled(View)`
max-width: 80px;
align-self: center;
`;

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\nCmd+D or shake for dev menu.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please update the text to come from translations

useEffect(() => {
requestFetchUser();
}, []);

useEffect(() => {
if (userLoadable.state === 'hasValue') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please take hasValue from constants

user={user}
/>
<CustomButtonParentView>
<Button onPress={requestFetchUser} title="Refresh" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please fetch refresh from translations

</CustomButtonParentView>
</View>
}
>
<ActivityIndicator testID="loader" size="large" color="#0000ff" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please not take the color directly


// Atom to manage loading state
export const userIsLoadingState = atom({
key: 'userIsLoadingState',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please create an object with all the possible keys first and then use it


const response = await getUser();

if (!response.ok) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please create a util function to handle this so it is resusebale

const { submitSpy } = setupJest();
const baseElement = renderProvider(
<ExampleScreenTest fetchUser={submitSpy} />
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please fix the import order here


jest.mock('@app/services/userService');

describe('Recoil Atoms and Selector', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please update the test name here

// Run the startup function when the component mounts
props.startup();
}, []);
// Simulate startup effect
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please update the comment here

jest.mock('recoil');
jest.mock('@app/services/navigationService');

describe('<RootScreen />', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please update the name here

export const getUser = async () => {
try {
const apiClient = await getApiClient();
return apiClient.get('quotes?count=1');
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please create an object with all the api endpoints we call

import i18n from '@app/utils/i18nextTestUtils'; // assuming i18n is configured in this file
import ConnectedLanguageProvider from '@atoms/LanguageProvider';
import i18n from '@app/utils/i18nextTestUtils';
import { RecoilRoot } from 'recoil';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please fix the import order here

Copy link

@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

Outside diff range, codebase verification and nitpick comments (1)
app/utils/apiUtils.js (1)

77-79: Improve the error handling.

Consider providing more context about the error, such as the operation that failed and any relevant details. This will help with debugging and troubleshooting.

Here's a suggestion:

-  } catch (err) {
-    throw new Error(err);
-  }
+  } catch (error) {
+    console.error('Error creating API client:', error);
+    throw new Error(`Failed to create API client: ${error.message}`);
+  }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e776e91 and d0f982c.

Files ignored due to path filters (2)
  • app/assets/images/wednesday-logo-new.png is excluded by !**/*.png
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (11)
  • app/app.js (1 hunks)
  • app/scenes/ExampleScreen/index.js (2 hunks)
  • app/scenes/ExampleScreen/tests/index.test.js (1 hunks)
  • app/scenes/ExampleScreen/tests/recoilState.test.js (1 hunks)
  • app/scenes/RootScreen/index.js (1 hunks)
  • app/scenes/RootScreen/tests/index.test.js (1 hunks)
  • app/services/userService.js (1 hunks)
  • app/themes/images.js (1 hunks)
  • app/utils/apiUtils.js (1 hunks)
  • app/utils/testUtils.js (1 hunks)
  • package.json (4 hunks)
Files skipped from review due to trivial changes (1)
  • app/themes/images.js
Files skipped from review as they are similar to previous changes (3)
  • app/scenes/ExampleScreen/tests/recoilState.test.js
  • app/scenes/RootScreen/tests/index.test.js
  • package.json
Additional comments not posted (26)
app/app.js (2)

1-8: Fix the import order.

The comment from the previous review about fixing the import order is still applicable. Please follow the recommended import order:

  1. React and other external libraries
  2. Recoil and other state management libraries
  3. Custom components and modules

2-2: LGTM: Transition from Redux to Recoil.

The code changes related to the transition from Redux to Recoil look good. The RecoilRoot component is correctly used to wrap the application, replacing the previous Redux setup.

Also applies to: 10-16

app/services/userService.js (5)

19-19: The existing comment is still valid.

The suggestion to create an object with all the API endpoints has not been addressed in the current changes.


4-4: LGTM!

The code changes are approved.


5-14: LGTM!

The code changes are approved.


15-15: LGTM!

The code changes are approved.


16-23: LGTM!

The code changes are approved.

app/scenes/RootScreen/index.js (5)

Line range hint 1-28:
The existing comment from the previous review is not relevant to the current code changes as it does not specify which comment needs to be updated and the code changes do not show any comments being added or modified.


1-7: LGTM!

The code changes are approved. The import statements have been correctly updated to transition from Redux to Recoil for state management.


8-16: LGTM!

The code changes are approved. The RootScreen component has been correctly modified to use Recoil instead of Redux for state management. The side effect introduced using useEffect is a good way to handle the startup logic based on the app state.


20-20: LGTM!

The code change is approved. The AppNavigator component is correctly rendered without the unnecessary reference to setTopLevelNavigator.


25-26: LGTM!

The code changes are approved. The export statement has been correctly updated to directly export RootScreen, removing the unnecessary connection to Redux. Exporting the component as RootScreenTest is useful for testing purposes.

app/utils/testUtils.js (3)

1-5: Skip the previous comment about fixing the import order.

The import order in the current code seems to be correct.


13-16: LGTM!

The code changes are approved.


19-24: LGTM!

The code changes are approved.

app/utils/apiUtils.js (4)

3-10: LGTM!

The changes to the import statements are approved. They are consistent with the refactoring to use axios and lodash utilities.


16-17: LGTM!

The changes to the getApiClient function are approved. They improve the retrieval of the API client by using the get function from lodash, which allows for a more concise implementation and provides a default value.


22-26: LGTM!

The changes to the generateApiClient function are approved. They streamline the assignment process and improve code readability by using the set function from lodash.


32-79: LGTM!

The changes to the createApiClientWithTransForm function are approved. They enhance the functionality and maintainability of the API client by leveraging axios's features, which provide a more robust and flexible approach to handling API requests and responses.

app/scenes/ExampleScreen/index.js (1)

38-38: LGTM!

The changes to the component declaration are approved as they align with the refactor to use Recoil for state management.

app/scenes/ExampleScreen/tests/index.test.js (6)

2-2: Skip the existing comment as the import order has been fixed.

The existing comment on line 2 requesting to fix the import order can be skipped as it has been addressed in the current diff.


2-7: LGTM!

The code changes are approved.


11-16: LGTM!

The code changes are approved.


23-29: LGTM!

The code changes are approved.


31-33: LGTM!

The code changes are approved.


35-103: LGTM!

The code changes are approved. The tests are comprehensive and cover the important scenarios. The use of Recoil hooks enhances the testing logic and ensures that the component is tested in isolation.

Copy link

@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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0f982c and a11c80d.

Files selected for processing (4)
  • app/scenes/ExampleScreen/index.js (2 hunks)
  • app/scenes/RootScreen/index.js (1 hunks)
  • app/translations/en.json (1 hunks)
  • app/utils/constants.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/utils/constants.js
Additional comments not posted (16)
app/translations/en.json (1)

8-8: LGTM!

The new translation entry for "refresh" is correctly added.

app/scenes/RootScreen/index.js (5)

1-7: LGTM!

The code changes are approved.


8-16: LGTM!

The code changes are approved.


20-20: LGTM!

The code change is approved.


25-25: LGTM!

The code change is approved.


26-26: Verify the purpose of the additional export.

The RootScreen component is also exported as RootScreenTest. Is this export intended for testing purposes?

app/scenes/ExampleScreen/index.js (10)

1-9: LGTM!

The import statements have been updated to reflect the transition from Redux to Recoil for state management.


13-15: LGTM!

The imports support the updated rendering logic and state management.


17-17: LGTM!

The import statement supports the transition to Recoil for state management.


40-43: LGTM!

The component has been refactored to use Recoil for state management instead of relying on props.


46-46: LGTM!

The requestFetchUser function has been updated to align with the transition to Recoil for state management.


53-57: LGTM!

The useEffect hook ensures that the user state stays in sync with the userLoadable state.


61-81: LGTM!

The rendering logic has been simplified and streamlined by using the conditional rendering component and directly accessing the Recoil state.


86-86: LGTM!

The export statement has been updated to reflect the removal of Redux from the component.


35-35: Skipped

The past comment is no longer applicable as the text has been removed in the current changes.


80-80: Skipped

The past comment is no longer applicable as the color prop has been removed in the current changes.

Copy link

@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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a11c80d and a49059b.

Files selected for processing (4)
  • .eslintrc.js (4 hunks)
  • app/scenes/ExampleScreen/recoilState.js (1 hunks)
  • app/scenes/RootScreen/recoilState.js (1 hunks)
  • app/utils/common.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/scenes/RootScreen/recoilState.js
Files skipped from review as they are similar to previous changes (2)
  • .eslintrc.js
  • app/scenes/ExampleScreen/recoilState.js

Comment on lines +4 to +8
export const errorHandlerFunction = (response, error) => {
if (!response.ok) {
throw new Error(error);
}
};
Copy link

Choose a reason for hiding this comment

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

Simplify the function by directly throwing the error.

The function can be simplified by directly throwing the error instead of using an if condition.

Apply this diff to simplify the function:

-export const errorHandlerFunction = (response, error) => {
-  if (!response.ok) {
-    throw new Error(error);
-  }
-};
+export const errorHandlerFunction = (response, error) =>
+  response.ok ? undefined : new Error(error);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const errorHandlerFunction = (response, error) => {
if (!response.ok) {
throw new Error(error);
}
};
export const errorHandlerFunction = (response, error) =>
response.ok ? undefined : new Error(error);

@shamoilattaar-wednesday shamoilattaar-wednesday merged commit 05d2991 into dev Sep 5, 2024
2 of 3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 9, 2024
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