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): Make a gendered version of the subpoena pdf #16413

Merged
merged 10 commits into from
Oct 16, 2024

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Oct 15, 2024

Make a gendered version of the subpoena pdf

Asana

What

Make a gendered version of the subpoena pdf

Why

The defendant can either be male, female or non-binary and that needs to be reflected in the PDF

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 PDF generation to include gender-specific introductory messages for subpoenas.
    • Added localization support for various gender identities in subpoena messages.
  • Bug Fixes

    • Removed outdated accused message definition to streamline message handling.
  • Refactor

    • Updated existing functions to utilize new gender handling logic for dynamic content generation.
  • Documentation

    • Introduced new message definitions for female and non-binary defendants, ensuring tailored communication.

@oddsson oddsson requested a review from a team as a code owner October 15, 2024 22:31
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes primarily enhance the handling of gender-specific content in the PDF generation process within the judicial system application. A new function, getIntro, is introduced to dynamically generate introductory text based on the defendant's gender. The pdfCore.ts file removes the accused message definition, while pdfSubpoena.ts adds multiple new message definitions for female and non-binary defendants. Additionally, a new enumeration Word and a function getWordByGender are introduced in formatters.ts to support gender-specific word formatting.

Changes

File Path Change Summary
apps/judicial-system/backend/src/app/formatters/... - Added getIntro function for gender-specific introductory text.
- Updated createSubpoena to use getIntro.
- Modified import statements to include new dependencies.
apps/judicial-system/backend/src/app/messages/... - Added new messages for female and non-binary defendants in subpoena object.
apps/judicial-system/backend/src/app/messages/... - Removed accused message from core object.
libs/judicial-system/formatters/src/lib/formatters.ts - Introduced Word enum and getWordByGender function for gender-specific word formatting.

Possibly related PRs

Suggested reviewers

  • unakb
  • oddsson

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 (1)
libs/judicial-system/formatters/src/lib/formatters.ts (1)

430-441: LGTM: New function getWordByGender added with a minor suggestion

The new function getWordByGender is well-implemented and follows TypeScript standards. It's exported, making it reusable across different NextJS apps, which aligns with the coding guidelines for libs.

Suggestion for improvement:
Consider handling unknown Word cases more explicitly. Instead of returning null, you could throw an error or return a default value. This would make the function's behavior more predictable and easier to use.

Example:

default:
  throw new Error(`Unknown word: ${word}`);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7a37f44 and 633abbc.

📒 Files selected for processing (4)
  • apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (5 hunks)
  • apps/judicial-system/backend/src/app/messages/pdfCore.ts (0 hunks)
  • apps/judicial-system/backend/src/app/messages/pdfSubpoena.ts (1 hunks)
  • libs/judicial-system/formatters/src/lib/formatters.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/judicial-system/backend/src/app/messages/pdfCore.ts
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/backend/src/app/formatters/subpoenaPdf.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/judicial-system/backend/src/app/messages/pdfSubpoena.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."
libs/judicial-system/formatters/src/lib/formatters.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 (8)
apps/judicial-system/backend/src/app/messages/pdfSubpoena.ts (4)

36-41: LGTM: Non-binary introduction message

The intro_non_binary message is well-defined and consistent with the PR objectives. It appropriately adapts the language for non-binary individuals.


48-54: LGTM: Female arrest introduction message

The arrestIntroFemale message is well-defined and consistent with the PR objectives. It appropriately adapts the language for female individuals in the context of arrest warnings.


68-74: LGTM: Female absence introduction message

The absenceIntroFemale message is well-defined and consistent with the PR objectives. It appropriately adapts the language for female individuals in the context of absence warnings.


30-81: Overall assessment: Gendered subpoena messages implementation

The changes successfully implement gendered versions of the subpoena messages, addressing the PR objective of creating a more inclusive PDF that accommodates male, female, and non-binary defendants. The new message definitions are well-structured and consistent with the existing codebase.

Key points:

  1. Appropriate message IDs have been created for female and non-binary versions.
  2. The content of the messages has been correctly adapted for different gender identities.
  3. The changes maintain consistency with the original messages while providing gender-specific language.

Please address the minor issues mentioned in the previous comments:

  1. Fix the typo in the intro_female message ID.
  2. Correct the descriptions for non-binary messages that incorrectly refer to female individuals.
  3. Verify the usage of "háns" instead of "hánar" in the non-binary absence message.

