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(skilavottord): Fix issue with numberplate count #16120

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

birkirkristmunds
Copy link
Member

@birkirkristmunds birkirkristmunds commented Sep 23, 2024

TS-916

What

Set number plate count to 0 if useStatus is not "Úr umferð (miði)" and outInStatus is "out".
Fix issues that number plate count is not correct in the parent component when revisiting the page.

Why

Fix issue that happens from time to time in Skilavottord that number plate count isn’t being sent to Samgöngustofa, causes this error car-recycling: Deregistered process failed. xxx

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 a reloadFlag property to enhance component reloading for accurate data display.
    • Added logic to manage reloadFlag state in the vehicle confirmation process.
  • Improvements

    • Changed the handling of plateCount assignment to ensure it reflects the actual value without defaulting.
  • Bug Fixes

    • Adjusted logic to conditionally set plateCount based on vehicle status.

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

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes introduce a new boolean property, reloadFlag, to the BoxProps interface of the CarDetailsBox2 component to manage component reloading. Additionally, the Confirm component is updated to include a state variable for reloadFlag, modifying the logic for handling vehicle information updates. The plateCount parameter in the vehicle-related methods has been adjusted to accept nullable values, enhancing flexibility in how vehicle data is processed.

Changes

File Change Summary
apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx Added reloadFlag: boolean to BoxProps interface.
apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx Introduced reloadFlag state variable and logic; updated plateCount type from Float! to Float; modified handleConfirm to conditionally set plateCount.
apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts Updated plateCount argument in updateVehicleInfo method to allow nullable values.
apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts Changed plateCount parameter in updateVehicleInfo method to be optional with a default value of 0, removing nullish coalescing operator for assignment.

Possibly related PRs

  • fix(applications): Minor translation fixes #15929: The Confirm.tsx file in this PR introduces a new state variable reloadFlag, which is directly related to the addition of the reloadFlag property in the BoxProps interface of the CarDetailsBox2 component in the main PR. Both changes involve managing component reloading behavior.
  • fix(skilavottord): Check current owner on deregistration #14763: This PR modifies the plateCount variable type in the Confirm.tsx file, which is also referenced in the main PR's context of vehicle information updates. While not directly related to the reloadFlag, it indicates a broader context of changes in vehicle-related components.

Suggested labels

automerge

Suggested reviewers

  • helgifr

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: 4

Outside diff range and nitpick comments (2)
apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx (1)

Line range hint 1-186: Overall structure adheres to best practices with room for minor improvements

The component generally follows NextJS and React best practices, with effective use of TypeScript for type safety. However, there are a few areas where it could be improved:

  1. Prop usage: The reloadFlag prop is defined but not used in the component.
  2. State management: Consider using the useReducer hook for managing related state variables like missingPlates and lostPlate.
  3. Prop drilling: The component receives many props. Consider using React Context or a state management library if this pattern is common across your application.

Here's an example of how you could use useReducer for state management:

type State = {
  missingPlates: boolean;
  lostPlate: boolean;
};

type Action =
  | { type: 'SET_MISSING_PLATES'; payload: boolean }
  | { type: 'SET_LOST_PLATE'; payload: boolean };

const reducer = (state: State, action: Action): State => {
  switch (action.type) {
    case 'SET_MISSING_PLATES':
      return { ...state, missingPlates: action.payload };
    case 'SET_LOST_PLATE':
      return { ...state, lostPlate: action.payload };
    default:
      return state;
  }
};

// In your component:
const [state, dispatch] = useReducer(reducer, {
  missingPlates: false,
  lostPlate: false,
});

// Then use dispatch to update state, e.g.:
dispatch({ type: 'SET_MISSING_PLATES', payload: true });

This approach can make your state updates more predictable and easier to test.

apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx (1)

109-112: Inline triggerReload function for clarity

The triggerReload function is only used once and can be inlined for simplicity. This makes the code more concise and easier to read.

Modify the useEffect hook to set reloadFlag directly:

-  const triggerReload = () => {
-    setReloadFlag(true)
-  }

   useEffect(() => {
-    triggerReload()
+    setReloadFlag(true)
   }, [])
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c04c51 and 3dda7b5.

Files selected for processing (4)
  • apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx (1 hunks)
  • apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx (6 hunks)
  • apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts (1 hunks)
  • apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts (1 hunks)
Additional context used
Path-based instructions (4)
apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.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/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.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/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.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/skilavottord/ws/src/app/modules/vehicle/vehicle.service.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."
Additional comments not posted (7)
apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts (1)

Line range hint 1-124: Overall assessment: Changes improve flexibility with minor concerns

The modifications to the updateVehicleInfo method in the VehicleService class enhance the flexibility of the API while maintaining backwards compatibility. The changes align well with NextJS best practices and improve TypeScript usage.

However, there's a minor concern regarding the potential for null or undefined values being assigned to plateCount. Implementing the suggested type guard or updating the method signature would further improve type safety without compromising the added flexibility.

The overall structure and functionality of the VehicleService class remain sound, with no apparent issues in state management or server-side rendering techniques.

apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts (2)

Line range hint 1-124: Overall assessment: Code change aligns with PR objectives

The modification to make plateCount nullable in the updateSkilavottordVehicleInfo method aligns with the PR objective of fixing the issue with numberplate count. The code maintains good TypeScript practices and follows NextJS conventions.

