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

fix(native-app): use correct locale in applications query #16115

Merged
merged 6 commits into from
Sep 23, 2024

Conversation

thoreyjona
Copy link
Contributor

@thoreyjona thoreyjona commented Sep 23, 2024

Accidentally was checking if locale === 'is-US' instead of 'is-IS' 😅 .

Also added some edge case fixes, if you have an application that is incomplete and you have completed 0 out of x steps in it, we show the progress bar for that.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Improved locale handling for the Applications Screen, enhancing the user experience based on regional settings.
    • Introduced a new styled component, Wrapper, to enhance the visual structure of loading and empty state components.
  • Refactor

    • Simplified the locale determination logic for better readability and maintainability.
    • Updated progress meter display logic in the Status Card for clearer representation based on progress data.

@thoreyjona thoreyjona requested a review from a team as a code owner September 23, 2024 13:06
Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes involve a refactor of the locale handling in the ApplicationsScreen component, simplifying the logic by introducing a single variable, queryLocale, for determining the query locale based on the user's locale. Additionally, a new styled component named Wrapper is added in applications-module.tsx to enhance the layout structure of loading and empty state components. Other modifications include adjustments to the ApplicationsPreview and StatusCard components to improve their rendering logic.

Changes

File Change Summary
apps/native/app/src/screens/applications/applications.tsx Refactored locale handling logic to use a single queryLocale variable for determining the query locale.
apps/native/app/src/screens/home/applications-module.tsx Introduced a new styled component Wrapper to encapsulate StatusCardSkeleton and EmptyCard, enhancing layout structure.
apps/native/app/src/screens/applications/components/applications-preview.tsx Modified condition for progressContainerWidth to depend on both slider and count values.
apps/native/app/src/ui/lib/card/status-card.tsx Introduced hideProgress variable to control the display of the ProgressMeter, simplifying the rendering logic.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • eirikurn
  • snaerseljan

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>, please review it.
    -- 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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.

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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
apps/native/app/src/screens/applications/applications.tsx (1)

107-110: LGTM! Consider adding a comment for clarity.

The changes correctly implement the fix for the locale check, aligning with the PR objectives. The introduction of queryLocale improves code readability and maintainability.

Consider adding a brief comment explaining the locale logic:

// Set query locale to 'is' for Icelandic, 'en' for all other locales
const queryLocale = locale === 'is-IS' ? 'is' : 'en'

This would provide context for future developers about the purpose of this check.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 52f1575 and 4748ff2.

Files selected for processing (1)
  • apps/native/app/src/screens/applications/applications.tsx (1 hunks)
Additional context used
Path-based instructions (1)
apps/native/app/src/screens/applications/applications.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
Additional comments not posted (1)
apps/native/app/src/screens/applications/applications.tsx (1)

Line range hint 1-191: Verify locale handling and consider further improvements.

The changes effectively address the locale issue without impacting other parts of the component. The use of usePreferencesStore() for locale management is a good practice for state management.

To ensure the changes don't have unintended consequences, please verify:

  1. The behavior of the application for both Icelandic and non-Icelandic locales.
  2. That the usePreferencesStore() hook correctly updates the locale when changed in the app settings.

Consider the following improvements:

  1. Extract the locale logic into a custom hook (e.g., useQueryLocale) for reusability across the app.
  2. Use a constant or enum for locale values to prevent typos and improve maintainability.

Example:

const LOCALES = {
  ICELANDIC: 'is-IS',
  QUERY_ICELANDIC: 'is',
  QUERY_DEFAULT: 'en',
} as const;

const useQueryLocale = () => {
  const { locale } = usePreferencesStore();
  return locale === LOCALES.ICELANDIC ? LOCALES.QUERY_ICELANDIC : LOCALES.QUERY_DEFAULT;
};

This approach would enhance code clarity and reduce the risk of errors in locale handling throughout the application.

@thoreyjona thoreyjona added the automerge Merge this PR as soon as all checks pass label Sep 23, 2024
@datadog-island-is
Copy link

datadog-island-is bot commented Sep 23, 2024

Datadog Report

All test runs fe5578c 🔗

3 Total Test Services: 0 Failed, 3 Passed
➡️ Test Sessions change in coverage: 7 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.99s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.72s 1 no change Link
web 0 0 0 84 0 31.13s 1 no change Link

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.63%. Comparing base (260b0e1) to head (ea0f9b9).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16115   +/-   ##
=======================================
  Coverage   36.63%   36.63%           
=======================================
  Files        6749     6749           
  Lines      138852   138852           
  Branches    39457    39457           
=======================================
  Hits        50863    50863           
  Misses      87989    87989           
Flag Coverage Δ
api 3.39% <ø> (ø)
api-domains-auth-admin 48.86% <ø> (ø)
web 1.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 260b0e1...ea0f9b9. Read the comment docs.

@thoreyjona thoreyjona removed the automerge Merge this PR as soon as all checks pass label Sep 23, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
apps/native/app/src/screens/home/applications-module.tsx (2)

24-26: LGTM: Styled component added correctly

The Wrapper styled component is well-implemented, following React and styled-components best practices. It enhances layout consistency by using theme values for spacing.

Consider using template literals for better readability:

const Wrapper = styled(View)`
-  margin-horizontal: ${({ theme }) => theme.spacing[2]}px;
+  margin-horizontal: ${({ theme }) => `${theme.spacing[2]}px`};
`

Locale checks for 'is-US' still present in several files

The PR intended to update locale checks from 'is-US' to 'is-IS'. However, the following files still contain 'is-US' locale comparisons:

  • apps/native/app/src/screens/applications/applications-in-progress.tsx
  • apps/native/app/src/screens/applications/applications-completed.tsx
  • apps/native/app/src/screens/applications/applications-incomplete.tsx