Once these issues are resolved, the implementation will fully meet the PR objectives and provide a more inclusive experience for all defendants.

libs/judicial-system/formatters/src/lib/formatters.ts (2)

426-429: LGTM: New enum Word added

The new enum Word is well-defined and follows TypeScript naming conventions. It's exported, making it reusable across different NextJS apps, which aligns with the coding guidelines for libs.


426-441: Summary: Enhancements for gender-specific word formatting

The additions to this file (enum Word and function getWordByGender) provide a robust mechanism for handling gender-specific word formatting in the judicial system. These changes:

  1. Improve reusability across different NextJS apps.
  2. Use TypeScript effectively for type safety.
  3. Enhance the flexibility of the formatters library.

These enhancements align well with the coding guidelines for libs and contribute to a more inclusive language handling in the judicial system application.

apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (2)

32-54: Ensure default gender handling aligns with requirements

Currently, when the gender is undefined, the default case returns the non-binary introductions. Please verify that this behavior aligns with the application's requirements. If not, consider specifying a default behavior or handling undefined cases appropriately.


142-149: Defaulting to Gender.MALE may not be appropriate when defendant.gender is undefined

The expression defendant.gender || Gender.MALE will default to Gender.MALE when defendant.gender is undefined. Please verify that defaulting to male is the intended behavior. If not, consider handling undefined gender differently to ensure correct gender-specific wording.

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 18.51852% with 22 lines in your changes missing coverage. Please review.

Project coverage is 36.73%. Comparing base (f7773d8) to head (c613301).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...l-system/backend/src/app/formatters/subpoenaPdf.ts 13.33% 13 Missing ⚠️
...s/judicial-system/formatters/src/lib/formatters.ts 25.00% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16413   +/-   ##
=======================================
  Coverage   36.72%   36.73%           
=======================================
  Files        6809     6809           
  Lines      141141   141120   -21     
  Branches    40236    40235    -1     
=======================================
+ Hits        51840    51844    +4     
+ Misses      89301    89276   -25     
Flag Coverage Δ
judicial-system-api 18.36% <ø> (ø)
judicial-system-backend 55.15% <18.51%> (-0.05%) ⬇️
judicial-system-formatters 79.25% <25.00%> (-0.75%) ⬇️
judicial-system-web 27.91% <10.00%> (-0.02%) ⬇️

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

Files with missing lines Coverage Δ
...udicial-system/backend/src/app/messages/pdfCore.ts 100.00% <ø> (ø)
...ial-system/backend/src/app/messages/pdfSubpoena.ts 100.00% <ø> (ø)
...s/judicial-system/formatters/src/lib/formatters.ts 76.73% <25.00%> (-3.27%) ⬇️
...l-system/backend/src/app/formatters/subpoenaPdf.ts 10.81% <13.33%> (-0.13%) ⬇️

... and 3 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 f7773d8...c613301. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 15, 2024

Datadog Report

All test runs bfe42a7 🔗

9 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 3 decreased, 9 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 2.69s 1 no change Link
application-system-api 0 0 0 120 2 3m 49.74s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 23.82s 1 no change Link
judicial-system-api 0 0 0 57 0 6.15s 1 no change Link
judicial-system-backend 0 0 0 21239 0 18m 31.65s 1 decreased (-0.02%) Link
judicial-system-formatters 0 0 0 38 0 5.25s 1 decreased (-0.3%) Link
judicial-system-web 0 0 0 338 0 1m 8.78s 1 no change Link
judicial-system-xrd-api 0 0 0 6 0 5.05s 1 decreased (-0.12%) Link
services-endorsements-api 0 0 0 42 0 44.44s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • judicial-system-formatters - jest 87.87% (-0.3%) - Details
  • judicial-system-xrd-api - jest 74.31% (-0.12%) - Details
  • judicial-system-backend - jest 58.58% (-0.02%) - Details

@gudjong gudjong added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 16, 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 (1)
apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (1)

33-61: Consider adding unit tests for getIntro function

The getIntro function is central to generating gender-specific content in subpoenas. To ensure accuracy and prevent regressions, consider adding unit tests that cover all possible gender values (MALE, FEMALE, NON_BINARY, and undefined) and verify that the correct messages are returned in each case.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 633abbc and 69db6d6.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (5 hunks)
  • apps/judicial-system/backend/src/app/messages/pdfSubpoena.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/judicial-system/backend/src/app/messages/pdfSubpoena.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/formatters/subpoenaPdf.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."

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 and nitpick comments (2)
apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (1)

