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

chore(j-s): Use lawyer registry from api #17434

Merged
merged 15 commits into from
Jan 17, 2025
Merged

chore(j-s): Use lawyer registry from api #17434

merged 15 commits into from
Jan 17, 2025

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Jan 7, 2025

Use lawyer registry from api

Asana

What

When we first integrated with the lawyer registry from LMFI we did so by creating an API route and calling the endpoint from there. Then when we were working on showing subpoenas on minar sidur we created the same module in our API layer because minar sidur needed to get the lawyer registry from us.

This PR cleans this code up a bit by removing the API routes and using the module in the API layer as well.

Why

This way, we don't have code that does the same thing living in two different places.

Screenshots / Gifs

Here you can see we're calling /api/defender/lawyerRegistry instead of /api/lawyers/getLawyers

Screenshot 2025-01-07 at 20 55 45

and here we're calling /api/defenders/lawyerRegistry/:id instead of /api/lawyers/getLawyer?nationalId=:id

Screenshot 2025-01-07 at 21 01 17

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

  • API Changes

    • Removed API endpoints for retrieving individual lawyer and list of lawyers.
    • Updated hooks to use new API endpoint /api/defender/lawyerRegistry.
  • Refactor

    • Simplified data fetching logic in lawyer-related hooks.
    • Consolidated fetch function across lawyer data retrieval methods.
  • New Features

    • Added specific error message for failures in fetching lawyer data.
  • Impact

    • Changes to how lawyer data is fetched and accessed in the application.
    • Potential improvements in data retrieval efficiency and endpoint management.

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > puppeteer-core > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > tempy > del > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > [email protected]: Rimraf versions prior to v4 are no longer supported
warning storybook > @storybook/cli > jscodeshift > temp > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning storybook > @storybook/cli > jscodeshift > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning react-native > @react-native/codegen > [email protected]: Glob versions prior to v9 are no longer supported
warning react-native > @react-native/community-cli-plugin > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning react-native > @react-native-community/cli > @react-native-community/cli-tools > [email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning react-native > @react-native/community-cli-plugin > @react-native/dev-middleware > @rnx-kit/chromium-edge-launcher > [email protected]: Rimraf versions prior to v4 are no longer supported
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.
warning react-native > @react-native/community-cli-plugin > @react-native/metro-babel-transformer > @react-native/babel-preset > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning next-auth > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning next-auth > [email protected]: this version is no longer supported
warning next-auth > @next-auth/typeorm-legacy-adapter > typeorm > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > stylus > [email protected]: Glob versions prior to v9 are no longer supported
warning @nx/next > @nx/webpack > webpack-dev-server > [email protected]: Rimraf versions prior to v4 are no longer supported
warning @nx/next > @nx/webpack > fork-ts-checker-webpack-plugin > [email protected]: this will be v4
warning @nx/next > @nx/webpack > webpack-dev-server > webpack-dev-middleware > [email protected]: this will be v4
warning workspace-aggregator-1c1994cb-e251-49db-b3b2-d1097e8b1339 > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning "@nx/eslint > @nx/js > [email protected]" has unmet peer dependency "@types/node@".
warning "@nx/next > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "styled-components > babel-plugin-styled-components > @babel/[email protected]" has unmet peer dependency "@babel/core@^7.0.0-0".
warning " > [email protected]" has unmet peer dependency "react-is@>= 16.8.0".
warning "@nx/react > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > [email protected]" has unmet peer dependency "@types/node@
".
warning " > [email protected]" has incorrect peer dependency "[email protected]".
warning "react-native > @react-native/[email protected]" has unmet peer dependency "@babel/preset-env@^7.1.6".
warning "react-native > @react-native/community-cli-plugin > @react-native/[email protected]" has unmet peer dependency "@babel/core@*".
warning "@vanilla-extract/next-plugin > @vanilla-extract/[email protected]" has unmet peer dependency "webpack@^4.30.0 || ^5.20.2".
warning " > [email protected]" has incorrect peer dependency "react@^16.13.1 || ^17".
warning " > [email protected]" has incorrect peer dependency "react-dom@^16.13.1 || ^17".
warning "next-auth > @next-auth/[email protected]" has unmet peer dependency "@prisma/client@^2.16.1".
warning "@nx/next > [email protected]" has unmet peer dependency "webpack@^5.1.0".

Walkthrough

This pull request involves the removal of several API endpoint files related to lawyer retrieval (getLawyer.ts, getLawyers.ts, and their corresponding index.ts files) and updates to the useLawyers hook. The changes redirect lawyer data fetching to a new endpoint /api/defender/lawyerRegistry, replacing the previous custom API routes with a more centralized approach. The modifications simplify the data retrieval process by consolidating the fetching logic and updating the API endpoints for both lawyer and individual lawyer retrieval.

Changes

File Change Summary
apps/judicial-system/web/pages/api/lawyers/getLawyer/getLawyer.ts Deleted API handler for retrieving individual lawyer by national ID
apps/judicial-system/web/pages/api/lawyers/getLawyer/index.ts Deleted index file that exported the lawyer retrieval handler
apps/judicial-system/web/pages/api/lawyers/getLawyers/getLawyers.ts Deleted API handler for fetching multiple lawyers
apps/judicial-system/web/pages/api/lawyers/getLawyers/index.ts Deleted index file that exported the lawyers retrieval handler
apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts Updated hooks to use new /api/defender/lawyerRegistry endpoint and refactored fetch logic
apps/judicial-system/web/messages/Core/errors.ts Added new error message for fetching lawyer failures

Possibly related PRs

Suggested reviewers

  • unakb

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Jan 7, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 12 lines in your changes missing coverage. Please review.

Project coverage is 35.60%. Comparing base (e2c586b) to head (f134108).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ystem/web/src/utils/hooks/useLawyers/useLawyers.ts 33.33% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17434      +/-   ##
==========================================
- Coverage   35.60%   35.60%   -0.01%     
==========================================
  Files        7019     7010       -9     
  Lines      150408   150237     -171     
  Branches    42961    42943      -18     
==========================================
- Hits        53553    53489      -64     
+ Misses      96855    96748     -107     
Flag Coverage Δ
judicial-system-backend 55.80% <ø> (ø)
judicial-system-web 27.98% <33.33%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
apps/judicial-system/web/messages/Core/errors.ts 100.00% <ø> (ø)
...ystem/web/src/utils/hooks/useLawyers/useLawyers.ts 37.03% <33.33%> (-9.63%) ⬇️

... and 52 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 e2c586b...f134108. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 7, 2025

Datadog Report

All test runs dd062e9 🔗

2 Total Test Services: 0 Failed, 2 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.09%), 1 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-backend 0 0 0 21352 0 18m 43.81s 1 no change Link
judicial-system-web 0 0 0 333 0 57.8s 1 increased (+0.09%) Link