Please update these instances to ensure consistency with the intended locale settings.

Analysis chain

Line range hint 1-100: Overall LGTM, but PR objectives not directly addressed

The changes in this file improve layout consistency and code readability by introducing a Wrapper styled component and restructuring the rendering of loading and empty states. These modifications align well with React, TypeScript, and styled-components best practices.

However, it's important to note that the primary objective of the PR (fixing the locale check from 'is-US' to 'is-IS') is not directly addressed in this file.

To ensure the PR objectives are met, please run the following script to check for the locale change in other files:

This will help verify if the locale fix has been implemented in other parts of the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for locale checks in the codebase

# Test: Look for both 'is-US' and 'is-IS' locale checks
echo "Searching for 'is-US' locale checks:"
rg --type typescript --type javascript "locale\s*===\s*['\"](is-US)['\"]"

echo "\nSearching for 'is-IS' locale checks:"
rg --type typescript --type javascript "locale\s*===\s*['\"](is-IS)['\"]"

Length of output: 411


Script:

#!/bin/bash
# Description: Search for 'is-US' and 'is-IS' locale checks in TypeScript and JavaScript files

echo "Searching for 'is-US' locale checks:"
rg --type ts --type tsx --type js --type jsx "locale\s*===\s*['\"]is-US['\"]"

echo "\nSearching for 'is-IS' locale checks:"
rg --type ts --type tsx --type js --type jsx "locale\s*===\s*['\"]is-IS['\"]"

Length of output: 405


Script:

#!/bin/bash
# Description: Search for 'is-US' and 'is-IS' locale checks in TypeScript and JavaScript files using file extensions

echo "Searching for 'is-US' locale checks:"
rg "locale\s*===\s*['\"]is-US['\"]" --glob "*.ts" --glob "*.tsx" --glob "*.js" --glob "*.jsx"

echo "\nSearching for 'is-IS' locale checks:"
rg "locale\s*===\s*['\"]is-IS['\"]" --glob "*.ts" --glob "*.tsx" --glob "*.js" --glob "*.jsx"

Length of output: 2602

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4748ff2 and 880d367.

Files selected for processing (1)
  • apps/native/app/src/screens/home/applications-module.tsx (3 hunks)
Additional context used
Path-based instructions (1)
apps/native/app/src/screens/home/applications-module.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
Additional comments not posted (2)
apps/native/app/src/screens/home/applications-module.tsx (2)

4-5: LGTM: Import statements updated correctly

The new imports for styled and View are correctly added to support the new styled component. This follows TypeScript best practices by explicitly importing used components.


58-60: LGTM: Loading state layout improved

The addition of the Wrapper component around StatusCardSkeleton improves layout consistency by applying the same margins to the loading state. This change aligns well with the component's overall structure.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
apps/native/app/src/ui/lib/card/status-card.tsx (2)

Line range hint 133-140: LGTM: Improved ProgressMeter rendering condition

The updated condition !hideProgress for rendering the ProgressMeter component is more comprehensive and flexible. It correctly considers both progress and progressTotalSteps.

For even better clarity, consider using a positive condition:

-{!hideProgress && (
+{showProgress && (

This would require updating the variable name and its logic:

const showProgress = !!progress || !!progressTotalSteps;

135-135: LGTM: Improved prop handling for ProgressMeter

The use of the nullish coalescing operator in progress ?? 0 for the finishedSteps prop is a good improvement. It ensures a default value of 0 when progress is undefined or null, preventing potential issues.

Consider applying the same pattern to totalSteps for consistency:

-totalSteps={progressTotalSteps ?? 0}
+totalSteps={progressTotalSteps ?? 1}

This ensures that totalSteps is always at least 1, preventing potential division-by-zero errors in the ProgressMeter component.

apps/native/app/src/screens/applications/components/applications-preview.tsx (1)

86-86: Approved with a suggestion for improved readability

The change correctly modifies the condition for setting progressContainerWidth, ensuring it's only applied when there are multiple items in the slider. This optimization aligns well with NextJS best practices for efficient rendering.

To further improve code readability, consider extracting the width calculation into a constant:

const sliderWidth = screenWidth - theme.spacing[2] * 6;
progressContainerWidth={slider && count > 1 ? sliderWidth : undefined}

This separation of concerns makes the code more maintainable and easier to understand at a glance.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 880d367 and efb5fb7.

Files selected for processing (2)
  • apps/native/app/src/screens/applications/components/applications-preview.tsx (1 hunks)
  • apps/native/app/src/ui/lib/card/status-card.tsx (2 hunks)
Additional context used
Path-based instructions (2)
apps/native/app/src/screens/applications/components/applications-preview.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/native/app/src/ui/lib/card/status-card.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
Additional comments not posted (2)
apps/native/app/src/ui/lib/card/status-card.tsx (2)

102-103: LGTM: Improved readability with hideProgress variable

The introduction of the hideProgress variable enhances code readability and follows the DRY principle. It clearly encapsulates the condition for hiding the progress meter.


Line range hint 102-140: Overall: Improved robustness and flexibility of StatusCard component

The changes to the StatusCard component enhance its robustness and flexibility:

  1. Introduction of hideProgress improves readability and maintainability.
  2. Updated rendering condition for ProgressMeter is more comprehensive.
  3. Use of nullish coalescing operator in prop handling prevents potential issues with undefined values.

These modifications align well with React and TypeScript best practices, making the component more resilient to different prop scenarios.

@thoreyjona thoreyjona added the automerge Merge this PR as soon as all checks pass label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants