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): Rewrites Input Advocate #17471

Merged
merged 5 commits into from
Jan 16, 2025
Merged

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Jan 10, 2025

Rewrites Input Advocate

Rewrite advocate input
label - lögmaður eða réttargæslumaður kemur ekki rétt út

What

  • Rewrites input advocate component.
  • Fixes labels and placeholders when advocate is lawyer.

Why

  • Cleaner code and verified bug.

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 advocate information management with more granular input controls
    • Improved internationalization support for legal professional labels and placeholders
  • Bug Fixes

    • Streamlined update processes for defender and civil claimant information
    • Simplified input validation and state management for advocate details
  • Refactor

    • Centralized logic for sending updates to the server
    • Removed deprecated utility functions and simplified code structure
    • Updated type definitions for legal professionals
  • Chores

    • Removed unused internationalization strings and associated files

The changes focus on improving the user experience for managing legal professional information in the judicial system application.

@gudjong gudjong requested a review from a team as a code owner January 10, 2025 18:05
Copy link
Contributor

coderabbitai bot commented Jan 10, 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-nullish-coalescing-operator 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-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 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-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-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-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-async-generator-functions 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 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-4afdc3df-c525-4f5b-9a97-360b8c8f3fb3 > [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 introduces significant changes to the judicial system web application, focusing on refactoring and improving the handling of advocate information, particularly for defenders. The modifications span multiple components and utility files, streamlining the logic for updating case and advocate details, removing unused utility functions, and enhancing the internationalization approach for input fields related to legal professionals.

Changes

File Change Summary
apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.tsx Updated component with new methods for handling advocate changes and case updates, including refactored title generation and centralized update logic.
apps/judicial-system/web/src/components/Inputs/Input.strings.ts Completely removed internationalization strings file that contained labels and placeholders for input fields.
apps/judicial-system/web/src/components/Inputs/InputAdvocate.strings.ts New file with internationalized message strings for legal professional labels and placeholders.
apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx Significant modifications to advocate input component, adding new props and handlers for managing advocate details.
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx Introduced new interface for civil claimant updates and consolidated update logic for civil claimants.
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx Refactored component to streamline updates for defendants, replacing multiple functions with consolidated methods.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx Updated handling of civil claimants and defendants, introducing new interfaces and simplifying update processes.
apps/judicial-system/web/src/utils/formatters.ts Removed multiple utility functions, leaving only replaceTabs.
apps/judicial-system/web/src/utils/utils.spec.tsx Removed tests for deleted formatter utility functions.
libs/judicial-system/types/src/index.ts Modified type exports, removing AdvocateType from exports.
libs/judicial-system/types/src/lib/lawyer.ts Removed AdvocateType enum, simplifying advocate categorization.

Possibly related PRs

  • feat(j-s): Public defender staff overview after review #14848: The changes in the main PR regarding the DefenderInfo component and its handling of advocate information may relate to the updates in the DefendantInfo component from this PR, as both involve displaying and managing information related to legal representatives.
  • feat(j-s): Register verdict view date and appeal date for defendants #16495: The main PR's updates to the DefenderInfo component, particularly around verdict view dates and appeal deadlines, are relevant to the changes in this PR, which also deals with verdict appeal deadlines and their management in the context of defendants.
  • fix(j-s): Withdraw Indictment Case #16525: The modifications in the main PR regarding the handling of advocate information and case updates may connect with the changes in this PR, which focuses on updating the handling of indictment cases and their associated information.

Suggested labels

automerge

Suggested reviewers

  • 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 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
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 (10)
apps/judicial-system/web/src/components/Inputs/InputAdvocate.strings.ts (1)

4-23: Consider optimizing duplicate message IDs.

The same ID 'judicial.system.core:lawyer_input.defender' is used across different label types. Consider using unique IDs like 'lawyer_input.defender.name', 'lawyer_input.defender.email', etc., to prevent potential conflicts and improve maintainability.

 export const nameLabelStrings = defineMessages({
   defender: {
-    id: 'judicial.system.core:lawyer_input.defender',
+    id: 'judicial.system.core:lawyer_input.defender.name',
     defaultMessage: 'Nafn verjanda',
     description: 'Notaður sem titill á nafni fyrir verjanda.',
   },
   // ... similar changes for other message IDs
 })

Also applies to: 27-46, 50-69

apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx (2)

42-45: Enhance component documentation.

While the current documentation provides a basic overview, it could be improved by documenting:

  • The purpose of each prop
  • Validation rules
  • Error handling behavior

Line range hint 95-179: Consider extracting validation logic.

The email and phone number validation logic is duplicated across handlers. Consider extracting it into a custom hook or utility function.

// useInputValidation.ts
export const useInputValidation = (type: 'email' | 'phone') => {
  const [errorMessage, setErrorMessage] = useState<string>('')
  
  const handleChange = useCallback((value: string, onChange: (value: string | null) => void) => {
    const sanitized = replaceTabs(value)
    removeErrorMessageIfValid(
      [type === 'email' ? 'email-format' : 'phonenumber'],
      sanitized,
      errorMessage,
      setErrorMessage
    )
    onChange(sanitized || null)
  }, [errorMessage])
  
  const handleBlur = useCallback((value: string, onSave: (value: string | null) => void) => {
    const sanitized = replaceTabs(value)
    validateAndSetErrorMessage(
      [type === 'email' ? 'email-format' : 'phonenumber'],
      sanitized,
      setErrorMessage
    )
    onSave(sanitized || null)
  }, [])
  
  return { errorMessage, handleChange, handleBlur }
}
apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.tsx (2)

37-59: Consider simplifying title logic.

The nested if-else structure could be simplified using a lookup object.

const titleMessages = {
  restriction: {
    prosecution: defenderInfo.restrictionCases.sections.defender.heading,
    default: defenderInfo.restrictionCases.sections.defender.title,
  },
  investigation: {
    prosecution: defenderInfo.investigationCases.sections.defender.heading,
    default: defenderInfo.investigationCases.sections.defender.title,
  },
}

const getSectionTitle = () => {
  const caseType = isRestrictionCase(workingCase.type) ? 'restriction' : 'investigation'
  const userType = isProsecutionUser(user) ? 'prosecution' : 'default'
  const message = titleMessages[caseType][userType]
  
  return formatMessage(message, {
    defenderType: workingCase.sessionArrangements === SessionArrangements.ALL_PRESENT_SPOKESPERSON
      ? 'Talsmaður'
      : 'Verjandi',
  })
}

116-135: Consider memoizing callback props.

The inline callback props for email and phone number changes could benefit from memoization to prevent unnecessary rerenders.

const handleEmailChange = useCallback(
  (defenderEmail: string | null) => setWorkingCase((prev) => ({ ...prev, defenderEmail })),
  []
)

const handleEmailSave = useCallback(
  (defenderEmail: string | null) => updateCase(workingCase.id, { defenderEmail }),
  [workingCase.id, updateCase]
)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (2)

55-80: Consider simplifying the defender waiver logic.

While the implementation is thorough, the conditional assignments could be simplified using object spread and conditional operators.

Consider this more maintainable approach:

-  const update: UpdateDefendant = {
-    defendantId: defendant.id,
-    defenderNationalId: defendantWaivesRightToCounsel
-      ? null
-      : defendant.defenderNationalId || null,
-    defenderName: defendantWaivesRightToCounsel
-      ? null
-      : defendant.defenderName,
-    defenderEmail: defendantWaivesRightToCounsel
-      ? null
-      : defendant.defenderEmail,
-    defenderPhoneNumber: defendantWaivesRightToCounsel
-      ? null
-      : defendant.defenderPhoneNumber,
-    defenderChoice:
-      defendantWaivesRightToCounsel === true
-        ? DefenderChoice.WAIVE
-        : DefenderChoice.DELAY,
-  }
+  const update: UpdateDefendant = {
+    defendantId: defendant.id,
+    defenderChoice: defendantWaivesRightToCounsel ? DefenderChoice.WAIVE : DefenderChoice.DELAY,
+    ...(defendantWaivesRightToCounsel
+      ? {
+          defenderNationalId: null,
+          defenderName: null,
+          defenderEmail: null,
+          defenderPhoneNumber: null,
+        }
+      : {
+          defenderNationalId: defendant.defenderNationalId || null,
+          defenderName: defendant.defenderName,
+          defenderEmail: defendant.defenderEmail,
+          defenderPhoneNumber: defendant.defenderPhoneNumber,
+        }),
+  }

82-109: Enhance readability of defender choice logic.

The current implementation uses multiple boolean checks that could be made more explicit.

Consider extracting the choice determination logic into a separate function:

const determineDefenderChoice = (
  defenderName: string | null,
  currentChoice: DefenderChoice | null
): DefenderChoice => {
  if (!defenderName && (!currentChoice || currentChoice === DefenderChoice.CHOOSE)) {
    return DefenderChoice.DELAY
  }
  if (defenderName && (!currentChoice || currentChoice === DefenderChoice.DELAY)) {
    return DefenderChoice.CHOOSE
  }
  return currentChoice as DefenderChoice
}

Then use it in the main function:

-    const isDelaying =
-      !defenderName &&
-      (!defenderChoice || defenderChoice === DefenderChoice.CHOOSE)
-    const isChoosing =
-      defenderName &&
-      (!defenderChoice || defenderChoice === DefenderChoice.DELAY)
-
-    const defenderChoiceUpdate = isDelaying
-      ? DefenderChoice.DELAY
-      : isChoosing
-      ? DefenderChoice.CHOOSE
-      : defenderChoice
+    const defenderChoiceUpdate = determineDefenderChoice(defenderName, defenderChoice)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (1)

44-65: Consider adding error handling.

The handler functions are well-structured with clear responsibilities. However, consider adding error handling for server communication failures.

 const handleUpdateCivilClaimant = (update: UpdateCivilClaimant) => {
+  try {
     updateCivilClaimant({
       caseId: workingCase.id,
       civilClaimantId: civilClaimant.id,
       ...update,
     })
+  } catch (error) {
+    // Handle error appropriately
+    console.error('Failed to update civil claimant:', error)
+  }
 }
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (2)

146-210: Consider optimizing removeAllCivilClaimants.

While the implementation is correct, consider using Promise.all for parallel deletion of civil claimants:

 const removeAllCivilClaimants = () => {
   if (!workingCase.civilClaimants) {
     return
   }

-  for (const civilClaimant of workingCase.civilClaimants) {
-    removeCivilClaimantById(civilClaimant.id)
-  }
+  return Promise.all(
+    workingCase.civilClaimants.map((civilClaimant) =>
+      removeCivilClaimantById(civilClaimant.id)
+    )
+  )
 }

586-636: Consider extracting common advocate handling logic.

The implementation is correct but duplicates patterns seen in SelectCivilClaimantAdvocate.tsx. Consider extracting these patterns into a custom hook for reusability.

Example:

// useAdvocateHandlers.ts
export const useAdvocateHandlers = (
  civilClaimantId: string,
  handleUpdate: (update: any) => void
) => {
  const onEmailChange = useCallback(
    (email: string | null) => handleUpdate({ civilClaimantId, spokespersonEmail: email }),
    [civilClaimantId, handleUpdate]
  )
  // ... other handlers
  return { onEmailChange, ... }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between acfeb49 and e1a5fcd.

📒 Files selected for processing (11)
  • apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.tsx (7 hunks)
  • apps/judicial-system/web/src/components/Inputs/Input.strings.ts (0 hunks)
  • apps/judicial-system/web/src/components/Inputs/InputAdvocate.strings.ts (1 hunks)
  • apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx (4 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (7 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (18 hunks)
  • apps/judicial-system/web/src/utils/formatters.ts (0 hunks)
  • apps/judicial-system/web/src/utils/utils.spec.tsx (0 hunks)
  • libs/judicial-system/types/src/index.ts (1 hunks)
  • libs/judicial-system/types/src/lib/lawyer.ts (0 hunks)
💤 Files with no reviewable changes (4)
  • libs/judicial-system/types/src/lib/lawyer.ts
  • apps/judicial-system/web/src/components/Inputs/Input.strings.ts
  • apps/judicial-system/web/src/utils/utils.spec.tsx
  • apps/judicial-system/web/src/utils/formatters.ts
🧰 Additional context used
📓 Path-based instructions (7)
libs/judicial-system/types/src/index.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."
apps/judicial-system/web/src/components/Inputs/InputAdvocate.strings.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/web/src/routes/Court/Indictments/Advocates/SelectDefender.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/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.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/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.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/judicial-system/web/src/components/Inputs/InputAdvocate.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/judicial-system/web/src/components/DefenderInfo/DefenderInfo.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."
📓 Learnings (2)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (1)
Learnt from: unakb
PR: island-is/island.is#16393
File: apps/judicial-system/web/src/routes/Court/Indictments/Advocates/Advocates.tsx:62-79
Timestamp: 2024-11-12T15:15:11.835Z
Learning: When optional chaining is already used on `workingCase.defendants` in the `Advocates.tsx` component, avoid suggesting additional null checks as it's already handled.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (1)
Learnt from: gudjong
PR: island-is/island.is#15421
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx:55-61
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The `updateCase` method in the `apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx` file has its own error handling, and additional error handling in the `initialize` function is not necessary.
🔇 Additional comments (16)
libs/judicial-system/types/src/index.ts (1)

123-123: LGTM! Export path updated correctly.

The change from './lib/advocate' to './lib/lawyer' aligns with the refactoring of advocate-related types.

apps/judicial-system/web/src/components/Inputs/InputAdvocate.strings.ts (1)

3-24: LGTM! Well-structured i18n messages.

The message definitions follow react-intl best practices with clear IDs, default messages, and descriptions.

Also applies to: 26-47, 49-70, 72-88

apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx (2)

24-38: LGTM! Well-typed props interface.

The props interface clearly defines all required properties with appropriate TypeScript types.


Line range hint 183-234: LGTM! Clean render logic with proper i18n.

The render logic is well-structured with appropriate use of internationalized labels and error handling.

apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.tsx (2)

31-34: LGTM! Clean hook usage.

The component properly destructures the required hooks and manages state effectively.


92-109: LGTM! Well-structured update handlers.

The handlers are well-organized and properly handle the case updates.

apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectDefender.tsx (3)

23-23: LGTM! Clean interface definition.

The interface follows TypeScript best practices by extending and omitting specific fields.


40-53: Well-structured state management handlers!

The functions follow a clear separation of concerns:

  • handleUpdateDefendantState: Updates local state
  • handleUpdateDefendant: Updates without state refresh
  • handleSetAndSendDefendantToServer: Updates with state refresh

This pattern aligns with React best practices for state management.


158-200: Well-structured advocate input handling!

The InputAdvocate component implementation:

  • Uses strongly-typed callbacks
  • Separates concerns between immediate state updates and server synchronization
  • Properly handles all advocate data aspects (name, email, phone)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (4)

30-31: LGTM! Clean interface definition.

The interface properly extends the input type while omitting ID fields that are handled at a higher level.


36-40: LGTM! Clean hook usage.

The hook destructuring is well-organized and follows React best practices.


85-87: LGTM! Clean radio button handlers.

The handlers are consistent and properly manage the spokesperson type updates.

Also applies to: 101-103


113-145: LGTM! Well-structured input handling.

The InputAdvocate component props are well-organized with clear separation between immediate updates and save operations.

apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (3)

57-61: LGTM! Consistent interface definitions.

The interfaces follow the same pattern as in SelectCivilClaimantAdvocate.tsx, maintaining consistency across the codebase.


Line range hint 228-279: LGTM! Robust national ID handling.

The implementation properly handles various edge cases and integrates well with the person data lookup functionality.


Line range hint 324-359: LGTM! Consistent plea handling.

The plea handlers follow a consistent pattern and properly update the defendant's state.

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

codecov bot commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 3.37079% with 172 lines in your changes missing coverage. Please review.

Project coverage is 35.70%. Comparing base (3cb5441) to head (cdd8774).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/Prosecutor/Indictments/Processing/Processing.tsx 0.00% 53 Missing ⚠️
...tes/Court/Indictments/Advocates/SelectDefender.tsx 0.00% 45 Missing ⚠️
...system/web/src/components/Inputs/InputAdvocate.tsx 2.85% 34 Missing ⚠️
...ictments/Advocates/SelectCivilClaimantAdvocate.tsx 0.00% 21 Missing ⚠️
...m/web/src/components/DefenderInfo/DefenderInfo.tsx 0.00% 19 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17471      +/-   ##
==========================================
+ Coverage   35.60%   35.70%   +0.09%     
==========================================
  Files        7015     6977      -38     
  Lines      150385   149619     -766     
  Branches    43007    42710     -297     
==========================================
- Hits        53541    53417     -124     
+ Misses      96844    96202     -642     
Flag Coverage Δ
application-templates-new-primary-school ?
judicial-system-backend 55.80% <100.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...web/src/components/Inputs/InputAdvocate.strings.ts 100.00% <100.00%> (ø)
apps/judicial-system/web/src/utils/formatters.ts 100.00% <ø> (+4.16%) ⬆️
libs/judicial-system/types/src/index.ts 100.00% <100.00%> (ø)
libs/judicial-system/types/src/lib/lawyer.ts 50.00% <ø> (ø)
...m/web/src/components/DefenderInfo/DefenderInfo.tsx 1.85% <0.00%> (-0.38%) ⬇️
...ictments/Advocates/SelectCivilClaimantAdvocate.tsx 0.00% <0.00%> (ø)
...system/web/src/components/Inputs/InputAdvocate.tsx 1.96% <2.85%> (+1.26%) ⬆️
...tes/Court/Indictments/Advocates/SelectDefender.tsx 0.00% <0.00%> (ø)
...s/Prosecutor/Indictments/Processing/Processing.tsx 0.00% <0.00%> (ø)

... and 82 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 3cb5441...cdd8774. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 10, 2025

Datadog Report

All test runs 284bc8e 🔗

10 Total Test Services: 0 Failed, 10 Passed
🔻 Test Sessions change in coverage: 5 decreased, 1 increased (+0.28%), 100 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.44s 1 no change Link
api 0 0 0 4 0 2.73s 1 no change Link
application-api-files 0 0 0 2 0 4.74s 1 no change Link
application-core 0 0 0 97 0 18.94s 1 no change Link
application-system-api 0 0 0 46 0 2m 33.73s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 28.77s 1 no change Link
application-templates-accident-notification 0 0 0 140 0 16.96s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 11.31s 1 no change Link
application-templates-driving-license 0 0 0 13 0 14.61s 1 no change Link
application-templates-example-payment 0 0 0 2 0 10.11s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (5)

  • judicial-system-web - jest 32.35% (-0.1%) - Details
  • judicial-system-api - jest 21.33% (-0.1%) - Details
  • judicial-system-scheduler - jest 76.81% (-0.08%) - Details
  • judicial-system-xrd-api - jest 74.8% (-0.07%) - Details
  • judicial-system-formatters - jest 87.37% (-0.05%) - Details

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 few comments and nits ☺️

@gudjong gudjong requested a review from thorhildurt January 16, 2025 11:12
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 👍

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/src/components/DefenderInfo/DefenderInfo.tsx (1)

169-173: Consider reducing repetition in radio button handlers.

The force flag is repeated in multiple handlers. Consider extracting a helper function to reduce duplication.

+const handleRequestSharedWithDefender = (requestSharedWithDefender: RequestSharedWithDefender) => {
+  handleSetAndSendCaseToServer({
+    requestSharedWithDefender,
+    force: true,
+  })
+}

-onChange={() => {
-  handleSetAndSendCaseToServer({
-    requestSharedWithDefender: RequestSharedWithDefender.READY_FOR_COURT,
-    force: true,
-  })
-}}
+onChange={() => handleRequestSharedWithDefender(RequestSharedWithDefender.READY_FOR_COURT)}

Also applies to: 196-200, 223-227

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1a5fcd and c9f2dab.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.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."
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prepare
🔇 Additional comments (4)
apps/judicial-system/web/src/components/DefenderInfo/DefenderInfo.tsx (4)

2-2: LGTM! Clean import and hook updates.

The changes follow React and i18n best practices, with proper typing and hook usage.

Also applies to: 17-17, 31-31


39-62: Consider optimizing the conditional formatting logic.

The defenderType formatting is only needed for non-restriction cases when the user is not a prosecution user. Consider extracting this logic for better readability.

 } else {
   if (isProsecutionUser(user)) {
     return formatMessage(
       defenderInfo.investigationCases.sections.defender.heading,
     )
   } else {
+    const message = defenderInfo.investigationCases.sections.defender.title
+    const isSpokesperson = workingCase.sessionArrangements === SessionArrangements.ALL_PRESENT_SPOKESPERSON
+    return formatMessage(message, {
+      defenderType: isSpokesperson ? 'Talsmaður' : 'Verjandi',
+    })
-    return formatMessage(
-      defenderInfo.investigationCases.sections.defender.title,
-      {
-        defenderType:
-          workingCase.sessionArrangements ===
-          SessionArrangements.ALL_PRESENT_SPOKESPERSON
-            ? 'Talsmaður'
-            : 'Verjandi',
-      },
-    )
   }
 }

97-114: LGTM! Well-structured handler functions.

The handlers effectively centralize the update logic and properly handle the force flag for autofill scenarios.


121-140: LGTM! Well-structured component props.

The InputAdvocate component now has:

  • Clear separation between local state updates and server persistence
  • Type-safe props with meaningful names
  • Granular control over individual fields

@gudjong gudjong added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 16, 2025
@oddsson oddsson added deprecated:automerge (Disabled) Merge this PR as soon as all checks pass and removed deprecated:automerge (Disabled) Merge this PR as soon as all checks pass labels Jan 16, 2025
@brynjarorng brynjarorng merged commit 58b89c1 into main Jan 16, 2025
112 of 113 checks passed
@brynjarorng brynjarorng deleted the j-s/rewrite-input-advocate branch January 16, 2025 16:01
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.

4 participants