However, as noted in the PR objectives, corresponding changes to the documentation have not been made. Consider updating the documentation to reflect this change in the API.


111-111: Verify handling of nullable plateCount in vehicleService

The change to make plateCount nullable improves the flexibility of the API, which aligns with the PR objective of fixing the numberplate count issue. However, please ensure the following:

  1. Verify that the updateVehicleInfo method in vehicleService can handle a nullable plateCount.
  2. Update any frontend code that calls this method to account for the optional plateCount.
  3. Consider adding documentation to explain when plateCount can be omitted and its implications.

To verify the handling of nullable plateCount, please run the following script:

apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx (1)

36-36: Consider revising the reloadFlag implementation

The reloadFlag property has been added to the BoxProps interface, but it's not being used within the component. This suggests a potential issue with data flow or state management.

Consider the following alternatives:

  1. If the reloadFlag is necessary, implement its usage within the component, possibly with the useEffect hook to trigger a re-render or data fetch.
  2. If the goal is to ensure data accuracy, consider using React's built-in state management or a state management library like Redux for more predictable data flow.
  3. If the property is no longer needed, remove it to keep the interface clean.

Example implementation using useEffect:

useEffect(() => {
  if (reloadFlag) {
    // Perform necessary data refresh or re-render logic here
  }
}, [reloadFlag]);

To confirm if reloadFlag is used elsewhere or if similar patterns exist:

Verification successful

reloadFlag is properly utilized within the component

The reloadFlag property is correctly used in apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx to manage the state and is passed to CarDetailsBox2.tsx as intended.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of reloadFlag in other components
rg --type typescript 'reloadFlag'

# Look for similar reload patterns in other components
ast-grep --lang typescript --pattern 'interface $interface { $$$1 reload: boolean $$$2 }'

Length of output: 160


Script:

#!/bin/bash
# Search for usage of reloadFlag in TypeScript files
rg --type ts --type tsx 'reloadFlag'

# Look for similar reload patterns in other components
ast-grep --lang typescript --pattern 'interface $interface { $$$1 reload: boolean $$$2 }'

Length of output: 156


Script:

#!/bin/bash
# Search for usage of reloadFlag in TypeScript files
rg 'reloadFlag' --glob '*.ts' --glob '*.tsx'

# Look for similar reload patterns in other components
ast-grep --lang typescript --pattern 'interface $interface { $$$1 reload: boolean $$$2 }'

Length of output: 757

apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx (3)

211-213: Validate logic for setting plateCount to zero

The condition on lines 211-213 sets plateCount to 0 based on outInStatus and useStatus. Verify that this logic aligns with the business rules and that setting plateCount to zero is the intended behavior in this scenario.


298-298: Confirm that CarDetailsBox2 accepts reloadFlag prop

You are passing reloadFlag to CarDetailsBox2 on line 298. Ensure that CarDetailsBox2 is designed to handle this prop and that it triggers the expected behavior within the child component.

Check the CarDetailsBox2 component to confirm it utilizes the reloadFlag prop appropriately.


90-90: Ensure backend compatibility with nullable plateCount

The mutation updateSkilavottordVehicleInfo now accepts plateCount as Float (nullable). Verify that the backend schema allows plateCount to be null and handles it correctly to prevent potential runtime errors.

Run the following script to confirm that plateCount is defined as a nullable field in the GraphQL schema:

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 36.63%. Comparing base (18ee0a4) to head (c943ce3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tord/ws/src/app/modules/vehicle/vehicle.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16120      +/-   ##
==========================================
- Coverage   36.65%   36.63%   -0.03%     
==========================================
  Files        6750     6749       -1     
  Lines      138925   138816     -109     
  Branches    39473    39439      -34     
==========================================
- Hits        50926    50855      -71     
+ Misses      87999    87961      -38     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.50% <ø> (ø)
application-template-api-modules 23.44% <ø> (-0.02%) ⬇️
skilavottord-ws 24.34% <0.00%> (ø)

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

Files with missing lines Coverage Δ
...ord/ws/src/app/modules/vehicle/vehicle.resolver.ts 0.00% <ø> (ø)
...tord/ws/src/app/modules/vehicle/vehicle.service.ts 19.56% <0.00%> (ø)

... and 18 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 18ee0a4...c943ce3. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 23, 2024

Datadog Report

All test runs 4095869 🔗

6 Total Test Services: 0 Failed, 6 Passed
➡️ Test Sessions change in coverage: 12 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 3.09s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.01s 1 no change Link
application-system-api 0 0 0 111 2 3m 16.96s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 40.99s 1 no change Link
skilavottord-ws 0 0 0 1 0 13.58s 1 no change Link
web 0 0 0 84 0 29.88s 1 no change Link

Copy link
Member

@veronikasif veronikasif left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@birkirkristmunds birkirkristmunds added the automerge Merge this PR as soon as all checks pass label Sep 23, 2024
@kodiakhq kodiakhq bot merged commit 4e76ba9 into main Sep 23, 2024
40 checks passed
@kodiakhq kodiakhq bot deleted the fix/skilavottord-fix-number-plate-count branch September 23, 2024 22:44
birkirkristmunds added a commit that referenced this pull request Sep 24, 2024
* TS-916 Fix issue with numberplate count

* TS-916 Fix code after code rabbit review

* TS-916 Fix code after code rabbit review

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Sep 24, 2024
* TS-916 Fix issue with numberplate count

* TS-916 Fix code after code rabbit review

* TS-916 Fix code after code rabbit review

---------

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