-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(j-s): Fix ServiceAnnouncement component for defenders #16840
Conversation
…e-announcement-defenders
…e-announcement-defenders
…e-announcement-defenders
…d-is/island.is into j-s/service-announcement-defenders
…e-announcement-defenders
…e-announcement-defenders
…to j-s/fix-served-bu
WalkthroughThe changes in this pull request involve modifications to several components within the judicial system application. Key updates include enhancements to the rendering logic and data handling in the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 (7)
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.strings.ts (1)
26-30
: LGTM! Consider adding English translations in descriptions.The new message definition follows the established pattern and aligns with the PR objective to show "Served electronically" instead of national ID. The message ID, default message, and description are consistent with other entries.
Consider adding English translations in the description to help non-Icelandic speaking developers:
servedToElectronically: { id: 'judicial.system.core:overview.served_electronically', defaultMessage: 'Rafrænt pósthólf island.is', - description: 'Notaður sem texti þegar birt var í pósthólfi.', + description: 'Notaður sem texti þegar birt var í pósthólfi. (EN: Used as text when served to electronic mailbox)', },apps/judicial-system/web/src/components/InfoCard/InfoCard.spec.tsx (2)
Line range hint
89-130
: Fix duplicate nested render calls in test caseThere's a critical structural issue where the
render
function is incorrectly nested within anotherrender
call. This will cause test failures.Apply this fix to remove the nested render:
test('should display the assigned defender name, email and phonenumber if that info is provided', async () => { // Arrange render( <MockedProvider> <LocaleProvider locale="is" messages={{}}> - render( - <MockedProvider> - <LocaleProvider locale="is" messages={{}}> <InfoCard sections={[ { id: 'sec_id', items: [ { id: 'itm_id', title: 'Titill', values: [ <DefendantInfo defendant={{ id: 'def_id', defenderName: 'Joe', defenderEmail: '[email protected]', defenderPhoneNumber: '455-5544', }} />, ], }, ], }, ]} /> - </LocaleProvider> - </MockedProvider> - , ) </LocaleProvider> </MockedProvider>, )
152-155
: Consider using translation keys instead of hardcoded stringsWhile the assertion logic is good, the test is using a hardcoded Icelandic string. Consider using the translation system for better maintainability and consistency.
Example approach:
expect( await screen.findByText( (_, element) => - element?.textContent === 'Verjandi: Hefur ekki verið skráður', + element?.textContent === messages.defender.notAssigned, ), ).toBeTruthy()This assumes you've defined the translation key in your messages object. You'll need to:
- Import the messages from your translation files
- Pass them to the LocaleProvider in the test setup
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (2)
78-87
: LGTM! Consider adding type assertions for better type safety.The new variables are well-structured and provide clear fallback handling. The code is readable and maintainable, which aligns with the team's preferences.
Consider adding type assertions to ensure type safety:
- const hasDefender = defendant.defenderName || defender?.name + const hasDefender = Boolean(defendant.defenderName || defender?.name)
Further
servedBy
usages detected that may display national IDs. Please update all instances to display "Served electronically":
apps/judicial-system/xrd-api/src/app/app.service.ts
apps/judicial-system/xrd-api/src/app/dto/subpoena.dto.ts
apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx
apps/judicial-system/api/src/app/modules/police/models/subpoenaStatus.model.ts
apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts
apps/judicial-system/backend/src/app/modules/police/police.service.ts
apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts
apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts
apps/judicial-system/backend/src/app/formatters/serviceCertificatePdf.ts
apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.strings.ts
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.strings.ts
🔗 Analysis chain
Line range hint
1-147
: Verify handling of servedBy field across the codebase.To ensure complete implementation of the PR objective (replacing national ID with "Served electronically"), let's verify all usages of the servedBy field.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining usage of servedBy field that might still display national IDs rg -g '*.{ts,tsx}' -A 3 'servedBy' # Search for translations or messages related to electronic service rg -g '*.strings.{ts,tsx}' -A 3 'electronic.*service|served.*electronic'Length of output: 7794
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (1)
71-80
: LGTM with a type safety enhancement suggestionThe function correctly implements the electronic service display logic while maintaining backwards compatibility. Good use of i18n for internationalization.
Consider adding type narrowing for better type safety:
const getMessage = ( servedBy?: string | null, serviceDate?: string | null, serviceStatus?: ServiceStatus | null, ): string => { const processServer = - serviceStatus === ServiceStatus.ELECTRONICALLY + serviceStatus && serviceStatus === ServiceStatus.ELECTRONICALLY ? formatMessage(strings.servedToElectronically) : servedByapps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (1)
Line range hint
1-450
: Consider adding JSDoc documentationGiven the complexity of this component (handling multiple states, transitions, and user roles), consider adding JSDoc documentation to describe:
- Component's purpose and responsibilities
- Key props and state management
- Available transitions and their conditions
- Modal types and their triggers
Example:
/** * Overview component for managing indictment cases. * * Handles: * - Case state transitions * - Document management * - Indictment confirmation/denial * - Case cancellation requests * * @component * @example * return ( * <Overview /> * ) */
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (5)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx
(2 hunks)apps/judicial-system/web/src/components/InfoCard/InfoCard.spec.tsx
(1 hunks)apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx
(1 hunks)apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.strings.ts
(1 hunks)apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.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/InfoCard/InfoCard.spec.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/Overview/Overview.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/Shared/IndictmentOverview/IndictmentOverview.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/Shared/IndictmentOverview/IndictmentOverview.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/components/InfoCard/DefendantInfo/DefendantInfo.tsx (4)
Learnt from: oddsson
PR: island-is/island.is#15461
File: apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx:36-62
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The user prefers readability over optimization in the `getAppealExpirationInfo` function within `DefendantInfo.tsx`.
Learnt from: oddsson
PR: island-is/island.is#15461
File: apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx:36-62
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The user prefers readability over optimization in the `getAppealExpirationInfo` function within `DefendantInfo.tsx`.
Learnt from: unakb
PR: island-is/island.is#14922
File: apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx:43-49
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The `getAppealExpirationInfo` function in `DefendantInfo.tsx` correctly uses `today < expiryDate` to determine if the current date is before the appeal expiration date.
Learnt from: unakb
PR: island-is/island.is#14922
File: apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx:43-49
Timestamp: 2024-11-12T15:15:26.274Z
Learning: The `getAppealExpirationInfo` function in `DefendantInfo.tsx` correctly uses `today < expiryDate` to determine if the current date is before the appeal expiration date.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (5)
Learnt from: oddsson
PR: island-is/island.is#16731
File: apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx:172-186
Timestamp: 2024-11-12T15:15:20.157Z
Learning: In `IndictmentOverview.tsx`, since the defendants data does not change, using `useMemo` to memoize the filtering logic is unnecessary.
Learnt from: unakb
PR: island-is/island.is#14712
File: apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentOverview.tsx:0-0
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The judicial system application uses a toaster notification system to handle errors globally.
Learnt from: unakb
PR: island-is/island.is#14712
File: apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/IndictmentOverview.tsx:0-0
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The judicial system application uses a toaster notification system to handle errors globally.
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-11-12T15:15:11.835Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-11-12T15:15:11.835Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
🔇 Additional comments (5)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx (1)
Line range hint 140-147
: LGTM! The conditional rendering is well-implemented.
The additional serviceRequirement check improves the rendering logic by ensuring the verdict view date is only shown when necessary. The implementation is type-safe and follows React best practices.
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (3)
41-41
: LGTM: Clean import addition
The ServiceStatus import is properly added and grouped with related schema types.
87-91
: LGTM: Clean props update
The AlertMessage component correctly implements the new serviceStatus parameter while maintaining the existing structure.
71-91
: Verify the presence of required translation strings
Let's ensure the required translation string is properly defined in the strings file.
✅ Verification successful
Required translation string 'servedToElectronically' is properly defined.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if the required translation string exists
# Expected: Find the servedToElectronically string definition
rg "servedToElectronically" --type ts
Length of output: 557
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (1)
228-228
: LGTM! Clean boolean prop syntax
The simplified boolean prop syntax follows modern React best practices.
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16840 +/- ##
=======================================
Coverage 36.44% 36.44%
=======================================
Files 6852 6852
Lines 143527 143471 -56
Branches 40961 40932 -29
=======================================
- Hits 52303 52289 -14
+ Misses 91224 91182 -42
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 7 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportBranch report: ✅ 0 Failed, 333 Passed, 0 Skipped, 1m 9.93s Total Time |
* Checkpoint * Refactor AlertMessage * Format date * Cleanup * Cleanup * Merge * Add key * Refactor * Remove console.log * Refactoring * Merge * Show to prosecutors * Fix tests * Handle served by electronically * Checkpoint * Remove console.log --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Guðjón Guðjónsson <[email protected]> Co-authored-by: unakb <[email protected]>
Fix ServiceAnnouncement component for defenders
Asana
What
We are now showing the service status to defenders. When a service is done electronically, servedBy is set to the nationalId of the defendant. This PR shows "Served electronically" message instead of that.
Why
It's a bug
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes
DefendantInfo
component to enhance specificity.Refactor