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

feat(api): add extraxt strings for api law and order #16853

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

disaerna
Copy link
Member

@disaerna disaerna commented Nov 13, 2024

Api - Law and order

What

  • Add extract strings command to add translations messages to contenful
  • Rename subpoena to summon

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 new target for extracting localization strings, enhancing internationalization capabilities.
    • Added a new file for defining internationalized messages related to legal summons.
  • Bug Fixes

    • Updated terminology from "subpoena" to "summon" across various components, ensuring consistency in messaging and functionality.
  • Documentation

    • Enhanced localization by replacing hardcoded messages with references to a centralized message management system.

@disaerna disaerna requested a review from a team as a code owner November 13, 2024 14:38
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes in this pull request introduce a new target called extract-strings in the project configuration for the api-domains-law-and-order library, facilitating the extraction of localization strings. Additionally, multiple functions and variables related to "subpoena" have been renamed to "summon" across various files, including service and resolver classes. The localization of messages has been improved by referencing a new messages.ts file, which defines internationalized messages for legal actions. These modifications enhance the project's internationalization capabilities and align terminology with updated legal contexts.

Changes

File Path Change Summary
libs/api/domains/law-and-order/project.json Added a new target extract-strings using nx:run-commands to extract localization strings from a specified messages file.
libs/api/domains/law-and-order/src/lib/helpers/mappers.ts Renamed functions from "Subpoena" to "Summon" and updated DefenseChoices to use localized messages instead of hardcoded strings.
libs/api/domains/law-and-order/src/lib/law-and-order.resolver.ts Updated import from Subpoena model to Summon model and modified the getSubpoena method to getSummon in the LawAndOrderResolver class.
libs/api/domains/law-and-order/src/lib/law-and-order.service.ts Renamed methods and variables from "subpoena" to "summon" throughout the LawAndOrderService, including getSubpoena to getSummon and patchSubpoena to patchSummon.
libs/api/domains/law-and-order/src/lib/messages.ts Introduced a new file defining internationalized messages related to legal summons using react-intl.
libs/clients/judicial-system-sp/src/lib/judicialSystemSPClient.service.ts Renamed methods from "subpoena" to "summon" in the JudicialSystemSPClientService, including getSubpoena to getSummon and patchSubpoena to patchSummon.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • oddsson
  • unakb

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

🧹 Outside diff range and nitpick comments (6)
libs/api/domains/law-and-order/project.json (1)

28-32: Consider improving the extract-strings target configuration.

While the basic structure is good, consider these improvements for better maintainability:

  1. Define outputs for proper Nx caching
  2. Use variables for paths to avoid hardcoding
  3. Add error handling for the extraction process
 "extract-strings": {
   "executor": "nx:run-commands",
   "options": {
-    "command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/api/domains/law-and-order/src/lib/messages.ts'"
+    "command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/api/domains/law-and-order/src/lib/messages.ts' || exit 1"
+  },
+  "outputs": [
+    "{projectRoot}/src/lib/extracted-messages"
   }
 }
libs/api/domains/law-and-order/src/lib/messages.ts (2)

1-3: Consider improving type safety and documentation

The current implementation could benefit from:

  1. A more descriptive export name than 'm' (e.g., lawAndOrderMessages)
  2. TypeScript type definitions
  3. JSDoc documentation for better reusability
 import { defineMessages } from 'react-intl'

