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): Android users should be able to edit their mileage #15426

Merged
merged 5 commits into from
Jul 11, 2024

Conversation

thoreyjona
Copy link
Contributor

@thoreyjona thoreyjona commented Jul 3, 2024

What

When you submit mileage for you electric car you can edit it for 24 hours or some time period by clicking on the newest mileage and then a prompt should appear to allow you to edit. This does not work on android and probably never has I think 🫠

Also added better error handling for editing mileage and made dark mode a little bit smoother.

Why

Android users should be able to edit their mileage like iOS users.

Screenshots

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

    • Introduced platform-specific prompts for editing mileage on iOS and Android.
    • Added dynamic theme-based color changes in dark mode for the MileageCell component.
  • Refactor

    • Refactored mileage submission logic to include new functions for better error handling and success messaging.
  • Bug Fixes

    • Enhanced background color logic in the MileageCell component for better theme support in dark mode.

@thoreyjona thoreyjona requested a review from a team as a code owner July 3, 2024 09:23
Copy link
Contributor

coderabbitai bot commented Jul 3, 2024

Walkthrough

The updates across the components primarily focus on enhancing the mileage editing and submission process. This includes introducing platform-specific prompts for Android and iOS, using dynamic colors based on themes, and refining the error handling and success messaging mechanisms.

Changes

File Path Change Summary
apps/native/app/src/lib/show-picker.ts Added functions for Android-specific prompts and action parsing, and imported dynamicColor module.
.../screens/vehicles/components/mileage-cell.tsx Updated background color logic to use dynamic colors based on themes for dark mode.
.../screens/vehicles/vehicle-mileage.screen.tsx Refactored mileage editing and submission logic, added platform-specific prompts, and enhanced error handling.
.../types/react-native.d.ts Introduced new types for react-native-dialogs, enhancing prompt dialog options and responses.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant MileageCell
  participant VehicleMileageScreen
  participant showAndroidPrompt
  participant showIosPrompt

  User->>MileageCell: Tap on edit mileage
  MileageCell->>VehicleMileageScreen: Call onEdit
  alt isAndroid
    VehicleMileageScreen->>showAndroidPrompt: Display Android prompt
    showAndroidPrompt-->>VehicleMileageScreen: Return user input
  else isIos
    VehicleMileageScreen->>showIosPrompt: Display iOS prompt
    showIosPrompt-->>VehicleMileageScreen: Return user input
  end
  VehicleMileageScreen->>VehicleMileageScreen: Call onEditMileageSubmit
  VehicleMileageScreen->>User: Display success or error message
Loading

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

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit Configration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link
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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 61a4a34 and 3efb6c8.

Files selected for processing (4)
  • apps/native/app/src/lib/show-picker.ts (3 hunks)
  • apps/native/app/src/screens/vehicles/components/mileage-cell.tsx (1 hunks)
  • apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx (3 hunks)
  • apps/native/app/src/types/react-native.d.ts (2 hunks)
Additional context used
Path-based instructions (4)
apps/native/app/src/screens/vehicles/components/mileage-cell.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/types/react-native.d.ts (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/lib/show-picker.ts (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/screens/vehicles/vehicle-mileage.screen.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."
Biome
apps/native/app/src/types/react-native.d.ts

[error] 17-17: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

[error] 262-283: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (8)
apps/native/app/src/screens/vehicles/components/mileage-cell.tsx (1)

45-46: Ensure the dynamic color implementation is correct.

The dynamic color implementation for dark mode looks good. Verify that the dynamicColor function returns the expected color values for different themes.

apps/native/app/src/types/react-native.d.ts (3)

40-56: Ensure prompt-specific options are correctly defined.

The OptionsPrompt type definition looks correct. Verify that all properties are being used as expected in the codebase.


58-71: Ensure prompt response types are correctly defined.

The PromptResponse type definition looks correct. Verify that all possible response shapes are being handled correctly in the codebase.


82-86: Ensure the prompt function signature is correct.

The prompt function signature looks correct. Verify that the function is being called with the appropriate options in the codebase.

apps/native/app/src/lib/show-picker.ts (2)

58-71: Ensure the action parsing logic is correct.

The parseAndroidAction function logic looks correct. Verify that all possible action strings are being handled correctly.


159-182: Ensure the Android prompt logic is correct.

The showAndroidPrompt function logic looks correct. Verify that the theme colors and options are being applied correctly.

apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx (2)

182-233: Ensure the mileage submission logic is correct.

The onEditMileageSubmit function logic looks correct. Verify that the mileage is being parsed and submitted correctly.


Line range hint 114-130: Ensure the mileage parsing logic is correct.

The parseMileage function logic looks correct. Verify that the mileage input is being parsed and validated correctly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3efb6c8 and 749663c.

Files selected for processing (1)
  • apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Copy link
Member

@eirikurn eirikurn left a comment

Choose a reason for hiding this comment

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

Nice!

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, codebase verification and nitpick comments (3)
apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx (3)

224-231: Improve error handling in the catch block.

Consider logging the error or providing more details in the error alert for better debugging.

- .catch(() => {
+ .catch((error) => {
+   console.error('Failed to update mileage:', error);

186-187: Ensure data[0].internalId is always defined.

The initialization of data suggests that it could potentially be an empty array, which means data[0] might be undefined. This makes data[0].internalId potentially undefined as well. Consider adding a check to ensure data[0] is defined before accessing internalId.

  • Location: apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx at lines 186-187.
Analysis chain

Confirm that data[0].internalId is always defined.

Ensure that data[0].internalId is always defined before using it.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `data[0].internalId` is always defined.

# Test: Search for the data structure and ensure `internalId` is always defined.
rg --type tsx 'internalId' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 118


Script:

#!/bin/bash
# Description: Verify that `data[0].internalId` is always defined.

# Test: Search for the data structure and ensure `internalId` is always defined.
rg 'internalId' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 317


Script:

#!/bin/bash
# Description: Verify how `data` is populated to ensure `internalId` is always defined.

# Test: Search for the definition and initialization of `data` within the file.
rg 'data' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 1153


265-275: Ensure showAndroidPrompt handles all edge cases.

The current implementation of the showAndroidPrompt function does not explicitly handle input validation or error handling. It primarily relies on DialogAndroid.prompt and parseAndroidAction. Consider adding explicit input validation and error handling within the showAndroidPrompt function to ensure all edge cases are managed effectively.

  • Location: apps/native/app/src/lib/show-picker.ts
Analysis chain

Ensure showAndroidPrompt handles all edge cases.

Verify that the showAndroidPrompt function handles all edge cases and provides appropriate feedback to the user.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `showAndroidPrompt` handles all edge cases.

# Test: Search for the implementation of `showAndroidPrompt`. Expect: Proper handling of edge cases.
rg --type ts 'showAndroidPrompt' apps/native/app/src/lib/show-picker.ts

Length of output: 106


Script:

#!/bin/bash
# Extract the full implementation of the showAndroidPrompt function from the identified file.
ast-grep --lang typescript --pattern 'function showAndroidPrompt($_, $_, $_) { $$$ }' apps/native/app/src/lib/show-picker.ts

Length of output: 126


Script:

#!/bin/bash
# Extract the implementation of the showAndroidPrompt function with context lines for better understanding.
rg --type ts -A 50 'export function showAndroidPrompt' apps/native/app/src/lib/show-picker.ts

Length of output: 787

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 749663c and 5f24b85.

Files selected for processing (1)
  • apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx (3 hunks)
Additional context used
Path-based instructions (1)
apps/native/app/src/screens/vehicles/vehicle-mileage.screen.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 (5)
apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx (5)

198-206: Check for successful mutation handling.

Ensure that the mutation updateMileage handles both success and error responses correctly.


236-237: Omit the else clause to simplify the code.

The else clause can be omitted because previous branches break early.

-  } else if (isAndroid) {
+  }
+  if (isAndroid) {

29-31: Verify the usage of new imports.

Ensure that the newly imported entities (showAndroidPrompt, isAndroid, and isIos) are used correctly in the code.

Verification successful

Verified the usage of new imports.

The imported entities (showAndroidPrompt, isAndroid, and isIos) are used correctly in the file.

  • showAndroidPrompt is used in an await statement.
  • isAndroid is used in a conditional statement.
  • isIos is used in a conditional statement.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of newly imported entities.

# Test: Search for the usage of `showAndroidPrompt`. Expect: Proper usage within the file.
rg --type tsx 'showAndroidPrompt' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

# Test: Search for the usage of `isAndroid`. Expect: Proper usage within the file.
rg --type tsx 'isAndroid' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

# Test: Search for the usage of `isIos`. Expect: Proper usage within the file.
rg --type tsx 'isIos' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 357


Script:

#!/bin/bash
# Description: Verify the usage of newly imported entities.

# Test: Search for the usage of `showAndroidPrompt`. Expect: Proper usage within the file.
rg 'showAndroidPrompt' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

# Test: Search for the usage of `isAndroid`. Expect: Proper usage within the file.
rg 'isAndroid' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

# Test: Search for the usage of `isIos`. Expect: Proper usage within the file.
rg 'isIos' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 477


Line range hint 146-153:
Ensure proper handling of non-numeric input.

Verify that the function handles non-numeric input correctly and provides appropriate feedback.

Verification successful

Verified: Proper handling of non-numeric input in parseMileage function.

The function processes non-numeric input by stripping non-numeric characters and converting the result to a number. It ensures the number is valid within the specified range, providing appropriate feedback via alerts.

  • The regex \D removes non-numeric characters.
  • Alerts are shown for values that are too low or too high.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of non-numeric input in `parseMileage`.

# Test: Search for the usage of `parseMileage`. Expect: Proper handling of non-numeric input.
rg --type tsx 'parseMileage' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 120


Script:

#!/bin/bash
# Description: Verify the handling of non-numeric input in `parseMileage`.

# Test: Search for the usage of `parseMileage`. Expect: Proper handling of non-numeric input.
rg 'parseMileage' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 314


Script:

#!/bin/bash
# Description: Extract the implementation of `parseMileage` function.

# Extract the implementation of `parseMileage` from the specified file.
rg -A 20 'const parseMileage' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 838


183-184: Ensure proper error handling for undefined mileageInput.

Check if mileageInput is undefined before proceeding with the rest of the function logic.

Verification successful

Proper error handling for undefined mileageInput is present.

The onEditMileageSubmit function checks the validity of the parsed mileageInput and returns early if it is not valid, effectively handling undefined values.

  • The function starts by parsing mileageInput and checks if the resulting mileage is valid.
  • If mileage is not valid, the function returns early, preventing further execution.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of undefined `mileageInput`.

# Test: Search for the usage of the `onEditMileageSubmit` function. Expect: Proper handling of undefined `mileageInput`.
rg --type tsx 'onEditMileageSubmit' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 127


Script:

#!/bin/bash
# Description: Verify the handling of undefined `mileageInput`.

# Test: Search for the usage of the `onEditMileageSubmit` function. Expect: Proper handling of undefined `mileageInput`.
rg --type=typescript 'onEditMileageSubmit' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 141


Script:

#!/bin/bash
# Description: Verify the handling of undefined `mileageInput`.

# Test: Search for the usage of the `onEditMileageSubmit` function. Expect: Proper handling of undefined `mileageInput`.
rg 'onEditMileageSubmit' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 276


Script:

#!/bin/bash
# Extract the function definition of `onEditMileageSubmit` to check for proper error handling.
rg -A 20 'const onEditMileageSubmit = useCallback' apps/native/app/src/screens/vehicles/vehicle-mileage.screen.tsx

Length of output: 757

@thoreyjona thoreyjona added the automerge Merge this PR as soon as all checks pass label Jul 11, 2024
@kodiakhq kodiakhq bot merged commit 8bbf2d0 into main Jul 11, 2024
24 checks passed
@kodiakhq kodiakhq bot deleted the fix/edit-mileage-android branch July 11, 2024 09:43
oskarjs pushed a commit that referenced this pull request Aug 20, 2024
…15426)

* fix: android users can edit their newly submitted mileage now

* fix: dark mode color of editable mileage cell

* fix: no need for else if

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
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