@oddsson oddsson marked this pull request as ready for review January 7, 2025 21:03
@oddsson oddsson requested a review from a team as a code owner January 7, 2025 21:03
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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a1bc3b and 02269b6.

📒 Files selected for processing (5)
  • apps/judicial-system/web/pages/api/lawyers/getLawyer/getLawyer.ts (0 hunks)
  • apps/judicial-system/web/pages/api/lawyers/getLawyer/index.ts (0 hunks)
  • apps/judicial-system/web/pages/api/lawyers/getLawyers/getLawyers.ts (0 hunks)
  • apps/judicial-system/web/pages/api/lawyers/getLawyers/index.ts (0 hunks)
  • apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts (2 hunks)
💤 Files with no reviewable changes (4)
  • apps/judicial-system/web/pages/api/lawyers/getLawyer/index.ts
  • apps/judicial-system/web/pages/api/lawyers/getLawyers/index.ts
  • apps/judicial-system/web/pages/api/lawyers/getLawyer/getLawyer.ts
  • apps/judicial-system/web/pages/api/lawyers/getLawyers/getLawyers.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.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 (2)
apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts (2)

13-14: LGTM! The API endpoint change is well implemented.

The updated endpoint aligns with the PR objectives, and the SWR configuration is appropriate for this use case.