-export const m = defineMessages({
+/**
+ * Internationalized messages for law and order domain
+ * @description Contains messages related to summons and legal representation choices
+ */
+export const lawAndOrderMessages = defineMessages({

24-41: Add descriptions for translators

The legal choice messages would benefit from descriptions to provide context for translators, especially for legal terminology.

   waiveMessage: {
     id: 'api.law-and-order:no-defender',
+    description: 'Option shown when defendant chooses to waive their right to a defender',
     defaultMessage: 'Ég óska ekki eftir verjanda',
   },
   chooseMessage: {
     id: 'api.law-and-order:choosing-lawyer',
+    description: 'Option shown when defendant wants to choose their own lawyer as defender',
     defaultMessage:
       'Ég óska þess að valinn lögmaður verði skipaður verjandi minn',
   },
libs/clients/judicial-system-sp/src/lib/judicialSystemSPClient.service.ts (1)

Rename getSummon to getSubpoena for naming consistency
The method getSummon does not align with the widespread usage of subpoena in the codebase, which may cause confusion and maintenance challenges.

  • File: libs/clients/judicial-system-sp/src/lib/judicialSystemSPClient.service.ts
  • Method: getSummon
🔗 Analysis chain

Line range hint 49-56: Verify naming consistency between method and API endpoint

The method name getSummon doesn't match the underlying API endpoint name caseControllerGetSubpoena. This inconsistency could cause confusion for future maintenance.

Let's check if this is part of a broader renaming pattern:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of subpoena/summon to verify naming consistency
echo "Searching for subpoena references:"
rg -i "subpoena" --type ts

echo -e "\nSearching for summon references:"
rg -i "summon" --type ts

Length of output: 554


Script:

#!/bin/bash
# Search for type declarations and method names containing 'Subpoena' or 'Summon'
echo "Searching for type declarations with 'Subpoena' or 'Summon':"
rg -i -e "type.*Subpoena" -e "type.*Summon" --type ts

echo -e "\nSearching for method names with 'Subpoena' or 'Summon':"
rg -i -e "function.*Subpoena" -e "function.*Summon" --type ts

echo -e "\nSearching for class names with 'Subpoena' or 'Summon':"
rg -i -e "class.*Subpoena" -e "class.*Summon" --type ts

Length of output: 12067

libs/api/domains/law-and-order/src/lib/helpers/mappers.ts (1)

Line range hint 115-127: Consider consistent message handling for all choices

While most choices now use imported messages, the DELEGATE choice still uses a hardcoded message. Consider moving this message to the messages module for consistency and easier maintenance.

  DELEGATE: {
-   message: {
-     id: 'api.law-and-order:choose-for-me',
-     defaultMessage: 'Ég fel dómara málsins að tilnefna og skipa mér verjanda',
-   },
+   message: m.delegateMessage,
  },
libs/api/domains/law-and-order/src/lib/law-and-order.service.ts (1)

94-94: Handle case sensitivity appropriately when matching strings

The use of toLowerCase() on both item.label and summonString works for case-insensitive comparison. However, be cautious with localization, as case handling might differ in some locales. Consider using locale-aware string comparison if necessary.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2401e53 and b2f6a80.

📒 Files selected for processing (6)
  • libs/api/domains/law-and-order/project.json (1 hunks)
  • libs/api/domains/law-and-order/src/lib/helpers/mappers.ts (4 hunks)
  • libs/api/domains/law-and-order/src/lib/law-and-order.resolver.ts (2 hunks)
  • libs/api/domains/law-and-order/src/lib/law-and-order.service.ts (5 hunks)
  • libs/api/domains/law-and-order/src/lib/messages.ts (1 hunks)
  • libs/clients/judicial-system-sp/src/lib/judicialSystemSPClient.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
libs/api/domains/law-and-order/project.json (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/api/domains/law-and-order/src/lib/helpers/mappers.ts (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/api/domains/law-and-order/src/lib/law-and-order.resolver.ts (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/api/domains/law-and-order/src/lib/law-and-order.service.ts (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/api/domains/law-and-order/src/lib/messages.ts (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/clients/judicial-system-sp/src/lib/judicialSystemSPClient.service.ts (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 (7)
libs/clients/judicial-system-sp/src/lib/judicialSystemSPClient.service.ts (2)

Line range hint 1-62: Overall structure follows best practices

The service implementation follows good practices:

  • Proper dependency injection
  • Consistent error handling with middleware
  • Clear separation of concerns
  • Type-safe implementation

Line range hint 58-62: Consider updating type definitions to match new terminology

While the method has been renamed to patchSummon, it still uses CaseControllerUpdateSubpoenaRequest type and caseControllerUpdateSubpoena endpoint. Consider:

  1. Creating new types with updated terminology
  2. Deprecating old types if backward compatibility is needed

Let's check the type definitions and their usage:

#!/bin/bash
# Search for type definitions and their usage
echo "Searching for SubpoenaRequest type usage:"
rg "CaseControllerUpdateSubpoenaRequest" --type ts

echo -e "\nChecking generated API types:"
fd "fetch/index.ts" --exec cat {} \; | grep -A 5 "export.*Subpoena"
libs/api/domains/law-and-order/src/lib/helpers/mappers.ts (2)

9-9: LGTM: Clean import of messages module

The addition of the messages import follows good tree-shaking practices and aligns with the PR's objective of improving string extraction for translations.


Line range hint 1-127: Well-structured TypeScript implementation

The implementation demonstrates good practices:

  • Strong typing with proper interfaces and enums
  • Pure mapping functions that are easily reusable
  • Clear separation of concerns
libs/api/domains/law-and-order/src/lib/law-and-order.service.ts (3)

136-138: Ensure mapping functions handle all defense choices

You're using mapDefenseChoiceForSummon and mapDefenseChoiceForSummonDefaultChoice. Confirm that these functions correctly map all possible defense choices and have been updated to reflect any changes in the defense choice enumeration.


65-69: Verify localization keys in messages.ts

The variables summonString, seeSummonString, seeSummonInMailboxString, mailboxLink, and summonLink are using localization messages from m. Ensure that the corresponding keys (m.summon, m.seeSummon, etc.) are defined in messages.ts and accurately translated.


23-24: Confirm the implementation of new mapping functions

You've imported mapDefenseChoiceForSummon and mapDefenseChoiceForSummonDefaultChoice. Ensure these new functions are properly implemented in helpers/mappers.ts and handle all necessary cases for the summon process.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.59%. Comparing base (1c95866) to head (f093ed1).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16853   +/-   ##
=======================================
  Coverage   35.59%   35.59%           
=======================================
  Files        6920     6920           
  Lines      146139   146139           
  Branches    41512    41512           
=======================================
  Hits        52021    52021           
  Misses      94118    94118           
Flag Coverage Δ
api 3.34% <ø> (ø)

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 1c95866...f093ed1. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 13, 2024

Datadog Report

Branch report: my-pages/fix-law-and-order-strings
Commit report: 3658ddf
Test service: api

✅ 0 Failed, 4 Passed, 0 Skipped, 3.24s Total Time
➡️ Test Sessions change in coverage: 1 no change

@disaerna disaerna added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 21, 2024
@kodiakhq kodiakhq bot removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 21, 2024
Copy link
Contributor

kodiakhq bot commented Nov 21, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

LGTM

@disaerna disaerna added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 22, 2024
@kodiakhq kodiakhq bot removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 22, 2024
Copy link
Contributor

kodiakhq bot commented Nov 22, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

@disaerna disaerna added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 25, 2024
@kodiakhq kodiakhq bot merged commit cd5a0ac into main Nov 25, 2024
44 checks passed
@kodiakhq kodiakhq bot deleted the my-pages/fix-law-and-order-strings branch November 25, 2024 09:26
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