-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conversation
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 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. WalkthroughThe 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 Changes
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 fromgetApiClient
togenerateApiClient
.The transition from
getApiClient
togenerateApiClient
is incomplete. While the test fileapp/services/tests/userService.test.js
correctly usesgenerateApiClient
, thegetApiClient
function is still present and used in other parts of the codebase, such asapp/utils/apiUtils.js
andapp/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 withgenerateApiClient
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 thetest
script, assuming that thejest.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." fiLength of output: 156
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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 ofgrowthbook.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
andgetApiClient
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
'sset
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 theapiClient
property initialized tonull
is appropriate for storing the API client instance and allowing thegetApiClient
function to check the initialization status.
16-23
: LGTM! The refactor improves thegetUser
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 thelodash
library is necessary for its usage in thegetApiClient
function to assign the API client instance to theclient.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 theapp
state. TheAppNavigator
component is correctly rendered without the need forsetTopLevelNavigator
.
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-26app/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
tofalse
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 doneLength 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 $_($$$) { $$$ }' --jsonLength 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 doneLength 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 theapisauce
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 version3.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 ofstyled-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:
The addition of properties like
alwaysOutOfDate
,inputFileListPaths
, andoutputFileListPaths
allows for more granular control over the build process, such as specifying input and output file lists.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:
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.
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:
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.
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.
// 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]; | ||
} | ||
}); |
There was a problem hiding this comment.
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.
// 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, |
There was a problem hiding this comment.
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.
'fp/no-unused-expression': 0, | |
'fp/no-unused-expression': 'error', |
Coverage reportStatements coverage not met for global: expected >=80%, but got 79.64071856287424%
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success47 tests passing in 17 suites. Report generated by 🧪jest coverage report action from 732b82a |
There was a problem hiding this 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
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.', |
There was a problem hiding this comment.
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
app/scenes/ExampleScreen/index.js
Outdated
useEffect(() => { | ||
requestFetchUser(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (userLoadable.state === 'hasValue') { |
There was a problem hiding this comment.
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
app/scenes/ExampleScreen/index.js
Outdated
user={user} | ||
/> | ||
<CustomButtonParentView> | ||
<Button onPress={requestFetchUser} title="Refresh" /> |
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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
app/scenes/RootScreen/index.js
Outdated
// Run the startup function when the component mounts | ||
props.startup(); | ||
}, []); | ||
// Simulate startup effect |
There was a problem hiding this comment.
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 />', () => { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
app/utils/testUtils.js
Outdated
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'; |
There was a problem hiding this comment.
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
There was a problem hiding this 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
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:
- React and other external libraries
- Recoil and other state management libraries
- 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 usinguseEffect
is a good way to handle the startup logic based on theapp
state.
20-20
: LGTM!The code change is approved. The
AppNavigator
component is correctly rendered without the unnecessary reference tosetTopLevelNavigator
.
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 asRootScreenTest
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
andlodash
utilities.
16-17
: LGTM!The changes to the
getApiClient
function are approved. They improve the retrieval of the API client by using theget
function fromlodash
, 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 theset
function fromlodash
.
32-79
: LGTM!The changes to the
createApiClientWithTransForm
function are approved. They enhance the functionality and maintainability of the API client by leveragingaxios
'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.
There was a problem hiding this 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
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 asRootScreenTest
. 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 theuser
state stays in sync with theuserLoadable
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
: SkippedThe past comment is no longer applicable as the text has been removed in the current changes.
80-80
: SkippedThe past comment is no longer applicable as the color prop has been removed in the current changes.
There was a problem hiding this 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
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
export const errorHandlerFunction = (response, error) => { | ||
if (!response.ok) { | ||
throw new Error(error); | ||
} | ||
}; |
There was a problem hiding this comment.
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.
export const errorHandlerFunction = (response, error) => { | |
if (!response.ok) { | |
throw new Error(error); | |
} | |
}; | |
export const errorHandlerFunction = (response, error) => | |
response.ok ? undefined : new Error(error); |
Ticket Link
Related Links
Description
Steps to Reproduce / Test
GIF's
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores
Tests