Line range hint 1-52: Verify the impact of API endpoint changes.

The changes to the API endpoints might affect components using these hooks.

Let's verify the usage of these hooks and ensure all components are updated:

✅ Verification successful

API endpoint changes are properly encapsulated ✅

The changes to API endpoints are safely contained within the hooks implementation, with all components using these hooks correctly through proper imports. No direct usage of old API endpoints was found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using the old API endpoints
echo "Checking for old API endpoint usage..."
rg -l "api/lawyers/getLawyers\|api/lawyers/getLawyer" "apps/judicial-system/web/src/components"

# Search for components using these hooks
echo "Checking hook usage..."
rg -l "useGetLawyers\|useGetLawyer" "apps/judicial-system/web/src/components"

Length of output: 315


Script:

#!/bin/bash
# Search for any API endpoint patterns in the entire web directory
echo "Checking for API endpoint patterns..."
rg -l "api/lawyers|api/defender" "apps/judicial-system/web/src"

# Use ast-grep to find hook usage
echo "Checking hook usage with AST..."
ast-grep --pattern 'useGetLawyer($$$)' 
ast-grep --pattern 'useGetLawyers($$$)'

# Search for imports of these hooks
echo "Checking hook imports..."
rg -l "import.*useGetLawyer" "apps/judicial-system/web/src"

Length of output: 1334

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02269b6 and 73ac9ed.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.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 (3)
apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts (3)

20-21: API endpoint update looks good!

The endpoint change correctly implements the new lawyer registry path as specified in the PR objectives.


42-51: Remove duplicated fetcher implementation.

This fetcher implementation should be replaced with the shared implementation suggested above.


54-57: ⚠️ Potential issue

Add error handling to match useGetLawyers implementation.

The hook is missing error handling that exists in the useGetLawyers hook.

-  const { data } = useSWR<Lawyer>(
+  const { data, error } = useSWR<Lawyer>(
     nationalId && shouldFetch
       ? `/api/defender/lawyerRegistry/${nationalId}`
       : null,
     fetcher,
     {
       revalidateIfStale: false,
       revalidateOnFocus: false,
       revalidateOnReconnect: false,
       errorRetryCount: 2,
     },
   )

+  if (error) {
+    toast.error(formatMessage(errorMessages.fetchLawyer))
+    return undefined
+  }

   return data

Likely invalid or redundant comment.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 9, 2025
thorhildurt
thorhildurt previously approved these changes Jan 10, 2025
Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Looks good! Just left one nit 😇

@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 16, 2025
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

🧹 Nitpick comments (1)
apps/judicial-system/web/messages/Core/errors.ts (1)

97-102: LGTM with a minor suggestion for consistency.

The new error message is well-structured and aligns with the PR's goal of centralizing lawyer registry access. It complements the existing fetchLawyers message and follows the established patterns.

Consider using "við að" consistently in the defaultMessage. Other similar messages use this pattern:

-    defaultMessage: 'Upp kom villa við að sækja lögmann úr lögmanna skrá',
+    defaultMessage: 'Upp kom villa við að sækja lögmann frá lögmanna skrá',
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73ac9ed and b22a8b4.

📒 Files selected for processing (2)
  • apps/judicial-system/web/messages/Core/errors.ts (1 hunks)
  • apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/messages/Core/errors.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."

@oddsson oddsson dismissed stale reviews from thorhildurt and coderabbitai[bot] via c4576a2 January 16, 2025 15:43
@oddsson oddsson requested a review from thorhildurt January 17, 2025 08:45
@kodiakhq kodiakhq bot merged commit 4a71289 into main Jan 17, 2025
37 checks passed
@kodiakhq kodiakhq bot deleted the j-s/refactor-defender branch January 17, 2025 09:52
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.

2 participants