33-61: LGTM: getIntro function implements gender-specific content effectively

The getIntro function is well-implemented, using TypeScript features and providing a clear way to handle different genders. It aligns with the PR objectives by ensuring inclusivity.

For improved type safety, consider using a union type for the return value:

type IntroMessages = {
  intro: MessageDescriptor
  absenceIntro: MessageDescriptor
  arrestIntro: MessageDescriptor
}

const getIntro = (gender?: Gender): IntroMessages => {
  // ... existing implementation ...
}

This change would make the return type more explicit and reusable.

libs/judicial-system/formatters/src/lib/formatters.ts (1)

430-441: LGTM with suggestions: New function getWordByGender added

The new getWordByGender function is well-implemented and follows TypeScript conventions. It's exported for reuse across different NextJS apps, aligning with the coding guidelines for libs. However, consider the following suggestions for improvement:

  1. Use a type union instead of enum for Word to improve type safety:

    export type Word = 'AKAERDI';
  2. Use an object lookup instead of a switch statement for better extensibility:

    const wordMap: Record<Word, Record<Gender, string>> = {
      AKAERDI: {
        [Gender.MALE]: 'ákærði',
        [Gender.FEMALE]: 'ákærða',
        [Gender.OTHER]: 'ákært',
      },
    };
    
    export const getWordByGender = (word: Word, gender: Gender = Gender.OTHER): string =>
      wordMap[word][gender];

These changes would make the code more maintainable and easier to extend in the future.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 69db6d6 and c613301.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (5 hunks)
  • libs/judicial-system/formatters/src/lib/formatters.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/judicial-system/backend/src/app/formatters/subpoenaPdf.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."
libs/judicial-system/formatters/src/lib/formatters.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)
apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (5)

2-2: LGTM: Import statements updated correctly

The new import statements are appropriate for the implemented gender-specific functionality. They follow TypeScript best practices by importing specific types and functions, which aligns with the PR objectives.

Also applies to: 7-7, 10-10, 12-12, 14-14


85-85: LGTM: Gender-specific intro correctly integrated

The integration of the getIntro function with the defendant's gender is implemented correctly, ensuring that the appropriate gender-specific introductory messages are used in the subpoena creation process.


149-154: LGTM: Gender-specific accused title implemented correctly

The use of getWordByGender and capitalize functions to generate a gender-specific and properly capitalized word for "Accused" is well-implemented. This change enhances the document's gender-specificity, aligning with the PR objectives.


180-180: LGTM: Gender-specific introductory messages implemented correctly

The use of the intro object to retrieve gender-specific introductory messages is implemented correctly. This change ensures that the subpoena document uses appropriate gender-specific language throughout, consistent with the PR objectives.

Also applies to: 187-188


Line range hint 1-208: Overall assessment: Well-implemented gender-specific subpoena generation

The changes in this file effectively implement gender-specific content for subpoena PDF generation, aligning well with the PR objectives. The code adheres to TypeScript and NextJS best practices, and the implementation is inclusive and maintainable.

Key improvements:

  1. Introduction of the getIntro function for gender-specific message selection.
  2. Integration of gender-specific content throughout the subpoena creation process.
  3. Proper use of TypeScript features and imported functions for improved code quality.

The suggested minor improvements, if implemented, would further enhance type safety and code clarity. Great job on creating a more inclusive document generation process!

libs/judicial-system/formatters/src/lib/formatters.ts (2)

426-429: LGTM: New enum Word added

The new Word enum is well-defined and follows TypeScript naming conventions. It's exported, allowing for reuse across different NextJS apps, which aligns with the coding guidelines for libs.


426-441: Summary: Changes align with coding guidelines

The additions to this file (enum Word and function getWordByGender) adhere to the coding guidelines for libs/**/*:

  1. They are reusable across different NextJS apps.
  2. TypeScript is used for defining types and exporting them.
  3. The code is structured to allow effective tree-shaking and bundling.

These changes enhance the gender-specific word formatting capabilities of the judicial system formatters library.

@kodiakhq kodiakhq bot merged commit 775afb3 into main Oct 16, 2024
43 checks passed
@kodiakhq kodiakhq bot deleted the j-s/gendered-subpoena branch October 16, 2024 13:58
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