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(samgongustofa): Disable "Continue" button when selecting vehicle with error (and user has over 20 vehicles) #16752

Conversation

johannaagma
Copy link
Member

@johannaagma johannaagma commented Nov 7, 2024

What

When searching for vehicle (user has over 20), user is able to continue here:

image

We should disable the button, and also make zod validation prevent him from continuing to the next step

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

    • Enhanced flexibility in the VehiclesField component for better prop management.
    • Improved error handling and state management in the FindVehicleFormField, ensuring accurate vehicle details processing.
  • Bug Fixes

    • Refined logic for enabling/disabling the submission button based on vehicle status.
  • Documentation

    • Updated function signatures for clarity in the FindVehicleFormField.

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes involve modifications to the VehiclesField and FindVehicleFormField components. In VehiclesField, props are now forwarded using a spread operator, enhancing flexibility. The updateData function's dependencies have been updated to include updateApplication and locale, ensuring correct state updates. In FindVehicleFormField, error handling and state management have been improved, with updates to the submission button's enabled state and vehicle detail handling. Overall, these changes enhance prop management and robustness without altering the fundamental logic of the components.

Changes

File Change Summary
libs/application/templates/.../VehiclesField/index.tsx Updated prop handling in VehiclesField, replacing explicit application prop with {...props} spread operator. Adjusted updateData dependencies and useEffect logic for state updates.
libs/application/ui-fields/src/lib/FindVehicleFormField/.../FindVehicleFormField.tsx Enhanced error handling and state management in FindVehicleFormField. Updated function signatures and variable names, refined logic for vehicle and submission button states.

Possibly related PRs

  • fix(SGS): Fixing bug in FindVehicleFormField for Order-Plate #14904: This PR modifies the FindVehicleFormField component, which is directly related to the changes made in the VehiclesField component that forwards props to FindVehicleFormField. Both PRs involve updates to the same component, focusing on prop management and state handling.

Suggested labels

automerge

Suggested reviewers

  • thordurhhh
  • veronikasif

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

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.

Project coverage is 36.53%. Comparing base (b0a8c22) to head (5c08713).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../lib/FindVehicleFormField/FindVehicleFormField.tsx 0.00% 24 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16752      +/-   ##
==========================================
- Coverage   36.54%   36.53%   -0.01%     
==========================================
  Files        6888     6890       +2     
  Lines      143667   143657      -10     
  Branches    40937    40937              
==========================================
- Hits        52497    52486      -11     
- Misses      91170    91171       +1     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.35% <ø> (ø)
application-api-files 56.54% <ø> (ø)
application-core 70.98% <ø> (-0.08%) ⬇️
application-system-api 41.11% <ø> (ø)
application-template-api-modules 27.68% <ø> (+0.02%) ⬆️
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.26% <ø> (ø)
application-templates-estate 12.17% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.22% <ø> (ø)
application-templates-parental-leave 29.84% <ø> (ø)
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.80% <0.00%> (-0.02%) ⬇️
auth-react 21.92% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
contentful-apps 4.69% <ø> (ø)
financial-aid-backend 51.25% <ø> (ø)
financial-aid-shared 17.81% <ø> (ø)
island-ui-core 28.94% <ø> (ø)
judicial-system-web 27.58% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.95% <ø> (ø)
services-auth-personal-representative 45.56% <ø> (-0.03%) ⬇️
shared-components 26.95% <ø> (ø)
shared-form-fields 31.35% <ø> (ø)
web 1.80% <ø> (ø)

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

Files with missing lines Coverage Δ
.../lib/FindVehicleFormField/FindVehicleFormField.tsx 2.19% <0.00%> (-0.07%) ⬇️

... and 11 files with indirect coverage changes


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 b0a8c22...5c08713. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 7, 2024

Datadog Report

All test runs a77140d 🔗

34 Total Test Services: 0 Failed, 32 Passed
🔻 Test Sessions change in coverage: 2 decreased, 148 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 7.1s 1 no change Link
api 0 0 0 4 0 2.35s 1 no change Link
application-api-files 0 0 0 12 0 5.41s 1 no change Link
application-core 0 0 0 97 0 14.63s 1 decreased (-0.1%) Link
application-system-api 0 0 0 120 2 3m 43.82s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 6.85s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 16.85s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 9.87s 1 no change Link
application-templates-driving-license 0 0 0 13 0 13.24s 1 no change Link
application-templates-example-payment 0 0 0 2 0 10.26s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • application-core - jest 78.59% (-0.1%) - Details
  • application-ui-shell - jest 27.03% (-0.02%) - Details

@johannaagma johannaagma marked this pull request as ready for review November 7, 2024 08:33
@johannaagma johannaagma requested review from a team as code owners November 7, 2024 08:33
@johannaagma johannaagma changed the title fix(samgongustofa): Disable "Continue" button when selectin vehicle with error (and user has over 20 vehicles) fix(samgongustofa): Disable "Continue" button when selecting vehicle with error (and user has over 20 vehicles) Nov 7, 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 (4)
libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx (2)

65-65: Consider using a more specific prop spreading approach.

While spreading all props enhances flexibility, it might pass unnecessary props to the child component. Consider explicitly spreading only the required props or creating a dedicated type for the expected props.

-{...props}
+{
+  application: props.application,
+  setFieldLoadingState: props.setFieldLoadingState,
+  setSubmitButtonDisabled: props.setSubmitButtonDisabled,
+  // Add other necessary props
+}

Line range hint 39-53: Fix missing dependencies in useCallback.

The updateData callback uses updateApplication and locale, but they're not included in the dependency array. This could lead to stale closures.

  }, [
+   updateApplication,
+   application.id,
+   locale
  ])
libs/application/ui-fields/src/lib/FindVehicleFormField/FindVehicleFormField.tsx (2)

200-212: Consider improving error handling with TypeScript types

The error handling could be more robust by defining specific error types for better type safety and error differentiation.

- } catch (error) {
+ } catch (error: unknown) {
+   const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
    console.error('error', error)

Line range hint 262-302: Consider extracting common state management logic

The machine and vehicle state management share similar patterns. Consider extracting the common logic into a custom hook for better reusability and maintainability.

Example approach:

function useVehicleState<T extends { disabled?: boolean }>(
  fieldId: string,
  setValue: Function
) {
  const setCommonValues = (details: T, isDisabled: boolean) => {
    setValue('findVehicle', true)
    setSubmitButtonDisabled?.(!isDisabled)
    // ... other common logic
  }
  return { setCommonValues }
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3856383 and d8e1d21.

📒 Files selected for processing (2)
  • libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/FindVehicleFormField/FindVehicleFormField.tsx (8 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/FindVehicleFormField/FindVehicleFormField.tsx (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (4)
libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx (2)

Line range hint 28-37: LGTM! Well-structured vehicle details fetching logic.

The wrapper function provides a clean abstraction for vehicle details fetching with proper TypeScript types and error handling.


Line range hint 54-95: Implementation aligns with PR objectives.

The conditional rendering correctly handles users with over 20 vehicles by using FindVehicleFormField with proper error handling and button state management. This matches the PR's goal of disabling the 'Continue' button when selecting a vehicle with error.

✅ Verification successful

Implementation correctly handles submit button state

The FindVehicleFormField component properly implements the setSubmitButtonDisabled functionality:

  • Disables submit button when vehicle validation fails
  • Enables submit button when a valid vehicle is selected
  • Consistently handles error states and loading states
  • Used consistently across different vehicle-related forms in the codebase

The implementation aligns with the PR objectives and follows the established patterns across the codebase for managing form submission states.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that FindVehicleFormField is used consistently across the codebase
ast-grep --pattern 'FindVehicleFormField setSubmitButtonDisabled={$_}'

Length of output: 72


Script:

#!/bin/bash
# Let's try a broader search for FindVehicleFormField usage
ast-grep --pattern 'FindVehicleFormField'

# Also search for the component file to understand its implementation
fd FindVehicleFormField

# Search for setSubmitButtonDisabled prop usage in TSX files
rg "setSubmitButtonDisabled" -t tsx

Length of output: 4011


Script:

#!/bin/bash
# Let's examine the FindVehicleFormField component implementation
cat libs/application/ui-fields/src/lib/FindVehicleFormField/FindVehicleFormField.tsx

# And check for setSubmitButtonDisabled usage with proper file extension
rg "setSubmitButtonDisabled" --type-add 'tsx:*.tsx' -t tsx

Length of output: 24695

libs/application/ui-fields/src/lib/FindVehicleFormField/FindVehicleFormField.tsx (2)

233-257: LGTM: Effective implementation of vehicle validation and button state

The implementation correctly handles the disabled state based on validation errors and debt status, which aligns with the PR objective of preventing users from proceeding with invalid vehicle selections.


Line range hint 416-524: LGTM: Clear visual feedback for disabled states

The implementation provides clear visual feedback through color coding and error messages when a vehicle or machine is disabled, improving the user experience.

Copy link
Member

@jonnigs jonnigs left a comment

Choose a reason for hiding this comment

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

LGMT

@johannaagma johannaagma added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 7, 2024
@kodiakhq kodiakhq bot merged commit f117a85 into main Nov 7, 2024
120 checks passed
@kodiakhq kodiakhq bot deleted the fix/samgongustofa-dont-allow-continue-if-error-vehicle-search-field branch November 7, 2024 13:15
robertaandersen pushed a commit that referenced this pull request Nov 11, 2024
…with error (and user has over 20 vehicles) (#16752)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
jonnigs pushed a commit that referenced this pull request Nov 12, 2024
…with error (and user has over 20 vehicles) (#16752)

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
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants