From 1e673255ebc7d7ed76618fe21ca4ec6105da0673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 12:39:38 +0000 Subject: [PATCH 01/68] Add frontend changes for selecting indictment subtypes in indictment count --- .../Indictments/Indictment/Indictment.tsx | 2 +- .../Indictment/IndictmentCount.css.ts | 14 +++++++ .../Indictment/IndictmentCount.strings.ts | 5 +++ .../Indictment/IndictmentCount.tsx | 41 ++++++++++++++++++- libs/judicial-system/types/src/lib/case.ts | 5 ++- 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx index 135bb7a57348..e30f6bd64f9a 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx @@ -380,7 +380,7 @@ const Indictment = () => { onChange={handleUpdateIndictmentCount} setWorkingCase={setWorkingCase} updateIndictmentCountState={updateIndictmentCountState} - > + /> diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts new file mode 100644 index 000000000000..7db43bb9be27 --- /dev/null +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts @@ -0,0 +1,14 @@ +import { style } from '@vanilla-extract/css' + +import { theme } from '@island.is/island-ui/theme' + +export const indictmentSubtypesContainter = style({ + display: 'flex', + flexWrap: 'wrap', + gap: theme.spacing[1], + marginBottom: theme.spacing[2], +}) + +export const indictmentSubtypesItem = style({ + flex: `1 1 calc(50% - ${theme.spacing[1]}px)`, +}) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts index dcea457a39c5..d6b7abe87aff 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts @@ -141,4 +141,9 @@ export const indictmentCount = defineMessages({ 'Telst háttsemi þessi varða við {articles} umferðarlaga nr. 77/2019.', description: 'Notaður sem sjálfgefinn texti í heimfærslu svæði.', }, + selectIndictmentSubtype: { + id: 'judicial.system.core:indictments_indictment.indictment_count.select_indictment_subtype', + defaultMessage: 'Veldu sakarefni', + description: 'Notaður sem titill fyrir "Veldu sakarefni" svæði.', + }, }) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 995eb38f5d4c..a578e012448e 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -5,14 +5,20 @@ import { IntlShape, useIntl } from 'react-intl' import { Box, Button, + Checkbox, Icon, Input, Select, Tag, } from '@island.is/island-ui/core' -import { formatDate } from '@island.is/judicial-system/formatters' +import { + capitalize, + formatDate, + indictmentSubtypes, +} from '@island.is/judicial-system/formatters' import { CrimeScene, + IndictmentSubtype, offenseSubstances, Substance, SubstanceMap, @@ -20,6 +26,7 @@ import { import { BlueBox, IndictmentInfo, + SectionHeading, } from '@island.is/judicial-system-web/src/components' import { IndictmentCountOffense } from '@island.is/judicial-system-web/src/graphql/schema' import { @@ -39,6 +46,7 @@ import { Substances as SubstanceChoices } from './Substances/Substances' import { indictmentCount as strings } from './IndictmentCount.strings' import { indictmentCountEnum as enumStrings } from './IndictmentCountEnum.strings' import { indictmentCountSubstanceEnum as substanceStrings } from './IndictmentCountSubstanceEnum.strings' +import * as styles from './IndictmentCount.css' interface Props { indictmentCount: TIndictmentCount @@ -449,6 +457,37 @@ export const IndictmentCount: FC = ({ crimeScenes={workingCase.crimeScenes} /> + + +
+ {indictmentCount.policeCaseNumber && + workingCase.indictmentSubtypes[ + indictmentCount.policeCaseNumber + ].map((subtype: IndictmentSubtype) => ( +
+ { + // handleUpdateCivilClaimant({ + // caseId: workingCase.id, + // civilClaimantId: civilClaimant.id, + // nationalId: null, + // noNationalId: !civilClaimant.noNationalId, + // }) + // }} + backgroundColor="white" + large + filled + /> +
+ ))} +
+
0 && flatIndictmentSubtypes.every( - (val) => val === IndictmentSubtype.TRAFFIC_VIOLATION, + (val) => + val === IndictmentSubtype.TRAFFIC_VIOLATION || + // TODO: Refactor this + val === IndictmentSubtype.NARCOTICS_OFFENSE, ) ) } From adf5ded3009ac64ceee7e334151eac1ae3541365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 12:57:00 +0000 Subject: [PATCH 02/68] Create migration --- .../20241204124025-update-indictment-count.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js diff --git a/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js b/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js new file mode 100644 index 000000000000..bba95e9361aa --- /dev/null +++ b/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js @@ -0,0 +1,22 @@ +'use strict' + +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.sequelize.transaction((transaction) => + queryInterface.addColumn( + 'indictment_count', + 'indictment_count_subtype', + { + type: Sequelize.ARRAY(Sequelize.STRING), + allowNull: true, + defaultValue: [], + }, + { transaction }, + ), + ) + }, + + async down(queryInterface) { + await queryInterface.removeColumn('indictment_count', 'indictment_count_subtypes') + }, +} From 94e59f33cbf152dc882f6f0ea45c6a1231c37836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 13:49:36 +0000 Subject: [PATCH 03/68] Update DB on change --- .../dto/updateIndictmentCount.input.ts | 12 +++- .../models/indictmentCount.model.ts | 9 ++- .../20241204124025-update-indictment-count.js | 2 +- .../dto/updateIndictmentCount.dto.ts | 11 +++- .../models/indictmentCount.model.ts | 13 ++++- .../src/components/FormProvider/case.graphql | 1 + .../Indictment/IndictmentCount.tsx | 56 ++++++++++++------- .../utils/hooks/useIndictmentCounts/index.ts | 6 +- .../updateIndictmentCount.graphql | 1 + 9 files changed, 84 insertions(+), 27 deletions(-) diff --git a/apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts b/apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts index d4d05cedb578..7e26e223a6b6 100644 --- a/apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts +++ b/apps/judicial-system/api/src/app/modules/indictment-count/dto/updateIndictmentCount.input.ts @@ -4,7 +4,10 @@ import { GraphQLJSONObject } from 'graphql-type-json' import { Field, ID, InputType } from '@nestjs/graphql' import type { SubstanceMap } from '@island.is/judicial-system/types' -import { IndictmentCountOffense } from '@island.is/judicial-system/types' +import { + IndictmentCountOffense, + IndictmentSubtype, +} from '@island.is/judicial-system/types' @InputType() export class UpdateIndictmentCountInput { @@ -53,4 +56,11 @@ export class UpdateIndictmentCountInput { @IsOptional() @Field(() => String, { nullable: true }) readonly legalArguments?: string + + @Allow() + @IsOptional() + @IsArray() + @IsEnum(IndictmentSubtype, { each: true }) + @Field(() => [IndictmentSubtype], { nullable: true }) + readonly indictmentCountSubtypes?: IndictmentSubtype[] } diff --git a/apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts b/apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts index 3ea6a132945c..f3ef5aa954c6 100644 --- a/apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts +++ b/apps/judicial-system/api/src/app/modules/indictment-count/models/indictmentCount.model.ts @@ -3,9 +3,13 @@ import { GraphQLJSONObject } from 'graphql-type-json' import { Field, ID, ObjectType, registerEnumType } from '@nestjs/graphql' import type { SubstanceMap } from '@island.is/judicial-system/types' -import { IndictmentCountOffense } from '@island.is/judicial-system/types' +import { + IndictmentCountOffense, + IndictmentSubtype, +} from '@island.is/judicial-system/types' registerEnumType(IndictmentCountOffense, { name: 'IndictmentCountOffense' }) +registerEnumType(IndictmentSubtype, { name: 'IndictmentSubtype' }) @ObjectType() export class IndictmentCount { @@ -41,4 +45,7 @@ export class IndictmentCount { @Field(() => String, { nullable: true }) readonly legalArguments?: string + + @Field(() => [IndictmentSubtype], { nullable: true }) + readonly indictmentCountSubtypes?: IndictmentSubtype[] } diff --git a/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js b/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js index bba95e9361aa..9297700a679e 100644 --- a/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js +++ b/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js @@ -5,7 +5,7 @@ module.exports = { await queryInterface.sequelize.transaction((transaction) => queryInterface.addColumn( 'indictment_count', - 'indictment_count_subtype', + 'indictment_count_subtypes', { type: Sequelize.ARRAY(Sequelize.STRING), allowNull: true, diff --git a/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts b/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts index 0559ffa35277..3b12997e7fed 100644 --- a/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts @@ -10,7 +10,10 @@ import { import { ApiPropertyOptional } from '@nestjs/swagger' import type { SubstanceMap } from '@island.is/judicial-system/types' -import { IndictmentCountOffense } from '@island.is/judicial-system/types' +import { + IndictmentCountOffense, + IndictmentSubtype, +} from '@island.is/judicial-system/types' export class UpdateIndictmentCountDto { @IsOptional() @@ -50,4 +53,10 @@ export class UpdateIndictmentCountDto { @IsString() @ApiPropertyOptional({ type: String }) readonly legalArguments?: string + + @IsOptional() + @IsArray() + @IsEnum(IndictmentSubtype, { each: true }) + @ApiPropertyOptional({ enum: IndictmentSubtype, isArray: true }) + readonly indictmentCountSubtypes?: IndictmentSubtype[] } diff --git a/apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts b/apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts index ae7ec5c59316..03b9d511f2d7 100644 --- a/apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts +++ b/apps/judicial-system/backend/src/app/modules/indictment-count/models/indictmentCount.model.ts @@ -11,7 +11,10 @@ import { import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' import type { SubstanceMap } from '@island.is/judicial-system/types' -import { IndictmentCountOffense } from '@island.is/judicial-system/types' +import { + IndictmentCountOffense, + IndictmentSubtype, +} from '@island.is/judicial-system/types' import { Case } from '../../case/models/case.model' @@ -69,4 +72,12 @@ export class IndictmentCount extends Model { @Column({ type: DataType.TEXT, allowNull: true }) @ApiPropertyOptional({ type: String }) legalArguments?: string + + @Column({ + type: DataType.ARRAY(DataType.ENUM), + allowNull: true, + values: Object.values(IndictmentSubtype), + }) + @ApiPropertyOptional({ enum: IndictmentSubtype, isArray: true }) + indictmentCountSubtypes?: IndictmentSubtype[] } diff --git a/apps/judicial-system/web/src/components/FormProvider/case.graphql b/apps/judicial-system/web/src/components/FormProvider/case.graphql index f2a5e28a0aa0..fad260247afb 100644 --- a/apps/judicial-system/web/src/components/FormProvider/case.graphql +++ b/apps/judicial-system/web/src/components/FormProvider/case.graphql @@ -215,6 +215,7 @@ query Case($input: CaseQueryInput!) { lawsBroken incidentDescription legalArguments + indictmentCountSubtypes } requestDriversLicenseSuspension appealState diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index a578e012448e..1e539328449f 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -346,6 +346,10 @@ export const IndictmentCount: FC = ({ const [legalArgumentsErrorMessage, setLegalArgumentsErrorMessage] = useState('') + const subtypes = indictmentCount.policeCaseNumber + ? workingCase.indictmentSubtypes[indictmentCount.policeCaseNumber] + : [] + const offensesOptions = useMemo( () => Object.values(IndictmentCountOffense).map((offense) => ({ @@ -457,37 +461,47 @@ export const IndictmentCount: FC = ({ crimeScenes={workingCase.crimeScenes} /> - - -
- {indictmentCount.policeCaseNumber && - workingCase.indictmentSubtypes[ - indictmentCount.policeCaseNumber - ].map((subtype: IndictmentSubtype) => ( + {subtypes.length > 1 && ( + + +
+ {subtypes.map((subtype: IndictmentSubtype) => (
{ - // handleUpdateCivilClaimant({ - // caseId: workingCase.id, - // civilClaimantId: civilClaimant.id, - // nationalId: null, - // noNationalId: !civilClaimant.noNationalId, - // }) - // }} + checked={ + indictmentCount.indictmentCountSubtypes?.includes( + subtype, + ) ?? false + } + onChange={(evt) => { + const indictmentCountSubtypes = evt.target.checked + ? [ + ...(indictmentCount.indictmentCountSubtypes ?? []), + subtype, + ] + : [ + ...( + indictmentCount.indictmentCountSubtypes ?? [] + ).filter((val) => val !== subtype), + ] + + handleIndictmentCountChanges({ indictmentCountSubtypes }) + }} backgroundColor="white" large filled />
))} -
-
+
+
+ )} { const { formatMessage } = useIntl() const [createIndictmentCountMutation] = useCreateIndictmentCountMutation() - const [updateIndictmentCountMutation] = useUpdateIndictmentCountMutation() + const [ + updateIndictmentCountMutation, + { loading: isUpdatingIndictmentCount }, + ] = useUpdateIndictmentCountMutation() const [deleteIndictmentCountMutation] = useDeleteIndictmentCountMutation() const createIndictmentCount = useCallback( @@ -138,6 +141,7 @@ const useIndictmentCounts = () => { return { updateIndictmentCount, + isUpdatingIndictmentCount, createIndictmentCount, deleteIndictmentCount, updateIndictmentCountState, diff --git a/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql b/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql index f87f2173bf6f..f8aca1a9268d 100644 --- a/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql +++ b/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/updateIndictmentCount.graphql @@ -11,5 +11,6 @@ mutation UpdateIndictmentCount($input: UpdateIndictmentCountInput!) { lawsBroken incidentDescription legalArguments + indictmentCountSubtypes } } From 9532708281065638e27be705900a53737f0a601d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 14:08:45 +0000 Subject: [PATCH 04/68] Refactor --- .../Indictment/IndictmentCount.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 1e539328449f..12924dc9a512 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -412,6 +412,21 @@ export const IndictmentCount: FC = ({ }) } + const handleSubtypeChange = ( + subtype: IndictmentSubtype, + checked: boolean, + ) => { + const currentSubtypes = new Set( + indictmentCount.indictmentCountSubtypes ?? [], + ) + + checked ? currentSubtypes.add(subtype) : currentSubtypes.delete(subtype) + + handleIndictmentCountChanges({ + indictmentCountSubtypes: Array.from(currentSubtypes), + }) + } + return ( {onDelete && ( @@ -480,18 +495,7 @@ export const IndictmentCount: FC = ({ ) ?? false } onChange={(evt) => { - const indictmentCountSubtypes = evt.target.checked - ? [ - ...(indictmentCount.indictmentCountSubtypes ?? []), - subtype, - ] - : [ - ...( - indictmentCount.indictmentCountSubtypes ?? [] - ).filter((val) => val !== subtype), - ] - - handleIndictmentCountChanges({ indictmentCountSubtypes }) + handleSubtypeChange(subtype, evt.target.checked) }} backgroundColor="white" large From e5ea1e2dfac494ad6a857c1eddee6a6a1dff2db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 14:17:34 +0000 Subject: [PATCH 05/68] Refactor --- .../web/src/utils/hooks/useIndictmentCounts/index.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts b/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts index e77f52d8afe0..0d0e2b835b2e 100644 --- a/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts @@ -24,10 +24,7 @@ const useIndictmentCounts = () => { const { formatMessage } = useIntl() const [createIndictmentCountMutation] = useCreateIndictmentCountMutation() - const [ - updateIndictmentCountMutation, - { loading: isUpdatingIndictmentCount }, - ] = useUpdateIndictmentCountMutation() + const [updateIndictmentCountMutation] = useUpdateIndictmentCountMutation() const [deleteIndictmentCountMutation] = useDeleteIndictmentCountMutation() const createIndictmentCount = useCallback( @@ -141,7 +138,6 @@ const useIndictmentCounts = () => { return { updateIndictmentCount, - isUpdatingIndictmentCount, createIndictmentCount, deleteIndictmentCount, updateIndictmentCountState, From 853dea2fad99e841e7454b7a554d8948ba9ed40a Mon Sep 17 00:00:00 2001 From: andes-it Date: Wed, 4 Dec 2024 14:37:53 +0000 Subject: [PATCH 06/68] chore: nx format:write update dirty files --- .../migrations/20241204124025-update-indictment-count.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js b/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js index 9297700a679e..523e416ba23e 100644 --- a/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js +++ b/apps/judicial-system/backend/migrations/20241204124025-update-indictment-count.js @@ -1,7 +1,7 @@ 'use strict' module.exports = { - async up(queryInterface, Sequelize) { + async up(queryInterface, Sequelize) { await queryInterface.sequelize.transaction((transaction) => queryInterface.addColumn( 'indictment_count', @@ -17,6 +17,9 @@ module.exports = { }, async down(queryInterface) { - await queryInterface.removeColumn('indictment_count', 'indictment_count_subtypes') + await queryInterface.removeColumn( + 'indictment_count', + 'indictment_count_subtypes', + ) }, } From d0b5c60dbd7554036f967138e32538d454cf17ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 14:51:02 +0000 Subject: [PATCH 07/68] Add feature flag --- apps/judicial-system/api/infra/judicial-system-api.ts | 4 ++-- .../Prosecutor/Indictments/Indictment/IndictmentCount.tsx | 7 +++++-- .../web/src/utils/hooks/useSections/index.ts | 8 +++++++- charts/judicial-system/values.prod.yaml | 2 +- charts/judicial-system/values.staging.yaml | 2 +- charts/services/judicial-system-api/values.prod.yaml | 2 +- charts/services/judicial-system-api/values.staging.yaml | 2 +- libs/judicial-system/types/src/lib/case.ts | 5 +---- libs/judicial-system/types/src/lib/feature.ts | 1 + 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/apps/judicial-system/api/infra/judicial-system-api.ts b/apps/judicial-system/api/infra/judicial-system-api.ts index efe736fa005b..8f5cabe11e2c 100644 --- a/apps/judicial-system/api/infra/judicial-system-api.ts +++ b/apps/judicial-system/api/infra/judicial-system-api.ts @@ -47,8 +47,8 @@ export const serviceSetup = (services: { }, HIDDEN_FEATURES: { dev: '', - staging: '', - prod: '', + staging: 'MULTIPLE_INDICTMENT_SUBTYPES', + prod: 'MULTIPLE_INDICTMENT_SUBTYPES', }, }) .secrets({ diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 12924dc9a512..d1c964386e88 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -484,9 +484,12 @@ export const IndictmentCount: FC = ({ />
{subtypes.map((subtype: IndictmentSubtype) => ( -
+
{ const { formatMessage } = useIntl() const router = useRouter() + const { features } = useContext(FeatureContext) const isActive = (pathname: string) => router.pathname.replace(/\/\[\w+\]/g, '') === pathname @@ -402,7 +406,9 @@ const useSections = ( state === CaseState.RECEIVED || state === CaseState.WAITING_FOR_CANCELLATION || router.pathname === `${constants.INDICTMENTS_ADD_FILES_ROUTE}/[id]` - const isTrafficViolation = isTrafficViolationCase(workingCase) + const isTrafficViolation = + features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || + isTrafficViolationCase(workingCase) return { name: formatMessage(sections.indictmentCaseProsecutorSection.title), diff --git a/charts/judicial-system/values.prod.yaml b/charts/judicial-system/values.prod.yaml index dc74c1e64d61..ffcef752f5ec 100644 --- a/charts/judicial-system/values.prod.yaml +++ b/charts/judicial-system/values.prod.yaml @@ -30,7 +30,7 @@ judicial-system-api: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'master' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: '' + HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' IDENTITY_SERVER_ISSUER_URL: 'https://innskra.island.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/charts/judicial-system/values.staging.yaml b/charts/judicial-system/values.staging.yaml index 3dacb3f6fb4a..30afa9a56e74 100644 --- a/charts/judicial-system/values.staging.yaml +++ b/charts/judicial-system/values.staging.yaml @@ -30,7 +30,7 @@ judicial-system-api: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'test' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: '' + HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' IDENTITY_SERVER_ISSUER_URL: 'https://identity-server.staging01.devland.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/charts/services/judicial-system-api/values.prod.yaml b/charts/services/judicial-system-api/values.prod.yaml index 2143dcd8565b..05f04f9d7278 100644 --- a/charts/services/judicial-system-api/values.prod.yaml +++ b/charts/services/judicial-system-api/values.prod.yaml @@ -30,7 +30,7 @@ env: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'master' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: '' + HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' IDENTITY_SERVER_ISSUER_URL: 'https://innskra.island.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/charts/services/judicial-system-api/values.staging.yaml b/charts/services/judicial-system-api/values.staging.yaml index 3d6002b0a864..7533d12090a6 100644 --- a/charts/services/judicial-system-api/values.staging.yaml +++ b/charts/services/judicial-system-api/values.staging.yaml @@ -30,7 +30,7 @@ env: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'test' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: '' + HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' IDENTITY_SERVER_ISSUER_URL: 'https://identity-server.staging01.devland.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/libs/judicial-system/types/src/lib/case.ts b/libs/judicial-system/types/src/lib/case.ts index 357d26da8f5f..25beea51adcf 100644 --- a/libs/judicial-system/types/src/lib/case.ts +++ b/libs/judicial-system/types/src/lib/case.ts @@ -393,10 +393,7 @@ export const isTrafficViolationCase = (theCase: { return ( flatIndictmentSubtypes.length > 0 && flatIndictmentSubtypes.every( - (val) => - val === IndictmentSubtype.TRAFFIC_VIOLATION || - // TODO: Refactor this - val === IndictmentSubtype.NARCOTICS_OFFENSE, + (val) => val === IndictmentSubtype.TRAFFIC_VIOLATION, ) ) } diff --git a/libs/judicial-system/types/src/lib/feature.ts b/libs/judicial-system/types/src/lib/feature.ts index 742e56c2f145..dd8f5e437a8f 100644 --- a/libs/judicial-system/types/src/lib/feature.ts +++ b/libs/judicial-system/types/src/lib/feature.ts @@ -1,3 +1,4 @@ export enum Feature { NONE = 'NONE', // must be at least one + MULTIPLE_INDICTMENT_SUBTYPES = 'MULTIPLE_INDICTMENT_SUBTYPES', } From d31e20d957a04c2412616a28b29746981e37e6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 15:01:14 +0000 Subject: [PATCH 08/68] Refactor --- .../Prosecutor/Indictments/Indictment/IndictmentCount.css.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts index 7db43bb9be27..7671970527a8 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.css.ts @@ -11,4 +11,5 @@ export const indictmentSubtypesContainter = style({ export const indictmentSubtypesItem = style({ flex: `1 1 calc(50% - ${theme.spacing[1]}px)`, + whiteSpace: 'nowrap', }) From 026eaf64ecd8ec012c650f6fd323228ddef60517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 4 Dec 2024 15:23:19 +0000 Subject: [PATCH 09/68] Refactor --- .../components/ServiceAnnouncement/ServiceAnnouncement.tsx | 2 +- apps/judicial-system/web/src/utils/hooks/useSections/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx b/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx index 8dac19a8c448..f70fe17e3e35 100644 --- a/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx +++ b/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect, useState } from 'react' +import { FC } from 'react' import { IntlShape, MessageDescriptor, useIntl } from 'react-intl' import { AlertMessage, Box, LoadingDots, Text } from '@island.is/island-ui/core' diff --git a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts index e596490b9b80..c0bc8bfbb355 100644 --- a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts @@ -1,3 +1,4 @@ +import { useContext } from 'react' import { useIntl } from 'react-intl' import { useRouter } from 'next/router' @@ -19,6 +20,7 @@ import { isTrafficViolationCase, } from '@island.is/judicial-system/types' import { core, sections } from '@island.is/judicial-system-web/messages' +import { FeatureContext } from '@island.is/judicial-system-web/src/components' import { RouteSection } from '@island.is/judicial-system-web/src/components/PageLayout/PageLayout' import { formatCaseResult } from '@island.is/judicial-system-web/src/components/PageLayout/utils' import { @@ -34,8 +36,6 @@ import { TempCase as Case } from '@island.is/judicial-system-web/src/types' import { stepValidations, stepValidationsType } from '../../formHelper' import { shouldUseAppealWithdrawnRoutes } from '../../stepHelper' -import { useContext } from 'react' -import { FeatureContext } from '@island.is/judicial-system-web/src/components' const validateFormStepper = ( isActiveSubSectionValid: boolean, From 124668c8cfb8c7595e5471a0f4aea16e2dfc2d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 5 Dec 2024 11:34:35 +0000 Subject: [PATCH 10/68] Add featur flag --- .../IndictmentCaseFilesList.tsx | 8 +++++++- .../Prosecutor/Indictments/CaseFiles/CaseFiles.tsx | 11 +++++++++-- .../Prosecutor/Indictments/Processing/Processing.tsx | 7 ++++++- .../web/src/utils/hooks/useCaseList/index.tsx | 7 ++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx index 9dd7bb9cb3bd..b9646bc28671 100644 --- a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx +++ b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx @@ -5,6 +5,7 @@ import { AnimatePresence } from 'framer-motion' import { Box, Text } from '@island.is/island-ui/core' import { formatDate } from '@island.is/judicial-system/formatters' import { + Feature, isCompletedCase, isDefenceUser, isDistrictCourtUser, @@ -15,6 +16,7 @@ import { isTrafficViolationCase, } from '@island.is/judicial-system/types' import { + FeatureContext, FileNotFoundModal, PdfButton, SectionHeading, @@ -71,12 +73,16 @@ const IndictmentCaseFilesList: FC = ({ }) => { const { formatMessage } = useIntl() const { user, limitedAccess } = useContext(UserContext) + const { features } = useContext(FeatureContext) const { onOpen, fileNotFound, dismissFileNotFound } = useFileList({ caseId: workingCase.id, connectedCaseParentId, }) - const showTrafficViolationCaseFiles = isTrafficViolationCase(workingCase) + const showTrafficViolationCaseFiles = + features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || + isTrafficViolationCase(workingCase) + const showSubpoenaPdf = displayGeneratedPDFs && workingCase.defendants?.some( diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx index 72f3b46677af..e10112fd8b4e 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx @@ -5,9 +5,13 @@ import router from 'next/router' import { Box, InputFileUpload } from '@island.is/island-ui/core' import { fileExtensionWhitelist } from '@island.is/island-ui/core/types' import * as constants from '@island.is/judicial-system/consts' -import { isTrafficViolationCase } from '@island.is/judicial-system/types' +import { + Feature, + isTrafficViolationCase, +} from '@island.is/judicial-system/types' import { titles } from '@island.is/judicial-system-web/messages' import { + FeatureContext, FormContentContainer, FormContext, FormFooter, @@ -29,6 +33,7 @@ import * as strings from './CaseFiles.strings' const CaseFiles = () => { const { workingCase, isLoadingWorkingCase, caseNotFound } = useContext(FormContext) + const { features } = useContext(FeatureContext) const { formatMessage } = useIntl() const { uploadFiles, @@ -41,7 +46,9 @@ const CaseFiles = () => { workingCase.id, ) - const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase) + const isTrafficViolationCaseCheck = + features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || + isTrafficViolationCase(workingCase) const stepIsValid = (isTrafficViolationCaseCheck || diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx index b46712f2e366..f85025b8c9b6 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx @@ -12,12 +12,14 @@ import { import * as constants from '@island.is/judicial-system/consts' import { AdvocateType, + Feature, isTrafficViolationCase, } from '@island.is/judicial-system/types' import { core, titles } from '@island.is/judicial-system-web/messages' import { BlueBox, CommentsInput, + FeatureContext, FormContentContainer, FormContext, FormFooter, @@ -63,6 +65,7 @@ const Processing: FC = () => { isCaseUpToDate, refreshCase, } = useContext(FormContext) + const { features } = useContext(FeatureContext) const { updateCase, transitionCase, setAndSendCaseToServer } = useCase() const { formatMessage } = useIntl() const { updateDefendant, updateDefendantState } = useDefendants() @@ -73,7 +76,9 @@ const Processing: FC = () => { deleteCivilClaimant, } = useCivilClaimants() const router = useRouter() - const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase) + const isTrafficViolationCaseCheck = + features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || + isTrafficViolationCase(workingCase) const [civilClaimantNationalIdUpdate, setCivilClaimantNationalIdUpdate] = useState<{ nationalId: string | null; civilClaimantId: string }>() const [hasCivilClaimantChoice, setHasCivilClaimantChoice] = diff --git a/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx b/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx index d184a5703fb9..60458c5e195c 100644 --- a/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx +++ b/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx @@ -10,6 +10,7 @@ import { DEFENDER_ROUTE, } from '@island.is/judicial-system/consts' import { + Feature, isCompletedCase, isCourtOfAppealsUser, isDefenceUser, @@ -23,6 +24,7 @@ import { } from '@island.is/judicial-system/types' import { errors } from '@island.is/judicial-system-web/messages' import { + FeatureContext, FormContext, UserContext, } from '@island.is/judicial-system-web/src/components' @@ -40,6 +42,7 @@ const useCaseList = () => { >([null, false]) const { user, limitedAccess } = useContext(UserContext) const { getCase } = useContext(FormContext) + const { features } = useContext(FeatureContext) const { formatMessage } = useIntl() const { isTransitioningCase, isSendingNotification } = useCase() const router = useRouter() @@ -47,7 +50,9 @@ const useCaseList = () => { const openCase = useCallback( (caseToOpen: Case, openCaseInNewTab?: boolean) => { let routeTo = null - const isTrafficViolation = isTrafficViolationCase(caseToOpen) + const isTrafficViolation = + features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || + isTrafficViolationCase(caseToOpen) if (isDefenceUser(user)) { if (isRequestCase(caseToOpen.type)) { From bb9bf5b784d9a7eb62389a074b70bc2f56b6666b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 9 Dec 2024 14:01:05 +0000 Subject: [PATCH 11/68] Remove console.log() --- .../Indictment/IndictmentCount.strings.ts | 6 ++ .../Indictment/IndictmentCount.tsx | 59 +++++++++++++++---- .../judicial-system/web/src/utils/validate.ts | 20 ++++++- 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts index d6b7abe87aff..85dfb9e3d1ae 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts @@ -123,6 +123,12 @@ export const indictmentCount = defineMessages({ defaultMessage: 'í blóðsýni mældist', description: 'Notaður sem upphafstexti fyrir efni í blóði í atvikalýsingu.', }, + indictmentDescriptionSubtypesAutofill: { + id: 'judicial.system.core:indictments_indictment.indictment_count.indictment_description_subtypes_auto_fill', + defaultMessage: 'fyrir [{subtypes}] með því að hafa, {date}', + description: + 'Notaður sem ástæða í atvikalýsingu fyrir önnur brot en umferðalagabrot.', + }, legalArgumentsLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.legal_arguments_label', defaultMessage: 'Heimfærsla', diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index d1c964386e88..426fff7542c9 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -283,14 +283,34 @@ export const getLegalArguments = ( }) } +const hasOnlyOneItemInSubArrays = ( + indictmentSubtypes?: Record, +) => { + if (!indictmentSubtypes) return false + + return Object.values(indictmentSubtypes).every( + (subArray) => subArray.length === 1, + ) +} + export const getIncidentDescription = ( indictmentCount: TIndictmentCount, formatMessage: IntlShape['formatMessage'], crimeScene?: CrimeScene, + subtypes?: Record, ) => { - const { offenses, substances, vehicleRegistrationNumber } = indictmentCount - - if (offenses?.length === 0) { + const { + offenses, + substances, + vehicleRegistrationNumber, + indictmentCountSubtypes, + } = indictmentCount + + if ( + offenses?.length === 0 || + (!hasOnlyOneItemInSubArrays(subtypes) && + indictmentCountSubtypes?.length === 0) + ) { return '' } @@ -309,17 +329,29 @@ export const getIncidentDescription = ( formatMessage, ) - const incidentDescription = formatMessage( - strings.incidentDescriptionAutofill, - { - incidentDate: incidentDate ? incidentDate : '[Dagsetning]', - vehicleRegistrationNumber: vehicleRegistrationNumber - ? vehicleRegistrationNumber - : '[Skráningarnúmer ökutækis]', - reason, - incidentLocation: incidentLocation ? incidentLocation : '[Vettvangur]', - }, + const formattedIncidentDate = incidentDate ? incidentDate : '[Dagsetning]' + const formattedIndictmentLocation = incidentLocation + ? incidentLocation + : '[Vettvangur]' + const formattedVehicleRegistrationNumber = vehicleRegistrationNumber + ? vehicleRegistrationNumber + : '[Skráningarnúmer ökutækis]' + + const incidentDescription = indictmentCountSubtypes?.every( + (subtype) => subtype === IndictmentSubtype.TRAFFIC_VIOLATION, ) + ? formatMessage(strings.incidentDescriptionAutofill, { + incidentDate: formattedIncidentDate, + vehicleRegistrationNumber: formattedVehicleRegistrationNumber, + reason, + incidentLocation: formattedIndictmentLocation, + }) + : formatMessage(strings.indictmentDescriptionSubtypesAutofill, { + subtypes: indictmentCountSubtypes + ?.map((subtype) => indictmentSubtypes[subtype]) + .join(', '), + date: formattedIncidentDate, + }) return incidentDescription } @@ -404,6 +436,7 @@ export const IndictmentCount: FC = ({ }, formatMessage, crimeScene, + workingCase.indictmentSubtypes, ) onChange(indictmentCount.id, { diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 390946736f4a..8bdbf2c19cd2 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -294,12 +294,28 @@ export const isProcessingStepValidIndictments = ( ) } +const hasOnlyOneItemInSubArrays = ( + indictmentSubtypes?: Record, +) => { + if (!indictmentSubtypes) return false + + return Object.values(indictmentSubtypes).every( + (subArray) => subArray.length === 1, + ) +} + export const isTrafficViolationStepValidIndictments = ( workingCase: Case, ): boolean => { return Boolean( - workingCase.demands && - (!workingCase.hasCivilClaims || workingCase.civilDemands), + hasOnlyOneItemInSubArrays(workingCase.indictmentSubtypes) || + (workingCase.indictmentCounts?.every( + (indictmentCount) => + indictmentCount.indictmentCountSubtypes && + indictmentCount.indictmentCountSubtypes?.length > 0, + ) && + workingCase.demands && + (!workingCase.hasCivilClaims || workingCase.civilDemands)), ) } From 5e20628cc3a53faf4db754b624b022f165f3c02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 9 Dec 2024 15:07:51 +0000 Subject: [PATCH 12/68] Checkpoint --- .../Indictment/IndictmentCount.tsx | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 426fff7542c9..05841a63e87c 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -304,13 +304,10 @@ export const getIncidentDescription = ( substances, vehicleRegistrationNumber, indictmentCountSubtypes, + policeCaseNumber, } = indictmentCount - if ( - offenses?.length === 0 || - (!hasOnlyOneItemInSubArrays(subtypes) && - indictmentCountSubtypes?.length === 0) - ) { + if (offenses?.length === 0) { return '' } @@ -323,35 +320,51 @@ export const getIncidentDescription = ( formatDate(crimeScene.date, 'PPPP')?.replace('dagur,', 'daginn') ?? '' } - const reason = getIncidentDescriptionReason( - offenses ?? [], - substances ?? {}, - formatMessage, - ) - const formattedIncidentDate = incidentDate ? incidentDate : '[Dagsetning]' + const formattedIndictmentLocation = incidentLocation ? incidentLocation : '[Vettvangur]' + const formattedVehicleRegistrationNumber = vehicleRegistrationNumber ? vehicleRegistrationNumber : '[Skráningarnúmer ökutækis]' - const incidentDescription = indictmentCountSubtypes?.every( - (subtype) => subtype === IndictmentSubtype.TRAFFIC_VIOLATION, + const reason = getIncidentDescriptionReason( + offenses ?? [], + substances ?? {}, + formatMessage, ) - ? formatMessage(strings.incidentDescriptionAutofill, { - incidentDate: formattedIncidentDate, - vehicleRegistrationNumber: formattedVehicleRegistrationNumber, - reason, - incidentLocation: formattedIndictmentLocation, - }) - : formatMessage(strings.indictmentDescriptionSubtypesAutofill, { - subtypes: indictmentCountSubtypes - ?.map((subtype) => indictmentSubtypes[subtype]) - .join(', '), - date: formattedIncidentDate, - }) + + const incidentDescription = + hasOnlyOneItemInSubArrays(subtypes) && + policeCaseNumber && + subtypes && + subtypes[policeCaseNumber][0] === IndictmentSubtype.TRAFFIC_VIOLATION + ? formatMessage(strings.incidentDescriptionAutofill, { + incidentDate: formattedIncidentDate, + vehicleRegistrationNumber: formattedVehicleRegistrationNumber, + reason, + incidentLocation: formattedIndictmentLocation, + }) + : hasOnlyOneItemInSubArrays(subtypes) + ? formatMessage(strings.indictmentDescriptionSubtypesAutofill, { + subtypes: + subtypes && + policeCaseNumber && + indictmentSubtypes[ + subtypes[policeCaseNumber][0] as IndictmentSubtype + ], + date: formattedIncidentDate, + }) + : formatMessage(strings.indictmentDescriptionSubtypesAutofill, { + subtypes: indictmentCountSubtypes + ?.map((subtype) => indictmentSubtypes[subtype]) + .join(', '), + date: formattedIncidentDate, + }) + + console.log(incidentDescription) return incidentDescription } From 4112929ecf506a1cb6298596ee049df5f13de310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 9 Dec 2024 20:51:57 +0000 Subject: [PATCH 13/68] Refactor --- .../Indictment/IndictmentCount.tsx | 94 +++++++++---------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 05841a63e87c..987645edfe20 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -307,66 +307,58 @@ export const getIncidentDescription = ( policeCaseNumber, } = indictmentCount - if (offenses?.length === 0) { + if (!offenses || offenses.length === 0) { return '' } - let incidentLocation = '' - let incidentDate = '' - - if (crimeScene) { - incidentLocation = crimeScene.place ?? '' - incidentDate = - formatDate(crimeScene.date, 'PPPP')?.replace('dagur,', 'daginn') ?? '' - } - - const formattedIncidentDate = incidentDate ? incidentDate : '[Dagsetning]' - - const formattedIndictmentLocation = incidentLocation - ? incidentLocation - : '[Vettvangur]' + const incidentLocation = crimeScene?.place || '[Vettvangur]' + const incidentDate = crimeScene?.date + ? formatDate(crimeScene.date, 'PPPP')?.replace('dagur,', 'daginn') || '' + : '[Dagsetning]' - const formattedVehicleRegistrationNumber = vehicleRegistrationNumber - ? vehicleRegistrationNumber - : '[Skráningarnúmer ökutækis]' + const vehicleRegistration = + vehicleRegistrationNumber || '[Skráningarnúmer ökutækis]' const reason = getIncidentDescriptionReason( - offenses ?? [], - substances ?? {}, + offenses, + substances || {}, formatMessage, ) - const incidentDescription = - hasOnlyOneItemInSubArrays(subtypes) && - policeCaseNumber && - subtypes && - subtypes[policeCaseNumber][0] === IndictmentSubtype.TRAFFIC_VIOLATION - ? formatMessage(strings.incidentDescriptionAutofill, { - incidentDate: formattedIncidentDate, - vehicleRegistrationNumber: formattedVehicleRegistrationNumber, - reason, - incidentLocation: formattedIndictmentLocation, - }) - : hasOnlyOneItemInSubArrays(subtypes) - ? formatMessage(strings.indictmentDescriptionSubtypesAutofill, { - subtypes: - subtypes && - policeCaseNumber && - indictmentSubtypes[ - subtypes[policeCaseNumber][0] as IndictmentSubtype - ], - date: formattedIncidentDate, - }) - : formatMessage(strings.indictmentDescriptionSubtypesAutofill, { - subtypes: indictmentCountSubtypes - ?.map((subtype) => indictmentSubtypes[subtype]) - .join(', '), - date: formattedIncidentDate, - }) - - console.log(incidentDescription) - - return incidentDescription + const hasSingleSubtype = hasOnlyOneItemInSubArrays(subtypes) + + const singleSubType = + subtypes && policeCaseNumber && subtypes[policeCaseNumber]?.[0] + + const trafficViolationSubtype = + singleSubType === IndictmentSubtype.TRAFFIC_VIOLATION + + if (hasSingleSubtype && trafficViolationSubtype) { + return formatMessage(strings.incidentDescriptionAutofill, { + incidentDate, + vehicleRegistrationNumber: vehicleRegistration, + reason, + incidentLocation, + }) + } + + if (hasSingleSubtype) { + return formatMessage(strings.indictmentDescriptionSubtypesAutofill, { + subtypes: singleSubType + ? indictmentSubtypes[singleSubType as IndictmentSubtype] + : '', + date: incidentDate, + }) + } + + const allSubtypes = indictmentCountSubtypes + ?.map((subtype) => indictmentSubtypes[subtype]) + .join(', ') + + return formatMessage(strings.indictmentDescriptionSubtypesAutofill, { + subtypes: allSubtypes, + date: incidentDate, + }) } export const IndictmentCount: FC = ({ From c01023475733c2b4cf1c5a6964c8bf5a33d931fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 10 Dec 2024 10:36:30 +0000 Subject: [PATCH 14/68] Refactor --- .../Indictment/IndictmentCount.spec.tsx | 54 +- .../Indictment/IndictmentCount.strings.ts | 17 + .../Indictment/IndictmentCount.tsx | 656 +++++++++--------- 3 files changed, 410 insertions(+), 317 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx index 8aa5d8e14030..2485fec21f6c 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx @@ -1,12 +1,16 @@ import { createIntl } from 'react-intl' import { Substance, SubstanceMap } from '@island.is/judicial-system/types' -import { IndictmentCountOffense as offense } from '@island.is/judicial-system-web/src/graphql/schema' +import { + IndictmentSubtype, + IndictmentCountOffense as offense, +} from '@island.is/judicial-system-web/src/graphql/schema' import { getIncidentDescriptionReason, getLegalArguments, getRelevantSubstances, + getIncidentDescription, } from './IndictmentCount' const formatMessage = createIntl({ @@ -192,3 +196,51 @@ describe('getIncidentDescriptionReason', () => { ) }) }) + +describe.only('getIncidentDescription', () => { + test('should return an empty string if there are no offenses', () => { + const result = getIncidentDescription( + { id: 'testId', offenses: [] }, + formatMessage, + ) + + expect(result).toBe('') + }) + + test('should return an empty string if offenses are missing', () => { + const result = getIncidentDescription({ id: 'testId' }, formatMessage) + + expect(result).toBe('') + }) + + test('should return a description for only traffic violations', () => { + const result = getIncidentDescription( + { + id: 'testId', + offenses: [offense.DRUNK_DRIVING], + policeCaseNumber: '123-123-123', + }, + formatMessage, + {}, + { '123-123-123': [IndictmentSubtype.TRAFFIC_VIOLATION] }, + ) + + expect(result).toBe( + 'fyrir umferðarlagabrot með því að hafa, [Dagsetning], ekið bifreiðinni [Skráningarnúmer ökutækis] undir áhrifum áfengis um [Vettvangur], þar sem lögregla stöðvaði aksturinn.', + ) + }) + + test('should return a description for a single subtype that is not a traffic violation', () => { + const result = getIncidentDescription( + { + id: 'testId', + policeCaseNumber: '123-123-123', + }, + formatMessage, + {}, + { '123-123-123': [IndictmentSubtype.CUSTOMS_VIOLATION] }, + ) + + expect(result).toBe('fyrir [tollalagabrot] með því að hafa, [Dagsetning]') + }) +}) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts index 85dfb9e3d1ae..a308cf48e2b3 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts @@ -6,6 +6,11 @@ export const indictmentCount = defineMessages({ defaultMessage: 'Eyða', description: 'Notaður sem texti á Eyða hnappi á ákæruliða skrefi í ákærum.', }, + policeCaseNumberTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.police_case_number_title', + defaultMessage: 'Málsnúmer lögreglu', + description: 'Notaður sem titill fyrir "Málsnúmer lögreglu" svæði.', + }, policeCaseNumberLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.police_case_number_label', defaultMessage: 'LÖKE málsnúmer', @@ -42,6 +47,12 @@ export const indictmentCount = defineMessages({ description: 'Notaður sem skýritexti á "brot" lista á ákæruliða skrefi í ákærum.', }, + incidentDescriptionTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.incident_description_title', + defaultMessage: 'Atvikalýsing', + description: + 'Notaður sem titill á "atvikalýsing" svæði á ákæruliða skrefi í ákærum.', + }, incidentDescriptionLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.incident_description_label', defaultMessage: 'Atvikalýsing', @@ -129,6 +140,12 @@ export const indictmentCount = defineMessages({ description: 'Notaður sem ástæða í atvikalýsingu fyrir önnur brot en umferðalagabrot.', }, + legalArgumentsTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.legal_arguments_title', + defaultMessage: 'Heimfærsla', + description: + 'Notaður sem titill á "heimfærslu" svæði á ákæruliða skrefi í ákærum.', + }, legalArgumentsLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.legal_arguments_label', defaultMessage: 'Heimfærsla', diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 987645edfe20..3ed4a5af6ccd 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -19,6 +19,7 @@ import { import { CrimeScene, IndictmentSubtype, + isTrafficViolationCase, offenseSubstances, Substance, SubstanceMap, @@ -479,6 +480,11 @@ export const IndictmentCount: FC = ({ )} + - - - - + + + + + - ))} - - )} - {indictmentCount.offenses?.includes( - IndictmentCountOffense.DRUNK_DRIVING, - ) && ( - - { - removeErrorMessageIfValid( - ['empty'], - event.target.value, - bloodAlcoholContentErrorMessage, - setBloodAlcoholContentErrorMessage, - ) - - updateIndictmentCountState( - indictmentCount.id, - { - substances: { - ...indictmentCount.substances, - ALCOHOL: event.target.value, - }, - }, - setWorkingCase, - ) - }} - onBlur={(event) => { - const value = - event.target.value.length > 0 - ? `${event.target.value}${'0,00'.slice( - event.target.value.length, - )}` - : event.target.value - - validateAndSetErrorMessage( - ['empty'], - value, - setBloodAlcoholContentErrorMessage, - ) - - const substances = { - ...indictmentCount.substances, - ALCOHOL: value, - } - - handleIndictmentCountChanges({ - substances, - }) - }} - > - + offenseType === IndictmentCountOffense.ILLEGAL_DRUGS_DRIVING || + offenseType === + IndictmentCountOffense.PRESCRIPTION_DRUGS_DRIVING, + ) + .map((offenseType) => ( + + + + ))} + + { - const law = (selectedOption as LawsBrokenOption).law - const lawsBroken = [ - ...(indictmentCount.lawsBroken ?? []), - law, - ].sort(lawsCompare) - - onChange(indictmentCount.id, { - lawsBroken: lawsBroken, - legalArguments: getLegalArguments(lawsBroken, formatMessage), - }) - - handleIndictmentCountChanges({ - lawsBroken, - }) - }} - required - /> - - {indictmentCount.lawsBroken && indictmentCount.lawsBroken.length > 0 && ( - - {indictmentCount.lawsBroken.map((brokenLaw) => ( - - { - const lawsBroken = (indictmentCount.lawsBroken ?? []).filter( - (b) => lawsCompare(b, brokenLaw) !== 0, - ) - - onChange(indictmentCount.id, { - lawsBroken: lawsBroken, - legalArguments: getLegalArguments( - lawsBroken, - formatMessage, - ), - }) - }} - aria-label={lawTag(brokenLaw)} - > - - {lawTag(brokenLaw)} - + {indictmentCount.lawsBroken && indictmentCount.lawsBroken.length > 0 && ( + + {indictmentCount.lawsBroken.map((brokenLaw) => ( + + { + const lawsBroken = ( + indictmentCount.lawsBroken ?? [] + ).filter((b) => lawsCompare(b, brokenLaw) !== 0) + + onChange(indictmentCount.id, { + lawsBroken: lawsBroken, + legalArguments: getLegalArguments( + lawsBroken, + formatMessage, + ), + }) + }} + aria-label={lawTag(brokenLaw)} + > + + {lawTag(brokenLaw)} + + + - + ))} - ))} - + )} + )} - + + = ({ /> - - - { - removeErrorMessageIfValid( - ['empty'], - event.target.value, - legalArgumentsErrorMessage, - setLegalArgumentsErrorMessage, - ) + + - updateIndictmentCountState( - indictmentCount.id, - { legalArguments: event.target.value }, - setWorkingCase, - ) - }} - onBlur={(event) => { - validateAndSetErrorMessage( - ['empty'], - event.target.value, - setLegalArgumentsErrorMessage, - ) + { + removeErrorMessageIfValid( + ['empty'], + event.target.value, + legalArgumentsErrorMessage, + setLegalArgumentsErrorMessage, + ) - onChange(indictmentCount.id, { - legalArguments: event.target.value.trim(), - }) - }} - required - rows={7} - autoExpand={{ on: true, maxHeight: 600 }} - textarea - /> - + updateIndictmentCountState( + indictmentCount.id, + { legalArguments: event.target.value }, + setWorkingCase, + ) + }} + onBlur={(event) => { + validateAndSetErrorMessage( + ['empty'], + event.target.value, + setLegalArgumentsErrorMessage, + ) + + onChange(indictmentCount.id, { + legalArguments: event.target.value.trim(), + }) + }} + required + rows={7} + autoExpand={{ on: true, maxHeight: 600 }} + textarea + /> ) From 38acc5989d0ec64e1dcddaa8113d973ce1680ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 10 Dec 2024 14:02:25 +0000 Subject: [PATCH 15/68] Fix tests --- .../src/app/modules/event/event.service.ts | 2 +- .../Indictment/IndictmentCount.spec.tsx | 66 ++- .../Indictment/IndictmentCount.tsx | 535 +++++++++--------- 3 files changed, 339 insertions(+), 264 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/event/event.service.ts b/apps/judicial-system/backend/src/app/modules/event/event.service.ts index 9ab7679e86ae..d3b9c0848136 100644 --- a/apps/judicial-system/backend/src/app/modules/event/event.service.ts +++ b/apps/judicial-system/backend/src/app/modules/event/event.service.ts @@ -43,7 +43,7 @@ const caseEvent: Record = { [CaseTransition.ACCEPT]: ':white_check_mark: Samþykkt', [CaseTransition.APPEAL]: ':judge: Kæra', ARCHIVE: ':file_cabinet: Sett í geymslu', - [CaseTransition.ASK_FOR_CANCELLATION]: ':interrobang: Beðið um aftuköllun', + [CaseTransition.ASK_FOR_CANCELLATION]: ':interrobang: Beðið um afturköllun', [CaseTransition.ASK_FOR_CONFIRMATION]: ':question: Beðið um staðfestingu', [CaseTransition.COMPLETE]: ':white_check_mark: Lokið', [CaseTransition.COMPLETE_APPEAL]: ':white_check_mark: Kæru lokið', diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx index 2485fec21f6c..0a49e1dcf8ab 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx @@ -197,18 +197,25 @@ describe('getIncidentDescriptionReason', () => { }) }) -describe.only('getIncidentDescription', () => { - test('should return an empty string if there are no offenses', () => { +describe('getIncidentDescription', () => { + test('should return an empty string if there are no offenses in traffic violations', () => { const result = getIncidentDescription( - { id: 'testId', offenses: [] }, + { id: 'testId', offenses: [], policeCaseNumber: '123-123-123' }, formatMessage, + {}, + { '123-123-123': [IndictmentSubtype.TRAFFIC_VIOLATION] }, ) expect(result).toBe('') }) - test('should return an empty string if offenses are missing', () => { - const result = getIncidentDescription({ id: 'testId' }, formatMessage) + test('should return an empty string if offenses are missing in traffic violations', () => { + const result = getIncidentDescription( + { id: 'testId', policeCaseNumber: '123-123-123' }, + formatMessage, + {}, + { '123-123-123': [IndictmentSubtype.TRAFFIC_VIOLATION] }, + ) expect(result).toBe('') }) @@ -243,4 +250,53 @@ describe.only('getIncidentDescription', () => { expect(result).toBe('fyrir [tollalagabrot] með því að hafa, [Dagsetning]') }) + + test('should return a description when there are multiple subtypes but only traffic violation is selected', () => { + const result = getIncidentDescription( + { + id: 'testId', + policeCaseNumber: '123-123-123', + offenses: [offense.DRUNK_DRIVING], + indictmentCountSubtypes: [IndictmentSubtype.TRAFFIC_VIOLATION], + }, + formatMessage, + {}, + { + '123-123-123': [ + IndictmentSubtype.CUSTOMS_VIOLATION, + IndictmentSubtype.TRAFFIC_VIOLATION, + ], + }, + ) + + expect(result).toBe( + 'fyrir umferðarlagabrot með því að hafa, [Dagsetning], ekið bifreiðinni [Skráningarnúmer ökutækis] undir áhrifum áfengis um [Vettvangur], þar sem lögregla stöðvaði aksturinn.', + ) + }) + + test('should return a description when there are multiple subtypes and all are selected', () => { + const result = getIncidentDescription( + { + id: 'testId', + policeCaseNumber: '123-123-123', + offenses: [offense.DRUNK_DRIVING], + indictmentCountSubtypes: [ + IndictmentSubtype.CUSTOMS_VIOLATION, + IndictmentSubtype.TRAFFIC_VIOLATION, + ], + }, + formatMessage, + {}, + { + '123-123-123': [ + IndictmentSubtype.CUSTOMS_VIOLATION, + IndictmentSubtype.TRAFFIC_VIOLATION, + ], + }, + ) + + expect(result).toBe( + 'fyrir [tollalagabrot, umferðarlagabrot] með því að hafa, [Dagsetning]', + ) + }) }) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 3ed4a5af6ccd..f4d88c516ef4 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -308,10 +308,6 @@ export const getIncidentDescription = ( policeCaseNumber, } = indictmentCount - if (!offenses || offenses.length === 0) { - return '' - } - const incidentLocation = crimeScene?.place || '[Vettvangur]' const incidentDate = crimeScene?.date ? formatDate(crimeScene.date, 'PPPP')?.replace('dagur,', 'daginn') || '' @@ -320,12 +316,6 @@ export const getIncidentDescription = ( const vehicleRegistration = vehicleRegistrationNumber || '[Skráningarnúmer ökutækis]' - const reason = getIncidentDescriptionReason( - offenses, - substances || {}, - formatMessage, - ) - const hasSingleSubtype = hasOnlyOneItemInSubArrays(subtypes) const singleSubType = @@ -334,7 +324,27 @@ export const getIncidentDescription = ( const trafficViolationSubtype = singleSubType === IndictmentSubtype.TRAFFIC_VIOLATION - if (hasSingleSubtype && trafficViolationSubtype) { + if (!hasSingleSubtype && !indictmentCountSubtypes?.length) { + return '' + } + + console.log(hasSingleSubtype, trafficViolationSubtype, subtypes) + + if ( + (hasSingleSubtype && trafficViolationSubtype) || + (indictmentCountSubtypes?.length === 1 && + indictmentCountSubtypes[0] === IndictmentSubtype.TRAFFIC_VIOLATION) + ) { + if (!offenses || offenses.length === 0) { + return '' + } + + const reason = getIncidentDescriptionReason( + offenses, + substances || {}, + formatMessage, + ) + return formatMessage(strings.incidentDescriptionAutofill, { incidentDate, vehicleRegistrationNumber: vehicleRegistration, @@ -465,7 +475,6 @@ export const IndictmentCount: FC = ({ indictmentCountSubtypes: Array.from(currentSubtypes), }) } - return ( {onDelete && ( @@ -557,264 +566,274 @@ export const IndictmentCount: FC = ({ )} - {isTrafficViolationCase(workingCase) && ( - <> - - { - let { value } = nextState - value = value.toUpperCase() - - return { ...nextState, value } - }} - onChange={(event) => { - removeErrorMessageIfValid( - ['empty', 'vehicle-registration-number'], - event.target.value, - vehicleRegistrationNumberErrorMessage, - setVehicleRegistrationNumberErrorMessage, - ) - - updateIndictmentCountState( - indictmentCount.id, - { - vehicleRegistrationNumber: event.target.value, - }, - setWorkingCase, - ) - }} - onBlur={async (event) => { - validateAndSetErrorMessage( - ['empty', 'vehicle-registration-number'], - event.target.value, - setVehicleRegistrationNumberErrorMessage, - ) - - handleIndictmentCountChanges({ - vehicleRegistrationNumber: event.target.value, - }) - }} - > - - - - - + + + + + - ))} - - )} - {indictmentCount.offenses?.includes( - IndictmentCountOffense.DRUNK_DRIVING, - ) && ( - - { - removeErrorMessageIfValid( - ['empty'], - event.target.value, - bloodAlcoholContentErrorMessage, - setBloodAlcoholContentErrorMessage, - ) - - updateIndictmentCountState( - indictmentCount.id, - { - substances: { - ...indictmentCount.substances, - ALCOHOL: event.target.value, - }, - }, - setWorkingCase, - ) - }} - onBlur={(event) => { - const value = - event.target.value.length > 0 - ? `${event.target.value}${'0,00'.slice( - event.target.value.length, - )}` - : event.target.value - - validateAndSetErrorMessage( - ['empty'], - value, - setBloodAlcoholContentErrorMessage, - ) - - const substances = { - ...indictmentCount.substances, - ALCOHOL: value, - } - - handleIndictmentCountChanges({ - substances, - }) - }} - > - + offenseType === + IndictmentCountOffense.ILLEGAL_DRUGS_DRIVING || + offenseType === + IndictmentCountOffense.PRESCRIPTION_DRUGS_DRIVING, + ) + .map((offenseType) => ( + + + + ))} + + { - const law = (selectedOption as LawsBrokenOption).law - const lawsBroken = [ - ...(indictmentCount.lawsBroken ?? []), - law, - ].sort(lawsCompare) - - onChange(indictmentCount.id, { - lawsBroken: lawsBroken, - legalArguments: getLegalArguments(lawsBroken, formatMessage), - }) - - handleIndictmentCountChanges({ - lawsBroken, - }) - }} - required - /> - - {indictmentCount.lawsBroken && indictmentCount.lawsBroken.length > 0 && ( - - {indictmentCount.lawsBroken.map((brokenLaw) => ( - - { - const lawsBroken = ( - indictmentCount.lawsBroken ?? [] - ).filter((b) => lawsCompare(b, brokenLaw) !== 0) - - onChange(indictmentCount.id, { - lawsBroken: lawsBroken, - legalArguments: getLegalArguments( - lawsBroken, - formatMessage, - ), - }) - }} - aria-label={lawTag(brokenLaw)} - > - - {lawTag(brokenLaw)} - - - - - ))} - - )} - - )} + {indictmentCount.lawsBroken && + indictmentCount.lawsBroken.length > 0 && ( + + {indictmentCount.lawsBroken.map((brokenLaw) => ( + + { + const lawsBroken = ( + indictmentCount.lawsBroken ?? [] + ).filter((b) => lawsCompare(b, brokenLaw) !== 0) + + onChange(indictmentCount.id, { + lawsBroken: lawsBroken, + legalArguments: getLegalArguments( + lawsBroken, + formatMessage, + ), + }) + }} + aria-label={lawTag(brokenLaw)} + > + + {lawTag(brokenLaw)} + + + + + ))} + + )} + + ))} Date: Tue, 10 Dec 2024 14:02:42 +0000 Subject: [PATCH 16/68] Fix lint --- .../Prosecutor/Indictments/Indictment/IndictmentCount.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index f4d88c516ef4..b22434f2be99 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -328,8 +328,6 @@ export const getIncidentDescription = ( return '' } - console.log(hasSingleSubtype, trafficViolationSubtype, subtypes) - if ( (hasSingleSubtype && trafficViolationSubtype) || (indictmentCountSubtypes?.length === 1 && From e400b2cca85e9e6a64745d159056ae16a568f55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 10 Dec 2024 14:17:35 +0000 Subject: [PATCH 17/68] Add hasOnlyOneItemInSubArrays to utils --- .../web/src/components/CaseFile/CaseFile.tsx | 2 +- .../CourtArrangements/CourtArrangements.tsx | 2 +- .../RestrictionTags/RestrictionTags.tsx | 2 +- .../HearingArrangements.tsx | 2 +- .../HearingArrangements.tsx | 2 +- .../ReceptionAndAssignment.tsx | 2 +- .../CourtOfAppeal/AppealCase/AppealCase.tsx | 2 +- .../CourtOfAppeal/Overview/Overview.tsx | 2 +- .../CourtOfAppeal/Summary/Summary.spec.tsx | 2 +- .../routes/CourtOfAppeal/Summary/Summary.tsx | 2 +- .../Indictment/IndictmentCount.tsx | 11 +- .../InvestigationCase/Defendant/Defendant.tsx | 2 +- .../InvestigationCase/Overview/Overview.tsx | 2 +- .../RestrictionCase/Overview/Overview.tsx | 2 +- .../DefendantInfo/DefendantInfo.tsx | 2 +- .../hooks/useAppealAlertBanner/index.tsx | 2 +- .../utils/hooks/useNationalRegistry/index.ts | 2 +- .../web/src/utils/hooks/useSections/index.ts | 2 +- .../web/src/utils/utils.spec.tsx | 182 ++++++++++++------ .../web/src/utils/{stepHelper.ts => utils.ts} | 27 +++ .../judicial-system/web/src/utils/validate.ts | 2 +- 21 files changed, 165 insertions(+), 91 deletions(-) rename apps/judicial-system/web/src/utils/{stepHelper.ts => utils.ts} (83%) diff --git a/apps/judicial-system/web/src/components/CaseFile/CaseFile.tsx b/apps/judicial-system/web/src/components/CaseFile/CaseFile.tsx index f6447323b82d..31ea2167c494 100644 --- a/apps/judicial-system/web/src/components/CaseFile/CaseFile.tsx +++ b/apps/judicial-system/web/src/components/CaseFile/CaseFile.tsx @@ -5,7 +5,7 @@ import { IconMapIcon } from '@island.is/island-ui/core' import { Box, Icon, StatusColor, Text } from '@island.is/island-ui/core' import { Colors } from '@island.is/island-ui/theme' -import { fileSize } from '../../utils/stepHelper' +import { fileSize } from '../../utils/utils' import IconButton from '../IconButton/IconButton' import * as styles from './CaseFile.css' diff --git a/apps/judicial-system/web/src/components/CourtArrangements/CourtArrangements.tsx b/apps/judicial-system/web/src/components/CourtArrangements/CourtArrangements.tsx index 9e8ee4794428..528dc8c62c7e 100644 --- a/apps/judicial-system/web/src/components/CourtArrangements/CourtArrangements.tsx +++ b/apps/judicial-system/web/src/components/CourtArrangements/CourtArrangements.tsx @@ -17,7 +17,7 @@ import { UpdateCase, useCase, } from '@island.is/judicial-system-web/src/utils/hooks' -import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/utils' import { strings } from './CourtArrangements.string' diff --git a/apps/judicial-system/web/src/components/RestrictionTags/RestrictionTags.tsx b/apps/judicial-system/web/src/components/RestrictionTags/RestrictionTags.tsx index 244e40b50256..af0f5754f87f 100644 --- a/apps/judicial-system/web/src/components/RestrictionTags/RestrictionTags.tsx +++ b/apps/judicial-system/web/src/components/RestrictionTags/RestrictionTags.tsx @@ -8,7 +8,7 @@ import { CaseType, } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' -import { getRestrictionTagVariant } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { getRestrictionTagVariant } from '@island.is/judicial-system-web/src/utils/utils' interface Props { workingCase: Case diff --git a/apps/judicial-system/web/src/routes/Court/InvestigationCase/HearingArrangements/HearingArrangements.tsx b/apps/judicial-system/web/src/routes/Court/InvestigationCase/HearingArrangements/HearingArrangements.tsx index fe6b8e5775b3..a5c6736832c5 100644 --- a/apps/judicial-system/web/src/routes/Court/InvestigationCase/HearingArrangements/HearingArrangements.tsx +++ b/apps/judicial-system/web/src/routes/Court/InvestigationCase/HearingArrangements/HearingArrangements.tsx @@ -28,7 +28,7 @@ import { useCase, useOnceOn, } from '@island.is/judicial-system-web/src/utils/hooks' -import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/utils' import { isCourtHearingArrangementsStepValidIC } from '@island.is/judicial-system-web/src/utils/validate' import { icHearingArrangements as m } from './HearingArrangements.strings' diff --git a/apps/judicial-system/web/src/routes/Court/RestrictionCase/HearingArrangements/HearingArrangements.tsx b/apps/judicial-system/web/src/routes/Court/RestrictionCase/HearingArrangements/HearingArrangements.tsx index 29c8ac9ab0d6..0a47f7681314 100644 --- a/apps/judicial-system/web/src/routes/Court/RestrictionCase/HearingArrangements/HearingArrangements.tsx +++ b/apps/judicial-system/web/src/routes/Court/RestrictionCase/HearingArrangements/HearingArrangements.tsx @@ -28,7 +28,7 @@ import { useCase, useOnceOn, } from '@island.is/judicial-system-web/src/utils/hooks' -import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/utils' import { isCourtHearingArrangemenstStepValidRC } from '@island.is/judicial-system-web/src/utils/validate' import { rcHearingArrangements as m } from './HearingArrangements.strings' diff --git a/apps/judicial-system/web/src/routes/Court/components/ReceptionAndAssignment/ReceptionAndAssignment.tsx b/apps/judicial-system/web/src/routes/Court/components/ReceptionAndAssignment/ReceptionAndAssignment.tsx index fbde3ea941f9..ab11824c19c5 100644 --- a/apps/judicial-system/web/src/routes/Court/components/ReceptionAndAssignment/ReceptionAndAssignment.tsx +++ b/apps/judicial-system/web/src/routes/Court/components/ReceptionAndAssignment/ReceptionAndAssignment.tsx @@ -19,7 +19,7 @@ import { PageTitle, } from '@island.is/judicial-system-web/src/components' import { Gender } from '@island.is/judicial-system-web/src/graphql/schema' -import { getDefendantPleaText } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { getDefendantPleaText } from '@island.is/judicial-system-web/src/utils/utils' import { isReceptionAndAssignmentStepValid } from '@island.is/judicial-system-web/src/utils/validate' import CourtCaseNumber from '../CourtCaseNumber/CourtCaseNumber' diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/AppealCase/AppealCase.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/AppealCase/AppealCase.tsx index 034a368283de..174518642b1e 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/AppealCase/AppealCase.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/AppealCase/AppealCase.tsx @@ -28,7 +28,7 @@ import { useCase } from '@island.is/judicial-system-web/src/utils/hooks' import { hasSentNotification, isReopenedCOACase, -} from '@island.is/judicial-system-web/src/utils/stepHelper' +} from '@island.is/judicial-system-web/src/utils/utils' import { isCourtOfAppealCaseStepValid } from '@island.is/judicial-system-web/src/utils/validate' import CaseNumberInput from '../components/CaseNumberInput/CaseNumberInput' diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx index ee4b2b49bd93..d48aae95e800 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx @@ -20,7 +20,7 @@ import { } from '@island.is/judicial-system-web/src/components' import useInfoCardItems from '@island.is/judicial-system-web/src/components/InfoCard/useInfoCardItems' import { useAppealAlertBanner } from '@island.is/judicial-system-web/src/utils/hooks' -import { shouldUseAppealWithdrawnRoutes } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { shouldUseAppealWithdrawnRoutes } from '@island.is/judicial-system-web/src/utils/utils' import { titleForCase } from '@island.is/judicial-system-web/src/utils/titleForCase/titleForCase' import CaseFilesOverview from '../components/CaseFilesOverview/CaseFilesOverview' diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx index 75066f7860ae..fb2f012b2e7d 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx @@ -9,7 +9,7 @@ import { CaseType, } from '@island.is/judicial-system-web/src/graphql/schema' import { mockTransitonCaseMutation } from '@island.is/judicial-system-web/src/utils/mocks' -import * as stepHelper from '@island.is/judicial-system-web/src/utils/stepHelper' +import * as stepHelper from '@island.is/judicial-system-web/src/utils/utils' import { FormContextWrapper, IntlProviderWrapper, diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.tsx index 4d77a326cd87..3d34ee158612 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.tsx @@ -31,7 +31,7 @@ import { import { hasSentNotification, shouldUseAppealWithdrawnRoutes, -} from '@island.is/judicial-system-web/src/utils/stepHelper' +} from '@island.is/judicial-system-web/src/utils/utils' import CaseNumbers from '../components/CaseNumbers/CaseNumbers' import RulingModifiedModal from './RulingModifiedModal/RulingModifiedModal' diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index b22434f2be99..010818b31162 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -48,6 +48,7 @@ import { indictmentCount as strings } from './IndictmentCount.strings' import { indictmentCountEnum as enumStrings } from './IndictmentCountEnum.strings' import { indictmentCountSubstanceEnum as substanceStrings } from './IndictmentCountSubstanceEnum.strings' import * as styles from './IndictmentCount.css' +import { hasOnlyOneItemInSubArrays } from '@island.is/judicial-system-web/src/utils/utils' interface Props { indictmentCount: TIndictmentCount @@ -284,16 +285,6 @@ export const getLegalArguments = ( }) } -const hasOnlyOneItemInSubArrays = ( - indictmentSubtypes?: Record, -) => { - if (!indictmentSubtypes) return false - - return Object.values(indictmentSubtypes).every( - (subArray) => subArray.length === 1, - ) -} - export const getIncidentDescription = ( indictmentCount: TIndictmentCount, formatMessage: IntlShape['formatMessage'], diff --git a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx index 119bca8574ae..126942bbbc33 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx @@ -45,7 +45,7 @@ import { useCase, useDefendants, } from '@island.is/judicial-system-web/src/utils/hooks' -import { isBusiness } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { isBusiness } from '@island.is/judicial-system-web/src/utils/utils' import { isDefendantStepValidIC } from '@island.is/judicial-system-web/src/utils/validate' import { diff --git a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Overview/Overview.tsx b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Overview/Overview.tsx index 515c483ca2d4..f6e2f7521864 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Overview/Overview.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Overview/Overview.tsx @@ -44,7 +44,7 @@ import { NotificationType, } from '@island.is/judicial-system-web/src/graphql/schema' import { useCase } from '@island.is/judicial-system-web/src/utils/hooks' -import { createCaseResentExplanation } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { createCaseResentExplanation } from '@island.is/judicial-system-web/src/utils/utils' import * as styles from './Overview.css' diff --git a/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Overview/Overview.tsx b/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Overview/Overview.tsx index 1c5d3b0e2723..b45148fed9c6 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Overview/Overview.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Overview/Overview.tsx @@ -48,7 +48,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { useCase } from '@island.is/judicial-system-web/src/utils/hooks' import { formatRequestedCustodyRestrictions } from '@island.is/judicial-system-web/src/utils/restrictions' -import { createCaseResentExplanation } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { createCaseResentExplanation } from '@island.is/judicial-system-web/src/utils/utils' import * as styles from './Overview.css' diff --git a/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx index 3e4149d6dfb1..ab6664496ae2 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/components/DefendantInfo/DefendantInfo.tsx @@ -31,7 +31,7 @@ import { validateAndSetErrorMessage, } from '@island.is/judicial-system-web/src/utils/formHelper' import { useNationalRegistry } from '@island.is/judicial-system-web/src/utils/hooks' -import { isBusiness } from '@island.is/judicial-system-web/src/utils/stepHelper' +import { isBusiness } from '@island.is/judicial-system-web/src/utils/utils' import * as strings from './DefendantInfo.strings' diff --git a/apps/judicial-system/web/src/utils/hooks/useAppealAlertBanner/index.tsx b/apps/judicial-system/web/src/utils/hooks/useAppealAlertBanner/index.tsx index b1cd571d306f..7378e9ad3d87 100644 --- a/apps/judicial-system/web/src/utils/hooks/useAppealAlertBanner/index.tsx +++ b/apps/judicial-system/web/src/utils/hooks/useAppealAlertBanner/index.tsx @@ -30,7 +30,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase } from '@island.is/judicial-system-web/src/types' -import { hasSentNotification } from '../../stepHelper' +import { hasSentNotification } from '../../utils' import { strings } from './useAppealAlertBanner.strings' import * as styles from './useAppealAlertBanner.css' diff --git a/apps/judicial-system/web/src/utils/hooks/useNationalRegistry/index.ts b/apps/judicial-system/web/src/utils/hooks/useNationalRegistry/index.ts index aa1848fc1315..12d2977bf7e4 100644 --- a/apps/judicial-system/web/src/utils/hooks/useNationalRegistry/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useNationalRegistry/index.ts @@ -9,7 +9,7 @@ import { NationalRegistryResponsePerson, } from '@island.is/judicial-system-web/src/types' -import { isBusiness } from '../../stepHelper' +import { isBusiness } from '../../utils' import { validate } from '../../validate' const useNationalRegistry = (nationalId?: string | null) => { diff --git a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts index c0bc8bfbb355..350595015b5f 100644 --- a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts @@ -35,7 +35,7 @@ import { import { TempCase as Case } from '@island.is/judicial-system-web/src/types' import { stepValidations, stepValidationsType } from '../../formHelper' -import { shouldUseAppealWithdrawnRoutes } from '../../stepHelper' +import { shouldUseAppealWithdrawnRoutes } from '../../utils' const validateFormStepper = ( isActiveSubSectionValid: boolean, diff --git a/apps/judicial-system/web/src/utils/utils.spec.tsx b/apps/judicial-system/web/src/utils/utils.spec.tsx index a65cc31ecc11..86db8ab12d66 100644 --- a/apps/judicial-system/web/src/utils/utils.spec.tsx +++ b/apps/judicial-system/web/src/utils/utils.spec.tsx @@ -14,8 +14,9 @@ import { validateAndSendToServer } from './formHelper' import { getAppealEndDate, getShortGender, + hasOnlyOneItemInSubArrays, hasSentNotification, -} from './stepHelper' +} from './utils' describe('Formatters utils', () => { describe('Parse time', () => { @@ -137,7 +138,7 @@ describe('Formatters utils', () => { }) }) -describe('Step helper', () => { +describe('Utils', () => { describe('insertAt', () => { test('should insert a string at a certain position into another string', () => { // Arrange @@ -329,6 +330,70 @@ describe('Step helper', () => { // Assert expect(res).toEqual(false) }) + + test('should return false if no notification is found of a specific notification type', () => { + // Arrange + const email = faker.internet.email() + const n: Notification[] = [ + { + id: faker.datatype.uuid(), + created: faker.date.future().toISOString(), + caseId: faker.datatype.uuid(), + type: NotificationType.COURT_DATE, + recipients: [ + { + success: true, + address: email, + }, + ], + }, + ] + const nt = NotificationType.REVOKED + + // Act + const res = hasSentNotification(nt, n).hasSent + + // Assert + expect(res).toEqual(false) + }) + + test('should return true if the latest notification has been sent successfully', () => { + // Arrange + const email = faker.internet.email() + const n: Notification[] = [ + { + id: faker.datatype.uuid(), + created: faker.date.future().toISOString(), + caseId: faker.datatype.uuid(), + type: NotificationType.COURT_DATE, + recipients: [ + { + success: true, + address: email, + }, + ], + }, + { + id: faker.datatype.uuid(), + created: faker.date.past().toISOString(), + caseId: faker.datatype.uuid(), + type: NotificationType.COURT_DATE, + recipients: [ + { + success: true, + address: email, + }, + ], + }, + ] + const nt = NotificationType.COURT_DATE + + // Act + const res = hasSentNotification(nt, n).hasSent + + // Assert + expect(res).toEqual(true) + }) }) describe('validateAndSendToServer', () => { @@ -378,67 +443,58 @@ describe('Step helper', () => { }) }) - test('should return false if no notification is found of a spesific notification type', () => { - // Arrange - const email = faker.internet.email() - const n: Notification[] = [ - { - id: faker.datatype.uuid(), - created: faker.date.future().toISOString(), - caseId: faker.datatype.uuid(), - type: NotificationType.COURT_DATE, - recipients: [ - { - success: true, - address: email, - }, - ], - }, - ] - const nt = NotificationType.REVOKED - - // Act - const res = hasSentNotification(nt, n).hasSent - - // Assert - expect(res).toEqual(false) - }) + describe('hasOnlyOneItemInSubArrays', () => { + test('should return true if all subarrays in the given object have only one item', () => { + // Arrange + const indictmentSubtypes = { + '123-123-123': ['item1'], + '234-234-234': ['item2'], + } + + // Act + const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + + // Assert + expect(result).toEqual(true) + }) - test('should return true if the latest notification has been sent successfully', () => { - // Arrange - const email = faker.internet.email() - const n: Notification[] = [ - { - id: faker.datatype.uuid(), - created: faker.date.future().toISOString(), - caseId: faker.datatype.uuid(), - type: NotificationType.COURT_DATE, - recipients: [ - { - success: true, - address: email, - }, - ], - }, - { - id: faker.datatype.uuid(), - created: faker.date.past().toISOString(), - caseId: faker.datatype.uuid(), - type: NotificationType.COURT_DATE, - recipients: [ - { - success: true, - address: email, - }, - ], - }, - ] - const nt = NotificationType.COURT_DATE - - // Act - const res = hasSentNotification(nt, n).hasSent - - // Assert - expect(res).toEqual(true) + test('should return false if any subarray in the given object has more than one item', () => { + // Arrange + const indictmentSubtypes = { + '123-123-123': ['item1', 'item2'], + '234-234-234': ['item3'], + } + + // Act + const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + + // Assert + expect(result).toEqual(false) + }) + + test('should return false if the given object is empty', () => { + // Arrange + const indictmentSubtypes: Record = {} + + // Act + const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + + // Assert + expect(result).toEqual(false) + }) + + test('should return false if any subarray is the given object has no items', () => { + // Arrange + const indictmentSubtypes = { + '123-123-123': [], + '234-234-234': [], + } + + // Act + const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + + // Assert + expect(result).toEqual(false) + }) }) }) diff --git a/apps/judicial-system/web/src/utils/stepHelper.ts b/apps/judicial-system/web/src/utils/utils.ts similarity index 83% rename from apps/judicial-system/web/src/utils/stepHelper.ts rename to apps/judicial-system/web/src/utils/utils.ts index 5ea47b22ea76..09a76128da2e 100644 --- a/apps/judicial-system/web/src/utils/stepHelper.ts +++ b/apps/judicial-system/web/src/utils/utils.ts @@ -147,3 +147,30 @@ export const shouldUseAppealWithdrawnRoutes = (theCase: Case): boolean => { !theCase.appealJudge3) ) } + +/** + * Returns true if all subarrays in the given object have only one item. + * + * Example: + * const indictmentSubtypes = { + * '123-123-123': ['item1'], + * '234-234-234': ['item2'] + * } + * + * const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + * console.log(result) // true + * + * @param indictmentSubtypes - The object containing the subarrays to check. + * @returns {boolean} - True if all subarrays have only one item, false otherwise. + */ +export const hasOnlyOneItemInSubArrays = ( + indictmentSubtypes?: Record, +): boolean => { + if (!indictmentSubtypes || Object.keys(indictmentSubtypes).length === 0) { + return false + } + + return Object.values(indictmentSubtypes).every( + (subArray) => subArray.length === 1, + ) +} diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 8bdbf2c19cd2..c316017e3eba 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -17,7 +17,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' -import { isBusiness } from './stepHelper' +import { isBusiness } from './utils' export type Validation = | 'empty' From 209c06ff9773fe9f28bbfe83364d4f76a26b9de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 10 Dec 2024 14:20:19 +0000 Subject: [PATCH 18/68] Add hasOnlyOneItemInSubArrays to utils --- apps/judicial-system/web/src/utils/validate.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index c316017e3eba..b8eb1ea90228 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -17,7 +17,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' -import { isBusiness } from './utils' +import { hasOnlyOneItemInSubArrays, isBusiness } from './utils' export type Validation = | 'empty' @@ -294,16 +294,6 @@ export const isProcessingStepValidIndictments = ( ) } -const hasOnlyOneItemInSubArrays = ( - indictmentSubtypes?: Record, -) => { - if (!indictmentSubtypes) return false - - return Object.values(indictmentSubtypes).every( - (subArray) => subArray.length === 1, - ) -} - export const isTrafficViolationStepValidIndictments = ( workingCase: Case, ): boolean => { From 199283e418ee9021f6c2c05b6a5122af066c462a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 10 Dec 2024 14:43:26 +0000 Subject: [PATCH 19/68] Strip offence when removing traffic violation --- .../Prosecutor/Indictments/Indictment/IndictmentCount.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 010818b31162..e5949402200a 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -462,6 +462,9 @@ export const IndictmentCount: FC = ({ handleIndictmentCountChanges({ indictmentCountSubtypes: Array.from(currentSubtypes), + ...(!currentSubtypes.has(IndictmentSubtype.TRAFFIC_VIOLATION) && { + offenses: [], + }), }) } return ( From 48d491ef0ba8fc9d9ab9cd872908e721f71644ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 10 Dec 2024 15:04:04 +0000 Subject: [PATCH 20/68] Add headings --- .../Indictment/IndictmentCount.strings.ts | 24 +++++++++++++++++++ .../Indictment/IndictmentCount.tsx | 23 +++++++++++++++++- .../Substances/Substances.strings.ts | 7 ++++++ .../Indictment/Substances/Substances.tsx | 8 +++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts index a308cf48e2b3..8d3428aef3df 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings.ts @@ -23,6 +23,12 @@ export const indictmentCount = defineMessages({ description: 'Notaður sem skýritexti á LÖKE málsnúmers lista á ákæruliða skrefi í ákærum.', }, + vehicleRegistrationNumberTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.vehicle_registration_number_title', + defaultMessage: 'Númer ökutækis', + description: + 'Notaður sem titill á "Númer ökutækis" svæði á ákæruliða skrefi í ákærum.', + }, vehicleRegistrationNumberLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.vehicle_registration_number_label', defaultMessage: 'Skráningarnúmer ökutækis', @@ -35,6 +41,12 @@ export const indictmentCount = defineMessages({ description: 'Notaður sem skýritexti á "skráningarnúmer ökutækis" svæði á ákæruliða skrefi í ákærum.', }, + incidentTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.incident_title', + defaultMessage: 'Brot', + description: + 'Notaður sem titill á "brot" lista á ákæruliða skrefi í ákærum.', + }, incidentLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.incident_label', defaultMessage: 'Brot', @@ -65,6 +77,12 @@ export const indictmentCount = defineMessages({ description: 'Notaður sem skýritexti á "atvikalýsing" svæði á ákæruliða skrefi í ákærum.', }, + bloodAlcoholContentTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.blood_alcohol_content_title', + defaultMessage: 'Vínandamagn', + description: + 'Notaður sem titill á "vínandamagn" svæði á ákæruliða skrefi í ákærum.', + }, bloodAlcoholContentLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.blood_alcohol_content_label', defaultMessage: 'Vínandamagn (‰)', @@ -77,6 +95,12 @@ export const indictmentCount = defineMessages({ description: 'Notaður sem skýritexti á "vínandamagn" svæði á ákæruliða skrefi í ákærum.', }, + lawsBrokenTitle: { + id: 'judicial.system.core:indictments_indictment.indictment_count.laws_broken_title', + defaultMessage: 'Lagaákvæði', + description: + 'Notaður sem titill á "lagaákvæði" leitarboxi á ákæruliða skrefi í ákærum.', + }, lawsBrokenLabel: { id: 'judicial.system.core:indictments_indictment.indictment_count.laws_broken_label', defaultMessage: 'Lagaákvæði', diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index e5949402200a..07bd9f8c874f 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -528,6 +528,7 @@ export const IndictmentCount: FC = ({
{subtypes.map((subtype: IndictmentSubtype) => ( @@ -563,6 +564,11 @@ export const IndictmentCount: FC = ({ indictmentCount.indictmentCountSubtypes[0] === IndictmentSubtype.TRAFFIC_VIOLATION && ( <> + = ({ + = ({ return ( + + + + + - - - { + const law = (selectedOption as LawsBrokenOption).law + const lawsBroken = [ + ...(indictmentCount.lawsBroken ?? []), + law, + ].sort(lawsCompare) + + onChange(indictmentCount.id, { + lawsBroken: lawsBroken, + legalArguments: getLegalArguments( + lawsBroken, + formatMessage, + ), + }) + + handleIndictmentCountChanges({ + lawsBroken, + }) + }} + required + /> + + {indictmentCount.lawsBroken && + indictmentCount.lawsBroken.length > 0 && ( - {indictmentCount.offenses.map((offense) => ( + {indictmentCount.lawsBroken.map((brokenLaw) => ( = ({ { - const offenses = ( - indictmentCount.offenses ?? [] - ).filter((o) => o !== offense) - - offenseSubstances[offense].forEach((e) => { - if (indictmentCount.substances) { - delete indictmentCount.substances[e] - } - }) - - handleIndictmentCountChanges({ - offenses, - substances: indictmentCount.substances, + const lawsBroken = ( + indictmentCount.lawsBroken ?? [] + ).filter((b) => lawsCompare(b, brokenLaw) !== 0) + + onChange(indictmentCount.id, { + lawsBroken: lawsBroken, + legalArguments: getLegalArguments( + lawsBroken, + formatMessage, + ), }) }} + aria-label={lawTag(brokenLaw)} > - {formatMessage(enumStrings[offense])} + {lawTag(brokenLaw)} @@ -687,166 +843,8 @@ export const IndictmentCount: FC = ({ ))} )} - {indictmentCount.offenses?.includes( - IndictmentCountOffense.DRUNK_DRIVING, - ) && ( - - - { - removeErrorMessageIfValid( - ['empty'], - event.target.value, - bloodAlcoholContentErrorMessage, - setBloodAlcoholContentErrorMessage, - ) - - updateIndictmentCountState( - indictmentCount.id, - { - substances: { - ...indictmentCount.substances, - ALCOHOL: event.target.value, - }, - }, - setWorkingCase, - ) - }} - onBlur={(event) => { - const value = - event.target.value.length > 0 - ? `${event.target.value}${'0,00'.slice( - event.target.value.length, - )}` - : event.target.value - - validateAndSetErrorMessage( - ['empty'], - value, - setBloodAlcoholContentErrorMessage, - ) - - const substances = { - ...indictmentCount.substances, - ALCOHOL: value, - } - - handleIndictmentCountChanges({ - substances, - }) - }} - > - - - - )} - {indictmentCount.offenses - ?.filter( - (offenseType) => - offenseType === - IndictmentCountOffense.ILLEGAL_DRUGS_DRIVING || - offenseType === - IndictmentCountOffense.PRESCRIPTION_DRUGS_DRIVING, - ) - .map((offenseType) => ( - - - - ))} - - - + + + + - - - - - )} - {indictmentCount.offenses - ?.filter( - (offenseType) => - offenseType === - IndictmentCountOffense.ILLEGAL_DRUGS_DRIVING || - offenseType === - IndictmentCountOffense.PRESCRIPTION_DRUGS_DRIVING, - ) - .map((offenseType) => ( - - - - ))} + ))} + + + { - const law = (selectedOption as LawsBrokenOption).law - const lawsBroken = [ - ...(indictmentCount.lawsBroken ?? []), - law, - ].sort(lawsCompare) - - onChange(indictmentCount.id, { - lawsBroken: lawsBroken, - legalArguments: getLegalArguments( - lawsBroken, - formatMessage, - ), - }) - - handleIndictmentCountChanges({ - lawsBroken, - }) - }} - required - /> - - {indictmentCount.lawsBroken && - indictmentCount.lawsBroken.length > 0 && ( - - {indictmentCount.lawsBroken.map((brokenLaw) => ( - - { - const lawsBroken = ( - indictmentCount.lawsBroken ?? [] - ).filter((b) => lawsCompare(b, brokenLaw) !== 0) - - onChange(indictmentCount.id, { - lawsBroken: lawsBroken, - legalArguments: getLegalArguments( - lawsBroken, - formatMessage, - ), - }) - }} - aria-label={lawTag(brokenLaw)} - > - - {lawTag(brokenLaw)} - - - + {indictmentCount.lawsBroken.map((brokenLaw) => ( + + { + const lawsBroken = ( + indictmentCount.lawsBroken ?? [] + ).filter((b) => lawsCompare(b, brokenLaw) !== 0) + + onChange(indictmentCount.id, { + lawsBroken: lawsBroken, + legalArguments: getLegalArguments( + lawsBroken, + formatMessage, + ), + }) + }} + aria-label={lawTag(brokenLaw)} + > + + {lawTag(brokenLaw)} + - ))} + - )} - - ))} + ))} + + )} + + )} Date: Wed, 11 Dec 2024 15:22:07 +0000 Subject: [PATCH 23/68] Remove all indictmentCountSubtypes on remove --- .../Prosecutor/Indictments/Defendant/Defendant.tsx | 1 + .../Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx index 015d4bf71255..3d388f18b281 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx @@ -294,6 +294,7 @@ const Defendant = () => { updateIndictmentCount(workingCase.id, ic.id, { incidentDescription, + indictmentCountSubtypes: [], } as UpdateIndictmentCount) }) } diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 8d09a536a0b4..588ed8575e94 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -240,8 +240,17 @@ export const PoliceCaseInfo: FC = ({ variant="darkerBlue" onClick={() => { updatePoliceCase(index, { + policeCaseNumber: policeCaseNumbers[index], subtypes: subtypes.filter((s) => s !== subtype), }) + + updateIndictmentCount( + policeCaseNumbers[index], + crimeScene || {}, + { + [policeCaseNumbers[index]]: [], + }, + ) }} aria-label={formatMessage(policeCaseInfo.removeSubtype, { subtype: indictmentSubtypes[subtypes[0]], From 512a011a4517cc73078c80f712d4d732947b5ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 12 Dec 2024 14:47:56 +0000 Subject: [PATCH 24/68] Refactor --- .../Indictments/Defendant/Defendant.tsx | 9 ++++++++- .../PoliceCaseInfo/PoliceCaseInfo.tsx | 18 +++++++++++------- .../utils/hooks/useIndictmentCounts/index.ts | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx index 3d388f18b281..9a6fffd2d575 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx @@ -294,7 +294,9 @@ const Defendant = () => { updateIndictmentCount(workingCase.id, ic.id, { incidentDescription, - indictmentCountSubtypes: [], + ...(subtypes && { + indictmentCountSubtypes: subtypes[policeCaseNumber], + }), } as UpdateIndictmentCount) }) } @@ -509,6 +511,11 @@ const Defendant = () => { workingCase.origin === CaseOrigin.LOKE && index === 0 } updateIndictmentCount={handleUpdateIndictmentCount} + indictmentCount={workingCase.indictmentCounts?.find( + (ic) => + ic.policeCaseNumber === + workingCase.policeCaseNumbers?.[index], + )} /> )} diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 588ed8575e94..206095307685 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -26,6 +26,7 @@ import { } from '@island.is/judicial-system-web/src/utils/formHelper' import { policeCaseInfo } from './PoliceCaseInfo.strings' +import { TempIndictmentCount } from '@island.is/judicial-system-web/src/types' interface Props { index: number @@ -56,6 +57,7 @@ interface Props { subtypes?: Record, ) => void policeCaseNumberImmutable: boolean + indictmentCount?: TempIndictmentCount } export const PoliceCaseInfo: FC = ({ @@ -69,6 +71,7 @@ export const PoliceCaseInfo: FC = ({ updatePoliceCase, policeCaseNumberImmutable = false, updateIndictmentCount, + indictmentCount, }) => { const { formatMessage } = useIntl() @@ -215,12 +218,7 @@ export const PoliceCaseInfo: FC = ({ subtypes: [...(subtypes || []), indictmentSubtype], }) - updateIndictmentCount(policeCaseNumbers[index], crimeScene || {}, { - [policeCaseNumbers[index]]: [ - ...(subtypes || []), - indictmentSubtype, - ], - }) + updateIndictmentCount(policeCaseNumbers[index], crimeScene || {}) }} value={null} required @@ -244,11 +242,17 @@ export const PoliceCaseInfo: FC = ({ subtypes: subtypes.filter((s) => s !== subtype), }) + console.log(indictmentCount?.indictmentCountSubtypes) + updateIndictmentCount( policeCaseNumbers[index], crimeScene || {}, { - [policeCaseNumbers[index]]: [], + [policeCaseNumbers[index]]: subtypes.filter( + (s) => + s !== subtype && + indictmentCount?.indictmentCountSubtypes?.includes(s), + ), }, ) }} diff --git a/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts b/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts index 0d0e2b835b2e..0d3e2e9a11c4 100644 --- a/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useIndictmentCounts/index.ts @@ -80,7 +80,7 @@ const useIndictmentCounts = () => { const { data } = await updateIndictmentCountMutation({ variables: { input: { - indictmentCountId: indictmentCountId, + indictmentCountId, caseId, ...update, }, From 344c480d967ecd7cf7f24f1c63611f784548a355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 12 Dec 2024 14:56:07 +0000 Subject: [PATCH 25/68] Fix lint --- .../web/src/routes/CourtOfAppeal/Overview/Overview.tsx | 2 +- .../web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx | 2 +- .../Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx | 2 +- .../Indictments/Indictment/IndictmentCount.spec.tsx | 4 ++-- .../Indictments/Indictment/Substances/Substances.tsx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx index d48aae95e800..97581a5ecf69 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/Overview/Overview.tsx @@ -20,8 +20,8 @@ import { } from '@island.is/judicial-system-web/src/components' import useInfoCardItems from '@island.is/judicial-system-web/src/components/InfoCard/useInfoCardItems' import { useAppealAlertBanner } from '@island.is/judicial-system-web/src/utils/hooks' -import { shouldUseAppealWithdrawnRoutes } from '@island.is/judicial-system-web/src/utils/utils' import { titleForCase } from '@island.is/judicial-system-web/src/utils/titleForCase/titleForCase' +import { shouldUseAppealWithdrawnRoutes } from '@island.is/judicial-system-web/src/utils/utils' import CaseFilesOverview from '../components/CaseFilesOverview/CaseFilesOverview' import CaseOverviewHeader from '../components/CaseOverviewHeader/CaseOverviewHeader' diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx index fb2f012b2e7d..912472562aca 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx @@ -9,11 +9,11 @@ import { CaseType, } from '@island.is/judicial-system-web/src/graphql/schema' import { mockTransitonCaseMutation } from '@island.is/judicial-system-web/src/utils/mocks' -import * as stepHelper from '@island.is/judicial-system-web/src/utils/utils' import { FormContextWrapper, IntlProviderWrapper, } from '@island.is/judicial-system-web/src/utils/testHelpers' +import * as stepHelper from '@island.is/judicial-system-web/src/utils/utils' import Summary from './Summary' diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 206095307685..6836202da376 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -20,13 +20,13 @@ import { DateTime, UserContext, } from '@island.is/judicial-system-web/src/components' +import { TempIndictmentCount } from '@island.is/judicial-system-web/src/types' import { removeErrorMessageIfValid, validateAndSetErrorMessage, } from '@island.is/judicial-system-web/src/utils/formHelper' import { policeCaseInfo } from './PoliceCaseInfo.strings' -import { TempIndictmentCount } from '@island.is/judicial-system-web/src/types' interface Props { index: number diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx index 0a49e1dcf8ab..d545f8fcc9e8 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.spec.tsx @@ -2,15 +2,15 @@ import { createIntl } from 'react-intl' import { Substance, SubstanceMap } from '@island.is/judicial-system/types' import { - IndictmentSubtype, IndictmentCountOffense as offense, + IndictmentSubtype, } from '@island.is/judicial-system-web/src/graphql/schema' import { + getIncidentDescription, getIncidentDescriptionReason, getLegalArguments, getRelevantSubstances, - getIncidentDescription, } from './IndictmentCount' const formatMessage = createIntl({ diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Substances/Substances.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Substances/Substances.tsx index 3ecee6908694..902f9d82b404 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Substances/Substances.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Substances/Substances.tsx @@ -6,6 +6,7 @@ import { offenseSubstances, Substance as SubstanceEnum, } from '@island.is/judicial-system/types' +import { SectionHeading } from '@island.is/judicial-system-web/src/components' import { IndictmentCountOffense } from '@island.is/judicial-system-web/src/graphql/schema' import { ReactSelectOption, @@ -17,7 +18,6 @@ import { Substance } from '../Substance/Substance' import { substances as strings } from './Substances.strings' import { substanceEnum } from './SubstancesEnum.strings' import * as styles from './Substances.css' -import { SectionHeading } from '@island.is/judicial-system-web/src/components' interface Props { indictmentCount: TIndictmentCount From be33b29292b4d213f1e48c282bdc5709425908dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 12 Dec 2024 15:03:08 +0000 Subject: [PATCH 26/68] Cleanup --- .../Indictments/Defendant/Defendant.tsx | 19 +++++++++++-------- .../PoliceCaseInfo/PoliceCaseInfo.tsx | 4 +--- .../Indictment/IndictmentCount.tsx | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx index 9a6fffd2d575..54f34ccb9f36 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx @@ -279,25 +279,28 @@ const Defendant = () => { const handleUpdateIndictmentCount = ( policeCaseNumber: string, crimeScene: CrimeScene, - subtypes?: Record, + subtypes?: Record, ) => { if (workingCase.indictmentCounts) { workingCase.indictmentCounts - .filter((ic) => ic.policeCaseNumber === policeCaseNumber) - .forEach((ic) => { + .filter( + (indictmentCount) => + indictmentCount.policeCaseNumber === policeCaseNumber, + ) + .forEach((indictmentCount) => { const incidentDescription = getIncidentDescription( - ic, + indictmentCount, formatMessage, crimeScene, subtypes, ) - updateIndictmentCount(workingCase.id, ic.id, { + updateIndictmentCount(workingCase.id, indictmentCount.id, { incidentDescription, ...(subtypes && { indictmentCountSubtypes: subtypes[policeCaseNumber], }), - } as UpdateIndictmentCount) + }) }) } } @@ -512,8 +515,8 @@ const Defendant = () => { } updateIndictmentCount={handleUpdateIndictmentCount} indictmentCount={workingCase.indictmentCounts?.find( - (ic) => - ic.policeCaseNumber === + (indictmentCount) => + indictmentCount.policeCaseNumber === workingCase.policeCaseNumbers?.[index], )} /> diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 6836202da376..6b7eaa772036 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -54,7 +54,7 @@ interface Props { updateIndictmentCount: ( policeCaseNumber: string, crimeScene: CrimeScene, - subtypes?: Record, + subtypes?: Record, ) => void policeCaseNumberImmutable: boolean indictmentCount?: TempIndictmentCount @@ -242,8 +242,6 @@ export const PoliceCaseInfo: FC = ({ subtypes: subtypes.filter((s) => s !== subtype), }) - console.log(indictmentCount?.indictmentCountSubtypes) - updateIndictmentCount( policeCaseNumbers[index], crimeScene || {}, diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 00fd53cd7f4f..d11685e1dbd1 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -42,13 +42,13 @@ import { UpdateIndictmentCount, useIndictmentCounts, } from '@island.is/judicial-system-web/src/utils/hooks' +import { hasOnlyOneItemInSubArrays } from '@island.is/judicial-system-web/src/utils/utils' import { Substances as SubstanceChoices } from './Substances/Substances' import { indictmentCount as strings } from './IndictmentCount.strings' import { indictmentCountEnum as enumStrings } from './IndictmentCountEnum.strings' import { indictmentCountSubstanceEnum as substanceStrings } from './IndictmentCountSubstanceEnum.strings' import * as styles from './IndictmentCount.css' -import { hasOnlyOneItemInSubArrays } from '@island.is/judicial-system-web/src/utils/utils' interface Props { indictmentCount: TIndictmentCount From eed65d98b2d37a490868765b56abf6b0952471ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 12 Dec 2024 20:52:55 +0000 Subject: [PATCH 27/68] Refactor --- .../Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 6b7eaa772036..ac9de1949d7f 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -283,13 +283,8 @@ export const PoliceCaseInfo: FC = ({ updatePoliceCase() updateIndictmentCount( policeCaseNumbers[index], - { - ...crimeScene, - place: event.target.value, - }, - { - [policeCaseNumbers[index]]: [...(subtypes || [])], - }, + { ...crimeScene, place: event.target.value }, + { [policeCaseNumbers[index]]: [...(subtypes || [])] }, ) }} /> From eb8eaf0bb2869a8aab0d4b89f55e6ab807e109a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 12 Dec 2024 21:00:25 +0000 Subject: [PATCH 28/68] Refactor --- .../Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index ac9de1949d7f..20e54c567c67 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -86,6 +86,8 @@ export const PoliceCaseInfo: FC = ({ const [policeCaseNumberErrorMessage, setPoliceCaseNumberErrorMessage] = useState('') + const subtypesArray = [...(subtypes || [])] + useEffect(() => { if (policeCaseNumbers[index] !== originalPoliceCaseNumber) { // This component is now handling a new police case number @@ -215,7 +217,7 @@ export const PoliceCaseInfo: FC = ({ const indictmentSubtype = selectedOption?.value as IndictmentSubtype updatePoliceCase(index, { - subtypes: [...(subtypes || []), indictmentSubtype], + subtypes: [...subtypesArray, indictmentSubtype], }) updateIndictmentCount(policeCaseNumbers[index], crimeScene || {}) @@ -284,7 +286,7 @@ export const PoliceCaseInfo: FC = ({ updateIndictmentCount( policeCaseNumbers[index], { ...crimeScene, place: event.target.value }, - { [policeCaseNumbers[index]]: [...(subtypes || [])] }, + { [policeCaseNumbers[index]]: subtypesArray }, ) }} /> @@ -303,13 +305,8 @@ export const PoliceCaseInfo: FC = ({ updateIndictmentCount( policeCaseNumbers[index], - { - ...crimeScene, - date: date, - }, - { - [policeCaseNumbers[index]]: [...(subtypes || [])], - }, + { ...crimeScene, date: date }, + { [policeCaseNumbers[index]]: subtypesArray }, ) } }} From edf70e22fc7440854422bec56ab661bdf8e1b455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 12 Dec 2024 21:12:53 +0000 Subject: [PATCH 29/68] Refactor --- .../Prosecutor/Indictments/Indictment/IndictmentCount.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index d11685e1dbd1..cc145bdfb6d8 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -289,7 +289,7 @@ export const getIncidentDescription = ( indictmentCount: TIndictmentCount, formatMessage: IntlShape['formatMessage'], crimeScene?: CrimeScene, - subtypes?: Record, + subtypes?: Record, ) => { const { offenses, @@ -310,7 +310,7 @@ export const getIncidentDescription = ( const hasSingleSubtype = hasOnlyOneItemInSubArrays(subtypes) const singleSubType = - subtypes && policeCaseNumber && subtypes[policeCaseNumber]?.[0] + (policeCaseNumber && subtypes?.[policeCaseNumber]?.[0]) || undefined const trafficViolationSubtype = singleSubType === IndictmentSubtype.TRAFFIC_VIOLATION @@ -347,9 +347,7 @@ export const getIncidentDescription = ( if (hasSingleSubtype) { return formatMessage(strings.indictmentDescriptionSubtypesAutofill, { - subtypes: singleSubType - ? indictmentSubtypes[singleSubType as IndictmentSubtype] - : '', + subtypes: singleSubType ? indictmentSubtypes[singleSubType] : '', date: incidentDate, }) } From 9139e5f86c0279463a9d5cb35258c70ff550799a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 12:00:29 +0000 Subject: [PATCH 30/68] Remove isTrafficViolationCase checks --- .../src/app/modules/case/case.service.ts | 23 +++---- .../src/app/modules/case/pdf.service.ts | 7 --- .../web/src/utils/hooks/useCaseList/index.tsx | 11 +--- .../web/src/utils/hooks/useSections/index.ts | 61 ++++++++----------- libs/judicial-system/consts/src/lib/consts.ts | 4 +- 5 files changed, 35 insertions(+), 71 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index c89bbc8c0e0c..36304e74cd44 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -771,22 +771,13 @@ export class CaseService { }), ) - const caseFilesCategories = isTrafficViolationCase(theCase) - ? [ - CaseFileCategory.CRIMINAL_RECORD, - CaseFileCategory.COST_BREAKDOWN, - CaseFileCategory.CASE_FILE, - CaseFileCategory.PROSECUTOR_CASE_FILE, - CaseFileCategory.DEFENDANT_CASE_FILE, - ] - : [ - CaseFileCategory.INDICTMENT, - CaseFileCategory.CRIMINAL_RECORD, - CaseFileCategory.COST_BREAKDOWN, - CaseFileCategory.CASE_FILE, - CaseFileCategory.PROSECUTOR_CASE_FILE, - CaseFileCategory.DEFENDANT_CASE_FILE, - ] + const caseFilesCategories = [ + CaseFileCategory.CRIMINAL_RECORD, + CaseFileCategory.COST_BREAKDOWN, + CaseFileCategory.CASE_FILE, + CaseFileCategory.PROSECUTOR_CASE_FILE, + CaseFileCategory.DEFENDANT_CASE_FILE, + ] const deliverCaseFileToCourtMessages = theCase.caseFiles diff --git a/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts b/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts index 721c79cbf394..f39c5adf8737 100644 --- a/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts @@ -17,7 +17,6 @@ import { CaseFileCategory, EventType, hasIndictmentCaseBeenSubmittedToCourt, - isTrafficViolationCase, SubpoenaType, type User as TUser, } from '@island.is/judicial-system/types' @@ -205,12 +204,6 @@ export class PdfService { } async getIndictmentPdf(theCase: Case): Promise { - if (!isTrafficViolationCase(theCase)) { - throw new BadRequestException( - `Case ${theCase.id} is not a traffic violation case`, - ) - } - let confirmation: Confirmation | undefined = undefined if (hasIndictmentCaseBeenSubmittedToCourt(theCase.state)) { diff --git a/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx b/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx index 6629594f8d5f..d6a9cbd03e2e 100644 --- a/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx +++ b/apps/judicial-system/web/src/utils/hooks/useCaseList/index.tsx @@ -10,7 +10,6 @@ import { DEFENDER_ROUTE, } from '@island.is/judicial-system/consts' import { - Feature, isCompletedCase, isCourtOfAppealsUser, isDefenceUser, @@ -20,11 +19,9 @@ import { isPublicProsecutorUser, isRequestCase, isRestrictionCase, - isTrafficViolationCase, } from '@island.is/judicial-system/types' import { errors } from '@island.is/judicial-system-web/messages' import { - FeatureContext, FormContext, UserContext, } from '@island.is/judicial-system-web/src/components' @@ -42,7 +39,6 @@ const useCaseList = () => { >([null, false]) const { user, limitedAccess } = useContext(UserContext) const { getCase } = useContext(FormContext) - const { features } = useContext(FeatureContext) const { formatMessage } = useIntl() const { isTransitioningCase, isSendingNotification } = useCase() const router = useRouter() @@ -50,9 +46,6 @@ const useCaseList = () => { const openCase = useCallback( (caseToOpen: Case, openCaseInNewTab?: boolean) => { let routeTo = null - const isTrafficViolation = - features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || - isTrafficViolationCase(caseToOpen) if (isDefenceUser(user)) { if (isRequestCase(caseToOpen.type)) { @@ -129,7 +122,7 @@ const useCaseList = () => { : constants.CLOSED_INDICTMENT_OVERVIEW_ROUTE } else { routeTo = findFirstInvalidStep( - constants.prosecutorIndictmentRoutes(isTrafficViolation), + constants.prosecutorIndictmentRoutes, caseToOpen, ) } @@ -142,7 +135,7 @@ const useCaseList = () => { router.push(`${routeTo}/${caseToOpen.id}`) } }, - [router, user, features], + [router, user], ) const handleOpenCase = useCallback( diff --git a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts index 350595015b5f..f365d1b50fc9 100644 --- a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts @@ -8,7 +8,6 @@ import { getAppealResultTextByValue, } from '@island.is/judicial-system/formatters' import { - Feature, isCompletedCase, isCourtOfAppealsUser, isDefenceUser, @@ -17,7 +16,6 @@ import { isInvestigationCase, isProsecutionUser, isRestrictionCase, - isTrafficViolationCase, } from '@island.is/judicial-system/types' import { core, sections } from '@island.is/judicial-system-web/messages' import { FeatureContext } from '@island.is/judicial-system-web/src/components' @@ -406,9 +404,6 @@ const useSections = ( state === CaseState.RECEIVED || state === CaseState.WAITING_FOR_CANCELLATION || router.pathname === `${constants.INDICTMENTS_ADD_FILES_ROUTE}/[id]` - const isTrafficViolation = - features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || - isTrafficViolationCase(workingCase) return { name: formatMessage(sections.indictmentCaseProsecutorSection.title), @@ -505,39 +500,31 @@ const useSections = ( ) : undefined, }, - ...(isTrafficViolation - ? [ - { - name: formatMessage( - sections.indictmentCaseProsecutorSection.indictment, - ), - href: `${constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE}/${id}`, - isActive: isActive( - constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE, - ), - onClick: - !isActive( + { + name: formatMessage( + sections.indictmentCaseProsecutorSection.indictment, + ), + href: `${constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE}/${id}`, + isActive: isActive(constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE), + onClick: + !isActive(constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE) && + validateFormStepper( + isValid, + [ + constants.INDICTMENTS_DEFENDANT_ROUTE, + constants.INDICTMENTS_POLICE_CASE_FILES_ROUTE, + constants.INDICTMENTS_CASE_FILE_ROUTE, + constants.INDICTMENTS_PROCESSING_ROUTE, + ], + workingCase, + ) && + onNavigationTo + ? async () => + await onNavigationTo( constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE, - ) && - validateFormStepper( - isValid, - [ - constants.INDICTMENTS_DEFENDANT_ROUTE, - constants.INDICTMENTS_POLICE_CASE_FILES_ROUTE, - constants.INDICTMENTS_CASE_FILE_ROUTE, - constants.INDICTMENTS_PROCESSING_ROUTE, - ], - workingCase, - ) && - onNavigationTo - ? async () => - await onNavigationTo( - constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE, - ) - : undefined, - }, - ] - : []), + ) + : undefined, + }, { name: capitalize( formatMessage( diff --git a/libs/judicial-system/consts/src/lib/consts.ts b/libs/judicial-system/consts/src/lib/consts.ts index 90c4c60196a0..a2dcfaeb522f 100644 --- a/libs/judicial-system/consts/src/lib/consts.ts +++ b/libs/judicial-system/consts/src/lib/consts.ts @@ -225,12 +225,12 @@ export const prosecutorInvestigationCasesRoutes = [ INVESTIGATION_CASE_POLICE_CONFIRMATION_ROUTE, ] -export const prosecutorIndictmentRoutes = (isTrafficViolation: boolean) => [ +export const prosecutorIndictmentRoutes = [ INDICTMENTS_DEFENDANT_ROUTE, INDICTMENTS_POLICE_CASE_FILES_ROUTE, INDICTMENTS_CASE_FILE_ROUTE, INDICTMENTS_PROCESSING_ROUTE, - ...(isTrafficViolation ? [INDICTMENTS_TRAFFIC_VIOLATION_ROUTE] : []), + INDICTMENTS_TRAFFIC_VIOLATION_ROUTE, INDICTMENTS_CASE_FILES_ROUTE, INDICTMENTS_OVERVIEW_ROUTE, ] From b86e4ab214074f0317850411a30440b3ce384a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 12:31:54 +0000 Subject: [PATCH 31/68] Remove isTrafficViolationCase checks --- .../IndictmentCaseFilesList.tsx | 10 +-- .../Indictments/CaseFiles/CaseFiles.tsx | 78 ++++--------------- .../Indictments/Processing/Processing.tsx | 19 +---- .../web/src/utils/formHelper.ts | 3 +- .../judicial-system/web/src/utils/validate.ts | 14 +--- 5 files changed, 19 insertions(+), 105 deletions(-) diff --git a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx index b9646bc28671..46d0881beeb8 100644 --- a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx +++ b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx @@ -5,7 +5,6 @@ import { AnimatePresence } from 'framer-motion' import { Box, Text } from '@island.is/island-ui/core' import { formatDate } from '@island.is/judicial-system/formatters' import { - Feature, isCompletedCase, isDefenceUser, isDistrictCourtUser, @@ -13,10 +12,8 @@ import { isPublicProsecutor, isPublicProsecutorUser, isSuccessfulServiceStatus, - isTrafficViolationCase, } from '@island.is/judicial-system/types' import { - FeatureContext, FileNotFoundModal, PdfButton, SectionHeading, @@ -73,16 +70,11 @@ const IndictmentCaseFilesList: FC = ({ }) => { const { formatMessage } = useIntl() const { user, limitedAccess } = useContext(UserContext) - const { features } = useContext(FeatureContext) const { onOpen, fileNotFound, dismissFileNotFound } = useFileList({ caseId: workingCase.id, connectedCaseParentId, }) - const showTrafficViolationCaseFiles = - features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || - isTrafficViolationCase(workingCase) - const showSubpoenaPdf = displayGeneratedPDFs && workingCase.defendants?.some( @@ -134,7 +126,7 @@ const IndictmentCaseFilesList: FC = ({ )} - {showTrafficViolationCaseFiles && displayGeneratedPDFs && ( + {displayGeneratedPDFs && ( {formatMessage(caseFiles.indictmentSection)} diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx index e10112fd8b4e..eac947d0a0dd 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx @@ -5,13 +5,8 @@ import router from 'next/router' import { Box, InputFileUpload } from '@island.is/island-ui/core' import { fileExtensionWhitelist } from '@island.is/island-ui/core/types' import * as constants from '@island.is/judicial-system/consts' -import { - Feature, - isTrafficViolationCase, -} from '@island.is/judicial-system/types' import { titles } from '@island.is/judicial-system-web/messages' import { - FeatureContext, FormContentContainer, FormContext, FormFooter, @@ -33,7 +28,6 @@ import * as strings from './CaseFiles.strings' const CaseFiles = () => { const { workingCase, isLoadingWorkingCase, caseNotFound } = useContext(FormContext) - const { features } = useContext(FeatureContext) const { formatMessage } = useIntl() const { uploadFiles, @@ -46,18 +40,11 @@ const CaseFiles = () => { workingCase.id, ) - const isTrafficViolationCaseCheck = - features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || - isTrafficViolationCase(workingCase) - const stepIsValid = - (isTrafficViolationCaseCheck || - uploadFiles.some( - (file) => - file.category === CaseFileCategory.INDICTMENT && - file.status === 'done', - )) && - allFilesDoneOrError + uploadFiles.some( + (file) => + file.category === CaseFileCategory.INDICTMENT && file.status === 'done', + ) && allFilesDoneOrError const handleNavigationTo = useCallback( (destination: string) => router.push(`${destination}/${workingCase.id}`), [workingCase.id], @@ -77,32 +64,6 @@ const CaseFiles = () => { {formatMessage(strings.caseFiles.heading)} - {!isTrafficViolationCaseCheck && ( - - - file.category === CaseFileCategory.INDICTMENT, - )} - accept={Object.values(fileExtensionWhitelist)} - header={formatMessage(strings.caseFiles.inputFieldLabel)} - buttonLabel={formatMessage(strings.caseFiles.buttonLabel)} - onChange={(files) => - handleUpload( - addUploadFiles(files, { - category: CaseFileCategory.INDICTMENT, - }), - updateUploadFile, - ) - } - onRemove={(file) => handleRemove(file, removeUploadFile)} - onRetry={(file) => handleRetry(file, updateUploadFile)} - /> - - )} { { /> {workingCase.hasCivilClaims && ( - + @@ -203,24 +159,18 @@ const CaseFiles = () => { /> )} - {isTrafficViolationCaseCheck && ( - - - - )} + + + handleNavigationTo(constants.INDICTMENTS_OVERVIEW_ROUTE) } diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx index f85025b8c9b6..c85904016900 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx @@ -10,16 +10,11 @@ import { Text, } from '@island.is/island-ui/core' import * as constants from '@island.is/judicial-system/consts' -import { - AdvocateType, - Feature, - isTrafficViolationCase, -} from '@island.is/judicial-system/types' +import { AdvocateType } from '@island.is/judicial-system/types' import { core, titles } from '@island.is/judicial-system-web/messages' import { BlueBox, CommentsInput, - FeatureContext, FormContentContainer, FormContext, FormFooter, @@ -65,7 +60,6 @@ const Processing: FC = () => { isCaseUpToDate, refreshCase, } = useContext(FormContext) - const { features } = useContext(FeatureContext) const { updateCase, transitionCase, setAndSendCaseToServer } = useCase() const { formatMessage } = useIntl() const { updateDefendant, updateDefendantState } = useDefendants() @@ -76,9 +70,6 @@ const Processing: FC = () => { deleteCivilClaimant, } = useCivilClaimants() const router = useRouter() - const isTrafficViolationCaseCheck = - features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) || - isTrafficViolationCase(workingCase) const [civilClaimantNationalIdUpdate, setCivilClaimantNationalIdUpdate] = useState<{ nationalId: string | null; civilClaimantId: string }>() const [hasCivilClaimantChoice, setHasCivilClaimantChoice] = @@ -667,13 +658,7 @@ const Processing: FC = () => { nextButtonIcon="arrowForward" previousUrl={`${constants.INDICTMENTS_CASE_FILE_ROUTE}/${workingCase.id}`} nextIsDisabled={!stepIsValid} - onNextButtonClick={() => - handleNavigationTo( - isTrafficViolationCaseCheck - ? constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE - : constants.INDICTMENTS_CASE_FILES_ROUTE, - ) - } + nextUrl={constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE} /> diff --git a/apps/judicial-system/web/src/utils/formHelper.ts b/apps/judicial-system/web/src/utils/formHelper.ts index 18ad816407aa..4e319b1fc5b4 100644 --- a/apps/judicial-system/web/src/utils/formHelper.ts +++ b/apps/judicial-system/web/src/utils/formHelper.ts @@ -253,8 +253,7 @@ export const stepValidations = (): stepValidationsType => { validations.isProcessingStepValidIndictments(theCase), [constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE]: (theCase: Case) => validations.isTrafficViolationStepValidIndictments(theCase), - [constants.INDICTMENTS_CASE_FILES_ROUTE]: (theCase) => - validations.isCaseFilesStepValidIndictments(theCase), + [constants.INDICTMENTS_CASE_FILES_ROUTE]: () => true, [constants.INDICTMENTS_SUMMARY_ROUTE]: () => true, [constants.RESTRICTION_CASE_RECEPTION_AND_ASSIGNMENT_ROUTE]: ( theCase: Case, diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index b8eb1ea90228..cc626ef01ad4 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -1,8 +1,5 @@ // TODO: Add tests -import { - isIndictmentCase, - isTrafficViolationCase, -} from '@island.is/judicial-system/types' +import { isIndictmentCase } from '@island.is/judicial-system/types' import { CaseAppealRulingDecision, CaseAppealState, @@ -590,12 +587,3 @@ export const isCourtOfAppealWithdrawnCaseStepValid = ( [workingCase.appealCaseNumber, ['empty', 'appeal-case-number-format']], ]).isValid } - -export const isCaseFilesStepValidIndictments = (workingCase: Case): boolean => { - return Boolean( - isTrafficViolationCase(workingCase) || - workingCase.caseFiles?.some( - (file) => file.category === CaseFileCategory.INDICTMENT, - ), - ) -} From ce9d87bac4fb815086410d49d7ea691d1960d2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 13:24:14 +0000 Subject: [PATCH 32/68] Remove isTrafficViolationCase checks --- .../src/app/modules/case/case.service.ts | 13 +++--- .../app/modules/case/internalCase.service.ts | 40 ++++--------------- .../app/modules/subpoena/subpoena.service.ts | 25 +----------- .../Indictment/IndictmentCount.tsx | 13 +++++- libs/judicial-system/types/src/index.ts | 1 - libs/judicial-system/types/src/lib/case.ts | 31 -------------- 6 files changed, 24 insertions(+), 99 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index 36304e74cd44..1f3abe70b9f8 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -46,7 +46,6 @@ import { isCompletedCase, isIndictmentCase, isRequestCase, - isTrafficViolationCase, notificationTypes, StringType, stringTypes, @@ -799,13 +798,11 @@ export class CaseService { deliverCaseFileToCourtMessages, ) - if (isTrafficViolationCase(theCase)) { - messages.push({ - type: MessageType.DELIVERY_TO_COURT_INDICTMENT, - user, - caseId: theCase.id, - }) - } + messages.push({ + type: MessageType.DELIVERY_TO_COURT_INDICTMENT, + user, + caseId: theCase.id, + }) if (theCase.state === CaseState.WAITING_FOR_CANCELLATION) { messages.push({ diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index 729645bb5f82..1bbeb70e19b9 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -32,7 +32,6 @@ import { isProsecutionUser, isRequestCase, isRestrictionCase, - isTrafficViolationCase, NotificationType, restrictionCases, type User as TUser, @@ -1020,39 +1019,14 @@ export class InternalCaseService { user: TUser, ): Promise { try { - let policeDocuments: PoliceDocument[] + const file = await this.pdfService.getIndictmentPdf(theCase) - if (isTrafficViolationCase(theCase)) { - const file = await this.pdfService.getIndictmentPdf(theCase) - - policeDocuments = [ - { - type: PoliceDocumentType.RVAS, - courtDocument: Base64.btoa(file.toString('binary')), - }, - ] - } else { - policeDocuments = await Promise.all( - theCase.caseFiles - ?.filter( - (caseFile) => - caseFile.category === CaseFileCategory.INDICTMENT && - caseFile.key, - ) - .map(async (caseFile) => { - // TODO: Tolerate failure, but log error - const file = await this.fileService.getCaseFileFromS3( - theCase, - caseFile, - ) - - return { - type: PoliceDocumentType.RVAS, - courtDocument: Base64.btoa(file.toString('binary')), - } - }) ?? [], - ) - } + const policeDocuments = [ + { + type: PoliceDocumentType.RVAS, + courtDocument: Base64.btoa(file.toString('binary')), + }, + ] const delivered = await this.deliverCaseToPoliceWithFiles( theCase, diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts index e2d3116d4aa5..f1761e3eef2b 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts @@ -20,10 +20,8 @@ import { MessageType, } from '@island.is/judicial-system/message' import { - CaseFileCategory, isFailedServiceStatus, isSuccessfulServiceStatus, - isTrafficViolationCase, ServiceStatus, SubpoenaNotificationType, type User as TUser, @@ -283,27 +281,6 @@ export class SubpoenaService { return subpoena } - async getIndictmentPdf(theCase: Case): Promise { - if (isTrafficViolationCase(theCase)) { - return await this.pdfService.getIndictmentPdf(theCase) - } - - const indictmentCaseFile = theCase.caseFiles?.find( - (caseFile) => - caseFile.category === CaseFileCategory.INDICTMENT && caseFile.key, - ) - - if (!indictmentCaseFile) { - // This shouldn't ever happen - this.logger.error( - `No indictment found for case ${theCase.id} so cannot deliver subpoena to police`, - ) - throw new Error(`No indictment found for case ${theCase.id}`) - } - - return await this.fileService.getCaseFileFromS3(theCase, indictmentCaseFile) - } - async deliverSubpoenaToPolice( theCase: Case, defendant: Defendant, @@ -317,7 +294,7 @@ export class SubpoenaService { subpoena, ) - const indictmentPdf = await this.getIndictmentPdf(theCase) + const indictmentPdf = await this.pdfService.getIndictmentPdf(theCase) const createdSubpoena = await this.policeService.createSubpoena( theCase, diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index cc145bdfb6d8..ca2ade21d276 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -19,7 +19,6 @@ import { import { CrimeScene, IndictmentSubtype, - isTrafficViolationCase, offenseSubstances, Substance, SubstanceMap, @@ -469,6 +468,16 @@ export const IndictmentCount: FC = ({ }) } + const hasSingleSubtype = hasOnlyOneItemInSubArrays(subtypes) + + const singleSubType = + (indictmentCount.policeCaseNumber && + subtypes?.[indictmentCount.policeCaseNumber]?.[0]) || + undefined + + const trafficViolationSubtype = + singleSubType === IndictmentSubtype.TRAFFIC_VIOLATION + return ( {onDelete && ( @@ -561,7 +570,7 @@ export const IndictmentCount: FC = ({ )} - {(isTrafficViolationCase(workingCase) || + {((hasSingleSubtype && trafficViolationSubtype) || (indictmentCount?.indictmentCountSubtypes?.includes( IndictmentSubtype.TRAFFIC_VIOLATION, ) ?? diff --git a/libs/judicial-system/types/src/index.ts b/libs/judicial-system/types/src/index.ts index 82a11272ee06..76fc89387cb0 100644 --- a/libs/judicial-system/types/src/index.ts +++ b/libs/judicial-system/types/src/index.ts @@ -86,7 +86,6 @@ export { isInvestigationCase, isRequestCase, isAcceptingCaseDecision, - isTrafficViolationCase, completedRequestCaseStates, completedIndictmentCaseStates, completedCaseStates, diff --git a/libs/judicial-system/types/src/lib/case.ts b/libs/judicial-system/types/src/lib/case.ts index 25beea51adcf..e6595bd0e264 100644 --- a/libs/judicial-system/types/src/lib/case.ts +++ b/libs/judicial-system/types/src/lib/case.ts @@ -1,7 +1,3 @@ -import flatten from 'lodash/flatten' - -import { CaseFileCategory } from './file' - export enum CaseOrigin { UNKNOWN = 'UNKNOWN', RVG = 'RVG', @@ -371,33 +367,6 @@ export const hasIndictmentCaseBeenSubmittedToCourt = ( ) } -export const isTrafficViolationCase = (theCase: { - type?: CaseType | null - indictmentSubtypes?: IndictmentSubtypeMap - caseFiles?: { category?: CaseFileCategory | null }[] | null -}): boolean => { - if ( - theCase.type !== CaseType.INDICTMENT || - !theCase.indictmentSubtypes || - theCase.caseFiles?.some( - (file) => file.category === CaseFileCategory.INDICTMENT, - ) - ) { - return false - } - - const flatIndictmentSubtypes = flatten( - Object.values(theCase.indictmentSubtypes), - ) - - return ( - flatIndictmentSubtypes.length > 0 && - flatIndictmentSubtypes.every( - (val) => val === IndictmentSubtype.TRAFFIC_VIOLATION, - ) - ) -} - export const getStatementDeadline = (appealReceived: Date): string => { return new Date( new Date(appealReceived).setDate(appealReceived.getDate() + 1), From e6f2ccbb7e83ede33719b698dae10b14860937d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 13:30:06 +0000 Subject: [PATCH 33/68] Remove feature flag --- apps/judicial-system/api/infra/judicial-system-api.ts | 4 ++-- charts/judicial-system/values.prod.yaml | 2 +- charts/judicial-system/values.staging.yaml | 2 +- libs/judicial-system/types/src/lib/feature.ts | 1 - 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/judicial-system/api/infra/judicial-system-api.ts b/apps/judicial-system/api/infra/judicial-system-api.ts index 8f5cabe11e2c..efe736fa005b 100644 --- a/apps/judicial-system/api/infra/judicial-system-api.ts +++ b/apps/judicial-system/api/infra/judicial-system-api.ts @@ -47,8 +47,8 @@ export const serviceSetup = (services: { }, HIDDEN_FEATURES: { dev: '', - staging: 'MULTIPLE_INDICTMENT_SUBTYPES', - prod: 'MULTIPLE_INDICTMENT_SUBTYPES', + staging: '', + prod: '', }, }) .secrets({ diff --git a/charts/judicial-system/values.prod.yaml b/charts/judicial-system/values.prod.yaml index e0747b1254c4..4546f7547272 100644 --- a/charts/judicial-system/values.prod.yaml +++ b/charts/judicial-system/values.prod.yaml @@ -30,7 +30,7 @@ judicial-system-api: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'master' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' + HIDDEN_FEATURES: '' IDENTITY_SERVER_ISSUER_URL: 'https://innskra.island.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/charts/judicial-system/values.staging.yaml b/charts/judicial-system/values.staging.yaml index e6b543a61ce6..396f358fcac6 100644 --- a/charts/judicial-system/values.staging.yaml +++ b/charts/judicial-system/values.staging.yaml @@ -30,7 +30,7 @@ judicial-system-api: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'test' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' + HIDDEN_FEATURES: '' IDENTITY_SERVER_ISSUER_URL: 'https://identity-server.staging01.devland.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/libs/judicial-system/types/src/lib/feature.ts b/libs/judicial-system/types/src/lib/feature.ts index dd8f5e437a8f..742e56c2f145 100644 --- a/libs/judicial-system/types/src/lib/feature.ts +++ b/libs/judicial-system/types/src/lib/feature.ts @@ -1,4 +1,3 @@ export enum Feature { NONE = 'NONE', // must be at least one - MULTIPLE_INDICTMENT_SUBTYPES = 'MULTIPLE_INDICTMENT_SUBTYPES', } From b532f1b469fd6a222080c0b60cdf01f91af54c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Fri, 13 Dec 2024 14:51:02 +0000 Subject: [PATCH 34/68] Remove code related to CaseFileCategory INDICTMENT --- .../IndictmentCaseFilesList.tsx | 11 ----------- .../Prosecutor/Indictments/CaseFiles/CaseFiles.tsx | 6 +----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx index 46d0881beeb8..d72210b03dfa 100644 --- a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx +++ b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx @@ -83,9 +83,6 @@ const IndictmentCaseFilesList: FC = ({ const cf = workingCase.caseFiles - const indictments = cf?.filter( - (file) => file.category === CaseFileCategory.INDICTMENT, - ) const criminalRecords = cf?.filter( (file) => file.category === CaseFileCategory.CRIMINAL_RECORD, ) @@ -118,14 +115,6 @@ const IndictmentCaseFilesList: FC = ({ {displayHeading && ( )} - {indictments && indictments.length > 0 && ( - - - {formatMessage(caseFiles.indictmentSection)} - - - - )} {displayGeneratedPDFs && ( diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx index eac947d0a0dd..15110a97727d 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx @@ -40,11 +40,7 @@ const CaseFiles = () => { workingCase.id, ) - const stepIsValid = - uploadFiles.some( - (file) => - file.category === CaseFileCategory.INDICTMENT && file.status === 'done', - ) && allFilesDoneOrError + const stepIsValid = allFilesDoneOrError const handleNavigationTo = useCallback( (destination: string) => router.push(`${destination}/${workingCase.id}`), [workingCase.id], From 07c846718f0669e7d61e0d3e5cd20377c906cb66 Mon Sep 17 00:00:00 2001 From: andes-it Date: Fri, 13 Dec 2024 15:01:38 +0000 Subject: [PATCH 35/68] chore: charts update dirty files --- charts/services/judicial-system-api/values.prod.yaml | 2 +- charts/services/judicial-system-api/values.staging.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/services/judicial-system-api/values.prod.yaml b/charts/services/judicial-system-api/values.prod.yaml index 05f04f9d7278..2143dcd8565b 100644 --- a/charts/services/judicial-system-api/values.prod.yaml +++ b/charts/services/judicial-system-api/values.prod.yaml @@ -30,7 +30,7 @@ env: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'master' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' + HIDDEN_FEATURES: '' IDENTITY_SERVER_ISSUER_URL: 'https://innskra.island.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' diff --git a/charts/services/judicial-system-api/values.staging.yaml b/charts/services/judicial-system-api/values.staging.yaml index 8ec818a14e50..6ba09a9624d6 100644 --- a/charts/services/judicial-system-api/values.staging.yaml +++ b/charts/services/judicial-system-api/values.staging.yaml @@ -30,7 +30,7 @@ env: BACKEND_URL: 'http://web-judicial-system-backend' CONTENTFUL_ENVIRONMENT: 'test' CONTENTFUL_HOST: 'cdn.contentful.com' - HIDDEN_FEATURES: 'MULTIPLE_INDICTMENT_SUBTYPES' + HIDDEN_FEATURES: '' IDENTITY_SERVER_ISSUER_URL: 'https://identity-server.staging01.devland.is' LOG_LEVEL: 'info' NODE_OPTIONS: '--max-old-space-size=460 -r dd-trace/init' From 203f63882540b697d3284385cf3c51b587b061c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 16 Dec 2024 20:42:01 +0000 Subject: [PATCH 36/68] Rename import -- stepHelper to utils --- .../web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx index 912472562aca..f24308e2417e 100644 --- a/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx +++ b/apps/judicial-system/web/src/routes/CourtOfAppeal/Summary/Summary.spec.tsx @@ -13,7 +13,7 @@ import { FormContextWrapper, IntlProviderWrapper, } from '@island.is/judicial-system-web/src/utils/testHelpers' -import * as stepHelper from '@island.is/judicial-system-web/src/utils/utils' +import * as utils from '@island.is/judicial-system-web/src/utils/utils' import Summary from './Summary' @@ -70,7 +70,7 @@ describe('Summary', () => { it('should show a modal window when the appeal ruling is modified', async () => { const caseId = faker.datatype.uuid() jest - .spyOn(stepHelper, 'hasSentNotification') + .spyOn(utils, 'hasSentNotification') .mockReturnValue({ hasSent: true, date: null }) render( From 290c4bfa90ad51ce1043aaca52daf90fb77b758e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 16 Dec 2024 20:53:11 +0000 Subject: [PATCH 37/68] Break down a complex ternary statement into if statemetns --- .../judicial-system/web/src/utils/validate.ts | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index b8eb1ea90228..0ddae6c77615 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -297,16 +297,27 @@ export const isProcessingStepValidIndictments = ( export const isTrafficViolationStepValidIndictments = ( workingCase: Case, ): boolean => { - return Boolean( - hasOnlyOneItemInSubArrays(workingCase.indictmentSubtypes) || - (workingCase.indictmentCounts?.every( - (indictmentCount) => - indictmentCount.indictmentCountSubtypes && - indictmentCount.indictmentCountSubtypes?.length > 0, - ) && - workingCase.demands && - (!workingCase.hasCivilClaims || workingCase.civilDemands)), + if (!workingCase.indictmentSubtypes) { + return false + } + + if (hasOnlyOneItemInSubArrays(workingCase.indictmentSubtypes)) { + return true + } + + const hasValidIndictmentCounts = + workingCase.indictmentCounts?.every( + (indictmentCount) => + indictmentCount.indictmentCountSubtypes && + indictmentCount.indictmentCountSubtypes.length > 0, + ) ?? false + + const hasValidDemands = Boolean( + workingCase.demands && + (!workingCase.hasCivilClaims || workingCase.civilDemands), ) + + return hasValidIndictmentCounts && hasValidDemands } export const isPoliceDemandsStepValidRC = (workingCase: Case): boolean => { From 2cc996fc8bdbd625e5e15d9a7711f293d4ee278c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 16 Dec 2024 21:10:50 +0000 Subject: [PATCH 38/68] Improve validation on indictment screen --- apps/judicial-system/web/src/utils/validate.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 0ddae6c77615..8d41ab267a10 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -302,7 +302,19 @@ export const isTrafficViolationStepValidIndictments = ( } if (hasOnlyOneItemInSubArrays(workingCase.indictmentSubtypes)) { - return true + const hasValidTrafficViolationIndictmentCounts = + workingCase.indictmentCounts?.every( + (indictmentCount) => + indictmentCount.policeCaseNumber && + indictmentCount.offenses && + indictmentCount.offenses?.length > 0 && + indictmentCount.vehicleRegistrationNumber && + indictmentCount.lawsBroken && + indictmentCount.incidentDescription && + indictmentCount.legalArguments, + ) ?? false + + return hasValidTrafficViolationIndictmentCounts } const hasValidIndictmentCounts = From ebabc90ddaea2a6ed842f9b359ff38b5176cda03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 17 Dec 2024 13:38:08 +0000 Subject: [PATCH 39/68] Improve type safety --- .../Prosecutor/Indictments/Indictment/IndictmentCount.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index cc145bdfb6d8..ce7af0000e55 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -384,7 +384,7 @@ export const IndictmentCount: FC = ({ const [legalArgumentsErrorMessage, setLegalArgumentsErrorMessage] = useState('') - const subtypes = indictmentCount.policeCaseNumber + const subtypes: IndictmentSubtype[] = indictmentCount.policeCaseNumber ? workingCase.indictmentSubtypes[indictmentCount.policeCaseNumber] : [] From 4dd6cd300f7bf2a07c7b4d305fb2acab7b1dfdd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 17 Dec 2024 14:18:49 +0000 Subject: [PATCH 40/68] Remove unused code --- .../Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 20e54c567c67..d7fe3c28b7e2 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -214,13 +214,15 @@ export const PoliceCaseInfo: FC = ({ label={formatMessage(policeCaseInfo.indictmentTypeLabel)} placeholder={formatMessage(policeCaseInfo.indictmentTypePlaceholder)} onChange={(selectedOption) => { - const indictmentSubtype = selectedOption?.value as IndictmentSubtype + const indictmentSubtype = selectedOption?.value - updatePoliceCase(index, { - subtypes: [...subtypesArray, indictmentSubtype], - }) + if (!indictmentSubtype) { + return + } + + const subtypes = [...subtypesArray, indictmentSubtype] - updateIndictmentCount(policeCaseNumbers[index], crimeScene || {}) + updatePoliceCase(index, { subtypes }) }} value={null} required From 7903f24dfeae7da611ec8f5e47a7658482a440c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 17 Dec 2024 14:29:56 +0000 Subject: [PATCH 41/68] Refactor util --- .../Indictment/IndictmentCount.tsx | 4 ++-- .../web/src/utils/utils.spec.tsx | 10 +++++----- apps/judicial-system/web/src/utils/utils.ts | 20 +++++++++---------- .../judicial-system/web/src/utils/validate.ts | 4 ++-- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index ce7af0000e55..c9ce3332af04 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -42,7 +42,7 @@ import { UpdateIndictmentCount, useIndictmentCounts, } from '@island.is/judicial-system-web/src/utils/hooks' -import { hasOnlyOneItemInSubArrays } from '@island.is/judicial-system-web/src/utils/utils' +import { hasOnlyOneItemValues } from '@island.is/judicial-system-web/src/utils/utils' import { Substances as SubstanceChoices } from './Substances/Substances' import { indictmentCount as strings } from './IndictmentCount.strings' @@ -307,7 +307,7 @@ export const getIncidentDescription = ( const vehicleRegistration = vehicleRegistrationNumber || '[Skráningarnúmer ökutækis]' - const hasSingleSubtype = hasOnlyOneItemInSubArrays(subtypes) + const hasSingleSubtype = hasOnlyOneItemValues(subtypes) const singleSubType = (policeCaseNumber && subtypes?.[policeCaseNumber]?.[0]) || undefined diff --git a/apps/judicial-system/web/src/utils/utils.spec.tsx b/apps/judicial-system/web/src/utils/utils.spec.tsx index 86db8ab12d66..ae4e851090f4 100644 --- a/apps/judicial-system/web/src/utils/utils.spec.tsx +++ b/apps/judicial-system/web/src/utils/utils.spec.tsx @@ -14,7 +14,7 @@ import { validateAndSendToServer } from './formHelper' import { getAppealEndDate, getShortGender, - hasOnlyOneItemInSubArrays, + hasOnlyOneItemValues, hasSentNotification, } from './utils' @@ -452,7 +452,7 @@ describe('Utils', () => { } // Act - const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + const result = hasOnlyOneItemValues(indictmentSubtypes) // Assert expect(result).toEqual(true) @@ -466,7 +466,7 @@ describe('Utils', () => { } // Act - const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + const result = hasOnlyOneItemValues(indictmentSubtypes) // Assert expect(result).toEqual(false) @@ -477,7 +477,7 @@ describe('Utils', () => { const indictmentSubtypes: Record = {} // Act - const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + const result = hasOnlyOneItemValues(indictmentSubtypes) // Assert expect(result).toEqual(false) @@ -491,7 +491,7 @@ describe('Utils', () => { } // Act - const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + const result = hasOnlyOneItemValues(indictmentSubtypes) // Assert expect(result).toEqual(false) diff --git a/apps/judicial-system/web/src/utils/utils.ts b/apps/judicial-system/web/src/utils/utils.ts index 09a76128da2e..21de22262960 100644 --- a/apps/judicial-system/web/src/utils/utils.ts +++ b/apps/judicial-system/web/src/utils/utils.ts @@ -149,28 +149,26 @@ export const shouldUseAppealWithdrawnRoutes = (theCase: Case): boolean => { } /** - * Returns true if all subarrays in the given object have only one item. + * Returns true if all values in the given object have only one item. * * Example: - * const indictmentSubtypes = { + * const items = { * '123-123-123': ['item1'], * '234-234-234': ['item2'] * } * - * const result = hasOnlyOneItemInSubArrays(indictmentSubtypes) + * const result = hasOnlyOneItemValues(items) * console.log(result) // true * - * @param indictmentSubtypes - The object containing the subarrays to check. - * @returns {boolean} - True if all subarrays have only one item, false otherwise. + * @param items - The object containing the subarrays to check. + * @returns {boolean} - True if all values have only one item, false otherwise. */ -export const hasOnlyOneItemInSubArrays = ( - indictmentSubtypes?: Record, +export const hasOnlyOneItemValues = ( + items?: Record, ): boolean => { - if (!indictmentSubtypes || Object.keys(indictmentSubtypes).length === 0) { + if (!items || Object.keys(items).length === 0) { return false } - return Object.values(indictmentSubtypes).every( - (subArray) => subArray.length === 1, - ) + return Object.values(items).every((subArray) => subArray.length === 1) } diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 8d41ab267a10..8ba2988d7739 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -17,7 +17,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' -import { hasOnlyOneItemInSubArrays, isBusiness } from './utils' +import { hasOnlyOneItemValues, isBusiness } from './utils' export type Validation = | 'empty' @@ -301,7 +301,7 @@ export const isTrafficViolationStepValidIndictments = ( return false } - if (hasOnlyOneItemInSubArrays(workingCase.indictmentSubtypes)) { + if (hasOnlyOneItemValues(workingCase.indictmentSubtypes)) { const hasValidTrafficViolationIndictmentCounts = workingCase.indictmentCounts?.every( (indictmentCount) => From 0927926566112ea5b6042dc5bc3b1abec09929ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 17 Dec 2024 14:39:25 +0000 Subject: [PATCH 42/68] Cleanup state on remove traffic violation --- .../Prosecutor/Indictments/Indictment/IndictmentCount.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index c9ce3332af04..9ad169c57981 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -465,6 +465,8 @@ export const IndictmentCount: FC = ({ indictmentCountSubtypes: Array.from(currentSubtypes), ...(!currentSubtypes.has(IndictmentSubtype.TRAFFIC_VIOLATION) && { offenses: [], + substances: {}, + vehicleRegistrationNumber: null, }), }) } From d489b56f06926fdcb62cc48a1bcb9c1cd3ef98c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 17 Dec 2024 15:26:22 +0000 Subject: [PATCH 43/68] Improve validation --- .../judicial-system/web/src/utils/validate.ts | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 8ba2988d7739..3407c65ee859 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -1,5 +1,6 @@ // TODO: Add tests import { + IndictmentSubtype, isIndictmentCase, isTrafficViolationCase, } from '@island.is/judicial-system/types' @@ -11,6 +12,7 @@ import { CaseType, DateLog, DefenderChoice, + IndictmentCount, IndictmentDecision, SessionArrangements, User, @@ -18,6 +20,7 @@ import { import { TempCase as Case } from '@island.is/judicial-system-web/src/types' import { hasOnlyOneItemValues, isBusiness } from './utils' +import { indictmentCount } from '../routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings' export type Validation = | 'empty' @@ -297,22 +300,41 @@ export const isProcessingStepValidIndictments = ( export const isTrafficViolationStepValidIndictments = ( workingCase: Case, ): boolean => { - if (!workingCase.indictmentSubtypes) { + const hasValidDemands = Boolean( + workingCase.demands && + (!workingCase.hasCivilClaims || workingCase.civilDemands), + ) + + if (!workingCase.indictmentSubtypes || !hasValidDemands) { return false } - if (hasOnlyOneItemValues(workingCase.indictmentSubtypes)) { + const validateIndictmentCount = (indictmentCount: IndictmentCount) => + indictmentCount.policeCaseNumber && + indictmentCount.offenses && + indictmentCount.offenses?.length > 0 && + indictmentCount.vehicleRegistrationNumber && + indictmentCount.lawsBroken && + indictmentCount.incidentDescription && + indictmentCount.legalArguments + + const trafficViolationIndictmentCounts = + workingCase.indictmentCounts?.filter((indictmentCount) => + indictmentCount.indictmentCountSubtypes?.includes( + IndictmentSubtype.TRAFFIC_VIOLATION, + ), + ) ?? [] + + if (isTrafficViolationCase(workingCase)) { const hasValidTrafficViolationIndictmentCounts = - workingCase.indictmentCounts?.every( - (indictmentCount) => - indictmentCount.policeCaseNumber && - indictmentCount.offenses && - indictmentCount.offenses?.length > 0 && - indictmentCount.vehicleRegistrationNumber && - indictmentCount.lawsBroken && - indictmentCount.incidentDescription && - indictmentCount.legalArguments, - ) ?? false + workingCase.indictmentCounts?.every(validateIndictmentCount) ?? false + + return hasValidTrafficViolationIndictmentCounts + } + + if (trafficViolationIndictmentCounts.length > 0) { + const hasValidTrafficViolationIndictmentCounts = + trafficViolationIndictmentCounts.every(validateIndictmentCount) ?? false return hasValidTrafficViolationIndictmentCounts } @@ -324,11 +346,6 @@ export const isTrafficViolationStepValidIndictments = ( indictmentCount.indictmentCountSubtypes.length > 0, ) ?? false - const hasValidDemands = Boolean( - workingCase.demands && - (!workingCase.hasCivilClaims || workingCase.civilDemands), - ) - return hasValidIndictmentCounts && hasValidDemands } From ac1525ee00db86e9e30a5a130e330efea9814c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 17 Dec 2024 23:40:17 +0000 Subject: [PATCH 44/68] Refactor validation --- .../judicial-system/web/src/utils/validate.ts | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 3407c65ee859..ace515c31b88 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -21,6 +21,7 @@ import { TempCase as Case } from '@island.is/judicial-system-web/src/types' import { hasOnlyOneItemValues, isBusiness } from './utils' import { indictmentCount } from '../routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings' +import { flatten, partition } from 'lodash' export type Validation = | 'empty' @@ -318,13 +319,7 @@ export const isTrafficViolationStepValidIndictments = ( indictmentCount.incidentDescription && indictmentCount.legalArguments - const trafficViolationIndictmentCounts = - workingCase.indictmentCounts?.filter((indictmentCount) => - indictmentCount.indictmentCountSubtypes?.includes( - IndictmentSubtype.TRAFFIC_VIOLATION, - ), - ) ?? [] - + // All indictment counts are traffic violations if (isTrafficViolationCase(workingCase)) { const hasValidTrafficViolationIndictmentCounts = workingCase.indictmentCounts?.every(validateIndictmentCount) ?? false @@ -332,21 +327,48 @@ export const isTrafficViolationStepValidIndictments = ( return hasValidTrafficViolationIndictmentCounts } - if (trafficViolationIndictmentCounts.length > 0) { - const hasValidTrafficViolationIndictmentCounts = - trafficViolationIndictmentCounts.every(validateIndictmentCount) ?? false + // Some indictment counts are traffic violations while others are not + const [onlyTrafficViolationIndictmentCounts, otherIndictmentCounts] = + partition(workingCase.indictmentCounts, (indictmentCount) => { + const policeCaseNumber = indictmentCount.policeCaseNumber + + if ( + policeCaseNumber && + workingCase.indictmentSubtypes[policeCaseNumber].length === 1 && + workingCase.indictmentSubtypes[policeCaseNumber][0] === + IndictmentSubtype.TRAFFIC_VIOLATION + ) { + return true + } - return hasValidTrafficViolationIndictmentCounts - } + return false + }) + + console.log(onlyTrafficViolationIndictmentCounts, otherIndictmentCounts) + + // Some indictment counts have selected traffic violation while other have not + const [ + indictmentCountsWithSelectedTrafficViolation, + nonTrafficViolationIndictmentCounts, + ] = partition(otherIndictmentCounts, (indictmentCount) => + indictmentCount.indictmentCountSubtypes?.includes( + IndictmentSubtype.TRAFFIC_VIOLATION, + ), + ) + + const isTrafficViolationIndictmentCountsValid = [ + ...onlyTrafficViolationIndictmentCounts, + ...indictmentCountsWithSelectedTrafficViolation, + ].every(validateIndictmentCount) - const hasValidIndictmentCounts = - workingCase.indictmentCounts?.every( + const isOtherIndictmentCountsValid = + nonTrafficViolationIndictmentCounts.every( (indictmentCount) => indictmentCount.indictmentCountSubtypes && indictmentCount.indictmentCountSubtypes.length > 0, - ) ?? false + ) - return hasValidIndictmentCounts && hasValidDemands + return isTrafficViolationIndictmentCountsValid && isOtherIndictmentCountsValid } export const isPoliceDemandsStepValidRC = (workingCase: Case): boolean => { From 42e57cd6e6da87c2421809ec91bc9199f9debc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 09:21:59 +0000 Subject: [PATCH 45/68] Fix imports --- apps/judicial-system/web/src/utils/validate.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index ace515c31b88..7f5138be9d33 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -1,4 +1,6 @@ // TODO: Add tests +import partition from 'lodash/partition' + import { IndictmentSubtype, isIndictmentCase, @@ -19,9 +21,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' -import { hasOnlyOneItemValues, isBusiness } from './utils' -import { indictmentCount } from '../routes/Prosecutor/Indictments/Indictment/IndictmentCount.strings' -import { flatten, partition } from 'lodash' +import { isBusiness } from './utils' export type Validation = | 'empty' From cc95172f2673e66eb81b0d7088e7c8f4efbe6680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 09:22:54 +0000 Subject: [PATCH 46/68] Fix imports --- .../src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx index 54f34ccb9f36..3b7d15b9efc7 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx @@ -30,7 +30,6 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' import { - UpdateIndictmentCount, useCase, useDefendants, useIndictmentCounts, From 629ba490c3b74eb88c44f9065e73c00a0dff559a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 09:24:21 +0000 Subject: [PATCH 47/68] Remove console.log --- apps/judicial-system/web/src/utils/validate.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 7f5138be9d33..cffcc14ce9d3 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -344,8 +344,6 @@ export const isTrafficViolationStepValidIndictments = ( return false }) - console.log(onlyTrafficViolationIndictmentCounts, otherIndictmentCounts) - // Some indictment counts have selected traffic violation while other have not const [ indictmentCountsWithSelectedTrafficViolation, From 3c1a7b482f6e67c95fa035ebf955544f6fb642b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 10:09:55 +0000 Subject: [PATCH 48/68] Fix issue with rendering traffic violation fields --- .../Indictment/IndictmentCount.tsx | 34 ++++++++++++++++--- .../web/src/utils/formHelper.ts | 23 +++++++++++++ .../judicial-system/web/src/utils/validate.ts | 15 +++----- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 9ad169c57981..57232df7de08 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -35,6 +35,7 @@ import { TempIndictmentCount as TIndictmentCount, } from '@island.is/judicial-system-web/src/types' import { + isTrafficViolationIndictmentCount, removeErrorMessageIfValid, validateAndSetErrorMessage, } from '@island.is/judicial-system-web/src/utils/formHelper' @@ -471,6 +472,33 @@ export const IndictmentCount: FC = ({ }) } + const shouldShowTrafficViolationFields = () => { + if (isTrafficViolationCase(workingCase)) { + return true + } + + const policeCaseNumber = indictmentCount.policeCaseNumber + + if ( + isTrafficViolationIndictmentCount( + policeCaseNumber, + workingCase.indictmentSubtypes, + ) + ) { + return true + } + + if ( + indictmentCount?.indictmentCountSubtypes?.includes( + IndictmentSubtype.TRAFFIC_VIOLATION, + ) + ) { + return true + } + + return false + } + return ( {onDelete && ( @@ -563,11 +591,7 @@ export const IndictmentCount: FC = ({ )} - {(isTrafficViolationCase(workingCase) || - (indictmentCount?.indictmentCountSubtypes?.includes( - IndictmentSubtype.TRAFFIC_VIOLATION, - ) ?? - false)) && ( + {shouldShowTrafficViolationFields() && ( <> { return key } + +export const isTrafficViolationIndictmentCount = ( + policeCaseNumber?: string | null, + indictmentSubtypes?: IndictmentSubtypeMap, +) => { + if (!policeCaseNumber || !indictmentSubtypes) { + return false + } + + if ( + indictmentSubtypes[policeCaseNumber].length === 1 && + indictmentSubtypes[policeCaseNumber][0] === + IndictmentSubtype.TRAFFIC_VIOLATION + ) { + return true + } + + return false +} diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index cffcc14ce9d3..a0a2e2ce54aa 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -21,6 +21,7 @@ import { } from '@island.is/judicial-system-web/src/graphql/schema' import { TempCase as Case } from '@island.is/judicial-system-web/src/types' +import { isTrafficViolationIndictmentCount } from './formHelper' import { isBusiness } from './utils' export type Validation = @@ -332,16 +333,10 @@ export const isTrafficViolationStepValidIndictments = ( partition(workingCase.indictmentCounts, (indictmentCount) => { const policeCaseNumber = indictmentCount.policeCaseNumber - if ( - policeCaseNumber && - workingCase.indictmentSubtypes[policeCaseNumber].length === 1 && - workingCase.indictmentSubtypes[policeCaseNumber][0] === - IndictmentSubtype.TRAFFIC_VIOLATION - ) { - return true - } - - return false + return isTrafficViolationIndictmentCount( + policeCaseNumber, + workingCase.indictmentSubtypes, + ) }) // Some indictment counts have selected traffic violation while other have not From f0d558ae3e3299705a433905e2f11aec59f0e966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 10:55:10 +0000 Subject: [PATCH 49/68] Fix issues with autofill --- .../Indictments/Defendant/Defendant.tsx | 8 ++- .../Indictment/IndictmentCount.tsx | 23 +++---- .../web/src/utils/utils.spec.tsx | 62 +------------------ apps/judicial-system/web/src/utils/utils.ts | 25 -------- 4 files changed, 17 insertions(+), 101 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx index 3b7d15b9efc7..5214cd58e3ac 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/Defendant.tsx @@ -114,7 +114,7 @@ const Defendant = () => { } = useDefendants() const router = useRouter() - const { updateIndictmentCount } = useIndictmentCounts() + const { updateIndictmentCount, deleteIndictmentCount } = useIndictmentCounts() const [policeCases, setPoliceCases] = useState([]) @@ -248,6 +248,12 @@ const Defendant = () => { workingCase, setWorkingCase, ) + + const indictmentCountId = workingCase.indictmentCounts?.[index]?.id + + if (indictmentCountId) { + deleteIndictmentCount(workingCase.id, indictmentCountId) + } } const handleUpdatePoliceCase = ( diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx index 57232df7de08..72f3b2eb4bbe 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/IndictmentCount.tsx @@ -43,7 +43,6 @@ import { UpdateIndictmentCount, useIndictmentCounts, } from '@island.is/judicial-system-web/src/utils/hooks' -import { hasOnlyOneItemValues } from '@island.is/judicial-system-web/src/utils/utils' import { Substances as SubstanceChoices } from './Substances/Substances' import { indictmentCount as strings } from './IndictmentCount.strings' @@ -290,7 +289,7 @@ export const getIncidentDescription = ( indictmentCount: TIndictmentCount, formatMessage: IntlShape['formatMessage'], crimeScene?: CrimeScene, - subtypes?: Record, + subtypesRecord?: Record, ) => { const { offenses, @@ -308,23 +307,19 @@ export const getIncidentDescription = ( const vehicleRegistration = vehicleRegistrationNumber || '[Skráningarnúmer ökutækis]' - const hasSingleSubtype = hasOnlyOneItemValues(subtypes) - - const singleSubType = - (policeCaseNumber && subtypes?.[policeCaseNumber]?.[0]) || undefined - - const trafficViolationSubtype = - singleSubType === IndictmentSubtype.TRAFFIC_VIOLATION + const subtypes = + (subtypesRecord && policeCaseNumber && subtypesRecord[policeCaseNumber]) || + [] if ( - !hasSingleSubtype && + subtypes.length > 1 && (!indictmentCountSubtypes?.length || indictmentCountSubtypes.length === 0) ) { return '' } if ( - (hasSingleSubtype && trafficViolationSubtype) || + isTrafficViolationIndictmentCount(policeCaseNumber, subtypesRecord) || (indictmentCountSubtypes?.length === 1 && indictmentCountSubtypes[0] === IndictmentSubtype.TRAFFIC_VIOLATION) ) { @@ -346,9 +341,9 @@ export const getIncidentDescription = ( }) } - if (hasSingleSubtype) { + if (subtypes.length === 1) { return formatMessage(strings.indictmentDescriptionSubtypesAutofill, { - subtypes: singleSubType ? indictmentSubtypes[singleSubType] : '', + subtypes: indictmentSubtypes[subtypes[0]], date: incidentDate, }) } @@ -547,7 +542,7 @@ export const IndictmentCount: FC = ({ /> - {subtypes.length > 1 && ( + {subtypes?.length > 1 && ( <> { describe('Parse time', () => { @@ -442,59 +437,4 @@ describe('Utils', () => { expect(spy).not.toHaveBeenCalled() }) }) - - describe('hasOnlyOneItemInSubArrays', () => { - test('should return true if all subarrays in the given object have only one item', () => { - // Arrange - const indictmentSubtypes = { - '123-123-123': ['item1'], - '234-234-234': ['item2'], - } - - // Act - const result = hasOnlyOneItemValues(indictmentSubtypes) - - // Assert - expect(result).toEqual(true) - }) - - test('should return false if any subarray in the given object has more than one item', () => { - // Arrange - const indictmentSubtypes = { - '123-123-123': ['item1', 'item2'], - '234-234-234': ['item3'], - } - - // Act - const result = hasOnlyOneItemValues(indictmentSubtypes) - - // Assert - expect(result).toEqual(false) - }) - - test('should return false if the given object is empty', () => { - // Arrange - const indictmentSubtypes: Record = {} - - // Act - const result = hasOnlyOneItemValues(indictmentSubtypes) - - // Assert - expect(result).toEqual(false) - }) - - test('should return false if any subarray is the given object has no items', () => { - // Arrange - const indictmentSubtypes = { - '123-123-123': [], - '234-234-234': [], - } - - // Act - const result = hasOnlyOneItemValues(indictmentSubtypes) - - // Assert - expect(result).toEqual(false) - }) - }) }) diff --git a/apps/judicial-system/web/src/utils/utils.ts b/apps/judicial-system/web/src/utils/utils.ts index 21de22262960..5ea47b22ea76 100644 --- a/apps/judicial-system/web/src/utils/utils.ts +++ b/apps/judicial-system/web/src/utils/utils.ts @@ -147,28 +147,3 @@ export const shouldUseAppealWithdrawnRoutes = (theCase: Case): boolean => { !theCase.appealJudge3) ) } - -/** - * Returns true if all values in the given object have only one item. - * - * Example: - * const items = { - * '123-123-123': ['item1'], - * '234-234-234': ['item2'] - * } - * - * const result = hasOnlyOneItemValues(items) - * console.log(result) // true - * - * @param items - The object containing the subarrays to check. - * @returns {boolean} - True if all values have only one item, false otherwise. - */ -export const hasOnlyOneItemValues = ( - items?: Record, -): boolean => { - if (!items || Object.keys(items).length === 0) { - return false - } - - return Object.values(items).every((subArray) => subArray.length === 1) -} From 29098fba1668fbc348c23a60f6852e6dadfff5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 10:59:58 +0000 Subject: [PATCH 50/68] Fix validation --- apps/judicial-system/web/src/utils/validate.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index a0a2e2ce54aa..bd56438c88cb 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -357,8 +357,7 @@ export const isTrafficViolationStepValidIndictments = ( const isOtherIndictmentCountsValid = nonTrafficViolationIndictmentCounts.every( (indictmentCount) => - indictmentCount.indictmentCountSubtypes && - indictmentCount.indictmentCountSubtypes.length > 0, + indictmentCount.incidentDescription && indictmentCount.legalArguments, ) return isTrafficViolationIndictmentCountsValid && isOtherIndictmentCountsValid From fdf230eb1be15151d3eb96dd5b273fe874a53460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 11:05:39 +0000 Subject: [PATCH 51/68] Add tests --- .../web/src/utils/validate.spec.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/judicial-system/web/src/utils/validate.spec.ts b/apps/judicial-system/web/src/utils/validate.spec.ts index 706f7d60c451..cb2f50defb16 100644 --- a/apps/judicial-system/web/src/utils/validate.spec.ts +++ b/apps/judicial-system/web/src/utils/validate.spec.ts @@ -1,4 +1,6 @@ -import { validate } from './validate' +import faker from 'faker' + +import { isTrafficViolationStepValidIndictments, validate } from './validate' describe('Validate police casenumber format', () => { test('should fail if not in correct form', () => { @@ -296,3 +298,15 @@ describe('Validate vehicle registration number', () => { }, ) }) + +describe.only('isTrafficViolationStepValidIndictments', () => { + test('should return false if there are no demands in a case', () => { + const theCase = { + id: faker.datatype.uuid(), + demands: null, + } + + const result = isTrafficViolationStepValidIndictments(theCase) + expect(result).toEqual(false) + }) +}) From c5a28a5cb800b2f7d588cfa4a3cf4fffb7392ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Wed, 18 Dec 2024 23:22:32 +0000 Subject: [PATCH 52/68] Add tests for isTrafficViolationStepValidIndictments validation function --- .../web/src/utils/validate.spec.ts | 144 +++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.spec.ts b/apps/judicial-system/web/src/utils/validate.spec.ts index cb2f50defb16..3ef635b600e8 100644 --- a/apps/judicial-system/web/src/utils/validate.spec.ts +++ b/apps/judicial-system/web/src/utils/validate.spec.ts @@ -1,6 +1,12 @@ import faker from 'faker' import { isTrafficViolationStepValidIndictments, validate } from './validate' +import { + Case, + IndictmentCountOffense, + IndictmentSubtype, +} from '../graphql/schema' +import { getLegalArguments } from '../routes/Prosecutor/Indictments/Indictment/IndictmentCount' describe('Validate police casenumber format', () => { test('should fail if not in correct form', () => { @@ -299,9 +305,9 @@ describe('Validate vehicle registration number', () => { ) }) -describe.only('isTrafficViolationStepValidIndictments', () => { +describe('isTrafficViolationStepValidIndictments', () => { test('should return false if there are no demands in a case', () => { - const theCase = { + const theCase: Case = { id: faker.datatype.uuid(), demands: null, } @@ -309,4 +315,138 @@ describe.only('isTrafficViolationStepValidIndictments', () => { const result = isTrafficViolationStepValidIndictments(theCase) expect(result).toEqual(false) }) + + test('should return false if there are civil claims in a case but no civil demands', () => { + const theCase: Case = { + id: faker.datatype.uuid(), + demands: faker.lorem.paragraph(), + hasCivilClaims: true, + civilDemands: null, + } + + const result = isTrafficViolationStepValidIndictments(theCase) + expect(result).toEqual(false) + }) + + test('should return false if there are no indictment subtypes in a case', () => { + const theCase: Case = { + id: faker.datatype.uuid(), + demands: faker.lorem.paragraph(), + hasCivilClaims: true, + civilDemands: faker.lorem.paragraph(), + indictmentSubtypes: null, + } + + const result = isTrafficViolationStepValidIndictments(theCase) + expect(result).toEqual(false) + }) + + test('should return true if all indictment counts are pure traffic violations and all of them are valid', () => { + const theCase: Case = { + id: faker.datatype.uuid(), + demands: faker.lorem.sentence(), + hasCivilClaims: true, + civilDemands: faker.lorem.sentence(), + indictmentSubtypes: { + ['1234']: [IndictmentSubtype.TRAFFIC_VIOLATION], + ['5678']: [IndictmentSubtype.TRAFFIC_VIOLATION], + }, + indictmentCounts: [ + { + id: faker.datatype.uuid(), + policeCaseNumber: '1234', + offenses: [IndictmentCountOffense.DRIVING_WITHOUT_LICENCE], + vehicleRegistrationNumber: 'VV111', + lawsBroken: [[1], [2]], + incidentDescription: faker.lorem.sentence(), + legalArguments: faker.lorem.sentence(), + }, + { + id: faker.datatype.uuid(), + policeCaseNumber: '5678', + offenses: [IndictmentCountOffense.DRIVING_WITHOUT_LICENCE], + vehicleRegistrationNumber: 'VV111', + lawsBroken: [[1], [2]], + incidentDescription: faker.lorem.sentence(), + legalArguments: faker.lorem.sentence(), + }, + ], + } + + const result = isTrafficViolationStepValidIndictments(theCase) + expect(result).toEqual(true) + }) + + test('should return false if all indictment counts are pure traffic violations and one of them is invalid', () => { + const theCase: Case = { + id: faker.datatype.uuid(), + demands: faker.lorem.sentence(), + hasCivilClaims: true, + civilDemands: faker.lorem.sentence(), + indictmentSubtypes: { + ['1234']: [IndictmentSubtype.TRAFFIC_VIOLATION], + ['5678']: [IndictmentSubtype.TRAFFIC_VIOLATION], + }, + indictmentCounts: [ + { + id: faker.datatype.uuid(), + policeCaseNumber: '1234', + offenses: [IndictmentCountOffense.DRIVING_WITHOUT_LICENCE], + vehicleRegistrationNumber: 'VV111', + lawsBroken: [[1], [2]], + incidentDescription: faker.lorem.sentence(), + legalArguments: faker.lorem.sentence(), + }, + { + id: faker.datatype.uuid(), + policeCaseNumber: '5678', + offenses: [], // offences must have at least one value + vehicleRegistrationNumber: 'VV111', + lawsBroken: [[1], [2]], + incidentDescription: faker.lorem.sentence(), + legalArguments: faker.lorem.sentence(), + }, + ], + } + + const result = isTrafficViolationStepValidIndictments(theCase) + expect(result).toEqual(false) + }) + + test('should return true if one indictment count has selected traffic violation and another has not', () => { + const theCase: Case = { + id: faker.datatype.uuid(), + demands: faker.lorem.sentence(), + hasCivilClaims: true, + civilDemands: faker.lorem.sentence(), + indictmentSubtypes: { + ['1234']: [IndictmentSubtype.BODILY_INJURY], + ['5678']: [ + IndictmentSubtype.TRAFFIC_VIOLATION, + IndictmentSubtype.AGGRAVATED_ASSAULT, + ], + }, + indictmentCounts: [ + { + id: faker.datatype.uuid(), + policeCaseNumber: '1234', + incidentDescription: faker.lorem.sentence(), + legalArguments: faker.lorem.sentence(), + }, + { + id: faker.datatype.uuid(), + policeCaseNumber: '5678', + offenses: [IndictmentCountOffense.DRIVING_WITHOUT_LICENCE], // offences must have at least one value + vehicleRegistrationNumber: 'VV111', + lawsBroken: [[1], [2]], + incidentDescription: faker.lorem.sentence(), + legalArguments: faker.lorem.sentence(), + indictmentCountSubtypes: [IndictmentSubtype.TRAFFIC_VIOLATION], + }, + ], + } + + const result = isTrafficViolationStepValidIndictments(theCase) + expect(result).toEqual(true) + }) }) From 0b7a4529833567035834547a8353a28f2ac6a443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 19 Dec 2024 13:26:23 +0000 Subject: [PATCH 53/68] Add tests --- .../web/src/utils/validate.spec.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.spec.ts b/apps/judicial-system/web/src/utils/validate.spec.ts index 3ef635b600e8..9fb4fdea9ca6 100644 --- a/apps/judicial-system/web/src/utils/validate.spec.ts +++ b/apps/judicial-system/web/src/utils/validate.spec.ts @@ -1,12 +1,11 @@ import faker from 'faker' -import { isTrafficViolationStepValidIndictments, validate } from './validate' import { Case, IndictmentCountOffense, IndictmentSubtype, } from '../graphql/schema' -import { getLegalArguments } from '../routes/Prosecutor/Indictments/Indictment/IndictmentCount' +import { isTrafficViolationStepValidIndictments, validate } from './validate' describe('Validate police casenumber format', () => { test('should fail if not in correct form', () => { @@ -348,8 +347,8 @@ describe('isTrafficViolationStepValidIndictments', () => { hasCivilClaims: true, civilDemands: faker.lorem.sentence(), indictmentSubtypes: { - ['1234']: [IndictmentSubtype.TRAFFIC_VIOLATION], - ['5678']: [IndictmentSubtype.TRAFFIC_VIOLATION], + '1234': [IndictmentSubtype.TRAFFIC_VIOLATION], + '5678': [IndictmentSubtype.TRAFFIC_VIOLATION], }, indictmentCounts: [ { @@ -384,8 +383,8 @@ describe('isTrafficViolationStepValidIndictments', () => { hasCivilClaims: true, civilDemands: faker.lorem.sentence(), indictmentSubtypes: { - ['1234']: [IndictmentSubtype.TRAFFIC_VIOLATION], - ['5678']: [IndictmentSubtype.TRAFFIC_VIOLATION], + '1234': [IndictmentSubtype.TRAFFIC_VIOLATION], + '5678': [IndictmentSubtype.TRAFFIC_VIOLATION], }, indictmentCounts: [ { @@ -420,8 +419,8 @@ describe('isTrafficViolationStepValidIndictments', () => { hasCivilClaims: true, civilDemands: faker.lorem.sentence(), indictmentSubtypes: { - ['1234']: [IndictmentSubtype.BODILY_INJURY], - ['5678']: [ + '1234': [IndictmentSubtype.BODILY_INJURY], + '5678': [ IndictmentSubtype.TRAFFIC_VIOLATION, IndictmentSubtype.AGGRAVATED_ASSAULT, ], From 95c871deeb88e41ef857921161e3cd043887ea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 19 Dec 2024 14:45:18 +0000 Subject: [PATCH 54/68] Rename indictment pdf title --- .../IndictmentCaseFilesList/IndictmentCaseFilesList.tsx | 2 +- .../Prosecutor/Indictments/CaseFiles/CaseFiles.strings.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx index 8e4cbca0f40e..abf898cd975c 100644 --- a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx +++ b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx @@ -188,7 +188,7 @@ const IndictmentCaseFilesList: FC = ({ diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.strings.ts b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.strings.ts index 13050303164b..dd7dd3d921d2 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.strings.ts +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.strings.ts @@ -53,9 +53,9 @@ export const caseFiles = defineMessages({ description: 'Titill á Tilkynning til sakaskrár hluta á dómskjalaskjá í ákærum.', }, - trafficViolationIndictmentTitle: { - id: 'judicial.system.core:indictments.case_files.traffic_violation_indictment_title', + indictmentTitle: { + id: 'judicial.system.core:indictments.case_files.indictment_title', defaultMessage: 'Ákæra.pdf', - description: 'Titill á ákæru pdf fyrir umferðalagabrot.', + description: 'Titill á ákæru pdf fyrir ákæru.', }, }) From 2d014944f57e20947601a6791f906d2572f08930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 19 Dec 2024 14:48:14 +0000 Subject: [PATCH 55/68] Rename indictment screen validation function --- .../Indictments/Indictment/Indictment.tsx | 4 ++-- apps/judicial-system/web/src/utils/formHelper.ts | 2 +- .../judicial-system/web/src/utils/validate.spec.ts | 14 +++++++------- apps/judicial-system/web/src/utils/validate.ts | 4 +--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx index e30f6bd64f9a..9a550dfd64a4 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Indictment/Indictment.tsx @@ -40,7 +40,7 @@ import { useIndictmentCounts, useOnceOn, } from '@island.is/judicial-system-web/src/utils/hooks' -import { isTrafficViolationStepValidIndictments } from '@island.is/judicial-system-web/src/utils/validate' +import { isIndictmentStepValid } from '@island.is/judicial-system-web/src/utils/validate' import { usePoliceCaseInfoQuery } from '../Defendant/policeCaseInfo.generated' import { IndictmentCount } from './IndictmentCount' @@ -115,7 +115,7 @@ const Indictment = () => { }, }) - const stepIsValid = isTrafficViolationStepValidIndictments(workingCase) + const stepIsValid = isIndictmentStepValid(workingCase) const handleNavigationTo = useCallback( (destination: string) => router.push(`${destination}/${workingCase.id}`), diff --git a/apps/judicial-system/web/src/utils/formHelper.ts b/apps/judicial-system/web/src/utils/formHelper.ts index 80ac418c52e5..ff9aaa083224 100644 --- a/apps/judicial-system/web/src/utils/formHelper.ts +++ b/apps/judicial-system/web/src/utils/formHelper.ts @@ -256,7 +256,7 @@ export const stepValidations = (): stepValidationsType => { [constants.INDICTMENTS_PROCESSING_ROUTE]: (theCase: Case) => validations.isProcessingStepValidIndictments(theCase), [constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE]: (theCase: Case) => - validations.isTrafficViolationStepValidIndictments(theCase), + validations.isIndictmentStepValid(theCase), [constants.INDICTMENTS_CASE_FILES_ROUTE]: () => true, [constants.INDICTMENTS_SUMMARY_ROUTE]: () => true, [constants.RESTRICTION_CASE_RECEPTION_AND_ASSIGNMENT_ROUTE]: ( diff --git a/apps/judicial-system/web/src/utils/validate.spec.ts b/apps/judicial-system/web/src/utils/validate.spec.ts index 9fb4fdea9ca6..c150889608bc 100644 --- a/apps/judicial-system/web/src/utils/validate.spec.ts +++ b/apps/judicial-system/web/src/utils/validate.spec.ts @@ -5,7 +5,7 @@ import { IndictmentCountOffense, IndictmentSubtype, } from '../graphql/schema' -import { isTrafficViolationStepValidIndictments, validate } from './validate' +import { isIndictmentStepValid, validate } from './validate' describe('Validate police casenumber format', () => { test('should fail if not in correct form', () => { @@ -311,7 +311,7 @@ describe('isTrafficViolationStepValidIndictments', () => { demands: null, } - const result = isTrafficViolationStepValidIndictments(theCase) + const result = isIndictmentStepValid(theCase) expect(result).toEqual(false) }) @@ -323,7 +323,7 @@ describe('isTrafficViolationStepValidIndictments', () => { civilDemands: null, } - const result = isTrafficViolationStepValidIndictments(theCase) + const result = isIndictmentStepValid(theCase) expect(result).toEqual(false) }) @@ -336,7 +336,7 @@ describe('isTrafficViolationStepValidIndictments', () => { indictmentSubtypes: null, } - const result = isTrafficViolationStepValidIndictments(theCase) + const result = isIndictmentStepValid(theCase) expect(result).toEqual(false) }) @@ -372,7 +372,7 @@ describe('isTrafficViolationStepValidIndictments', () => { ], } - const result = isTrafficViolationStepValidIndictments(theCase) + const result = isIndictmentStepValid(theCase) expect(result).toEqual(true) }) @@ -408,7 +408,7 @@ describe('isTrafficViolationStepValidIndictments', () => { ], } - const result = isTrafficViolationStepValidIndictments(theCase) + const result = isIndictmentStepValid(theCase) expect(result).toEqual(false) }) @@ -445,7 +445,7 @@ describe('isTrafficViolationStepValidIndictments', () => { ], } - const result = isTrafficViolationStepValidIndictments(theCase) + const result = isIndictmentStepValid(theCase) expect(result).toEqual(true) }) }) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index e0bd88bf1062..1c78d457214a 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -299,9 +299,7 @@ export const isProcessingStepValidIndictments = ( ) } -export const isTrafficViolationStepValidIndictments = ( - workingCase: Case, -): boolean => { +export const isIndictmentStepValid = (workingCase: Case): boolean => { const hasValidDemands = Boolean( workingCase.demands && (!workingCase.hasCivilClaims || workingCase.civilDemands), From 41afbaeae87409ddf4125c21c2707956daa16c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 13 Jan 2025 14:41:36 +0000 Subject: [PATCH 56/68] Cleanup --- apps/judicial-system/web/src/utils/validate.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index 65b675ef2514..d59a92b604bc 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -1,6 +1,4 @@ // TODO: Add tests -import partition from 'lodash/partition' - import { IndictmentSubtype, isIndictmentCase, From a1b493e8d6cd479c6efb530d7723589292fd9b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 13 Jan 2025 14:42:57 +0000 Subject: [PATCH 57/68] Cleanup --- libs/judicial-system/types/src/lib/case.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/judicial-system/types/src/lib/case.ts b/libs/judicial-system/types/src/lib/case.ts index 4b0115e9a297..25beea51adcf 100644 --- a/libs/judicial-system/types/src/lib/case.ts +++ b/libs/judicial-system/types/src/lib/case.ts @@ -371,12 +371,6 @@ export const hasIndictmentCaseBeenSubmittedToCourt = ( ) } -export const getStatementDeadline = (appealReceived: Date): string => { - return new Date( - new Date(appealReceived).setDate(appealReceived.getDate() + 1), - ).toISOString() -} - export const isTrafficViolationCase = (theCase: { type?: CaseType | null indictmentSubtypes?: IndictmentSubtypeMap @@ -404,6 +398,12 @@ export const isTrafficViolationCase = (theCase: { ) } +export const getStatementDeadline = (appealReceived: Date): string => { + return new Date( + new Date(appealReceived).setDate(appealReceived.getDate() + 1), + ).toISOString() +} + export const isIndictmentCaseState = ( state: string, ): state is IndictmentCaseState => { From c047fc927e1dd441e3b2fe8442babaeb96e9f542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 13 Jan 2025 14:56:19 +0000 Subject: [PATCH 58/68] Cleanup --- .../src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx index 15110a97727d..b3d2520d335e 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx @@ -131,7 +131,7 @@ const CaseFiles = () => { /> {workingCase.hasCivilClaims && ( - + From 3f995e9ed61d11b6674b25dc755a8a8c1536d5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 13 Jan 2025 15:15:42 +0000 Subject: [PATCH 59/68] Cleanup --- .../backend/src/app/modules/case/pdf.service.ts | 1 - .../routes/Defender/Cases/components/DefenderCasesTable.tsx | 5 +---- apps/judicial-system/web/src/utils/validate.ts | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts b/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts index f39c5adf8737..c59e7f9feeb6 100644 --- a/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/pdf.service.ts @@ -1,7 +1,6 @@ import CryptoJS from 'crypto-js' import { - BadRequestException, forwardRef, Inject, Injectable, diff --git a/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx b/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx index be8edb2ecdd4..10060eb221a4 100644 --- a/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx +++ b/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx @@ -25,10 +25,7 @@ import { SortButton, TableSkeleton, } from '@island.is/judicial-system-web/src/components/Table' -import { - CaseListEntry, - Defendant, -} from '@island.is/judicial-system-web/src/graphql/schema' +import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema' import { useCaseList, useSort, diff --git a/apps/judicial-system/web/src/utils/validate.ts b/apps/judicial-system/web/src/utils/validate.ts index d59a92b604bc..f53773ba08a3 100644 --- a/apps/judicial-system/web/src/utils/validate.ts +++ b/apps/judicial-system/web/src/utils/validate.ts @@ -289,9 +289,7 @@ export const isProcessingStepValidIndictments = ( ) } -export const isTrafficViolationStepValidIndictments = ( - workingCase: Case, -): boolean => { +export const isIndictmentStepValid = (workingCase: Case): boolean => { const hasValidDemands = Boolean( workingCase.demands && (!workingCase.hasCivilClaims || workingCase.civilDemands), From d1a15b91a5ea00b67040eb40bfbeb6a4692d38a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Mon, 13 Jan 2025 15:21:02 +0000 Subject: [PATCH 60/68] Cleanup --- .../routes/Prosecutor/Indictments/Processing/Processing.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx index 7088f1060acc..a27679249bea 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx @@ -10,10 +10,7 @@ import { Text, } from '@island.is/island-ui/core' import * as constants from '@island.is/judicial-system/consts' -import { - AdvocateType, - isTrafficViolationCase, -} from '@island.is/judicial-system/types' +import { AdvocateType } from '@island.is/judicial-system/types' import { core, titles } from '@island.is/judicial-system-web/messages' import { BlueBox, @@ -74,7 +71,6 @@ const Processing: FC = () => { } = useCivilClaimants() const router = useRouter() - const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase) const [civilClaimantNationalIdUpdate, setCivilClaimantNationalIdUpdate] = useState<{ nationalId: string | null; civilClaimantId: string }>() const [hasCivilClaimantChoice, setHasCivilClaimantChoice] = From 7a4faef78785edccecf1c3b28eafc1e7b6eab44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 14 Jan 2025 14:12:48 +0000 Subject: [PATCH 61/68] Remove tests --- .../deliverIndictmentToPolice.spec.ts | 64 ------------------- 1 file changed, 64 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts index a9bf45ec1fb2..d9f403762815 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts @@ -74,70 +74,6 @@ describe('InternalCaseController - Deliver indictment to police', () => { } }) - describe('deliver indictment case files to police', () => { - const caseId = uuid() - const caseType = CaseType.INDICTMENT - const caseState = CaseState.WAITING_FOR_CONFIRMATION - const policeCaseNumber = uuid() - const courtCaseNumber = uuid() - const defendantNationalId = '0123456789' - const indictmentKey = uuid() - const indictmentPdf = 'test indictment' - const caseFile = { - id: uuid(), - key: indictmentKey, - category: CaseFileCategory.INDICTMENT, - } - const theCase = { - id: caseId, - origin: CaseOrigin.LOKE, - type: caseType, - state: caseState, - policeCaseNumbers: [policeCaseNumber], - courtCaseNumber, - defendants: [{ nationalId: defendantNationalId }], - caseFiles: [caseFile], - } as Case - - let then: Then - - beforeEach(async () => { - const mockGetCaseFileFromS3 = - mockFileService.getCaseFileFromS3 as jest.Mock - mockGetCaseFileFromS3.mockResolvedValueOnce(indictmentPdf) - const mockUpdatePoliceCase = - mockPoliceService.updatePoliceCase as jest.Mock - mockUpdatePoliceCase.mockResolvedValueOnce(true) - - then = await givenWhenThen(caseId, theCase) - }) - - it('should update the police case', async () => { - expect(mockFileService.getCaseFileFromS3).toHaveBeenCalledWith( - theCase, - caseFile, - ) - expect(mockPoliceService.updatePoliceCase).toHaveBeenCalledWith( - user, - caseId, - caseType, - caseState, - policeCaseNumber, - courtCaseNumber, - defendantNationalId, - date, - '', - [ - { - type: PoliceDocumentType.RVAS, - courtDocument: Base64.btoa(indictmentPdf), - }, - ], - ) - expect(then.result.delivered).toEqual(true) - }) - }) - describe('deliver generated indictment pdf to police', () => { const caseId = uuid() const caseType = CaseType.INDICTMENT From 3d687a3a83bc3d925c18787163c7cec9b6898a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 14 Jan 2025 14:31:24 +0000 Subject: [PATCH 62/68] Fix tests --- .../test/caseController/createCourtCase.spec.ts | 15 ++++----------- .../case/test/caseController/update.spec.ts | 6 ------ .../deliverIndictmentToPolice.spec.ts | 1 - 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts index b1daaac68f15..142af91b6a0b 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts @@ -306,12 +306,6 @@ describe('CaseController - Create court case', () => { type: CaseType.INDICTMENT, policeCaseNumbers: [policeCaseNumber1, policeCaseNumber2], caseFiles: [ - { - id: indictmentId, - key: uuid(), - state: CaseFileState.STORED_IN_RVG, - category: CaseFileCategory.INDICTMENT, - }, { id: criminalRecordId, key: uuid(), @@ -365,25 +359,24 @@ describe('CaseController - Create court case', () => { type: MessageType.DELIVERY_TO_COURT_CASE_FILE, user, caseId, - elementId: indictmentId, + elementId: criminalRecordId, }, { type: MessageType.DELIVERY_TO_COURT_CASE_FILE, user, caseId, - elementId: criminalRecordId, + elementId: costBreakdownId, }, { type: MessageType.DELIVERY_TO_COURT_CASE_FILE, user, caseId, - elementId: costBreakdownId, + elementId: uncategorisedId, }, { - type: MessageType.DELIVERY_TO_COURT_CASE_FILE, + type: MessageType.DELIVERY_TO_COURT_INDICTMENT, user, caseId, - elementId: uncategorisedId, }, ]) }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts index 51d7fd6c5d6e..33c470a55809 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts @@ -415,12 +415,6 @@ describe('CaseController - Update', () => { type, policeCaseNumbers: [policeCaseNumber1, policeCaseNumber2], caseFiles: [ - { - id: indictmentId, - key: uuid(), - state: CaseFileState.STORED_IN_RVG, - category: CaseFileCategory.INDICTMENT, - }, { id: criminalRecordId, key: uuid(), diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts index d9f403762815..757d3ca7ea18 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentToPolice.spec.ts @@ -2,7 +2,6 @@ import { Base64 } from 'js-base64' import { uuid } from 'uuidv4' import { - CaseFileCategory, CaseOrigin, CaseState, CaseType, From 8f8131fb548836f5a8b97699255701c98bdec7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 16 Jan 2025 13:09:31 +0000 Subject: [PATCH 63/68] Fix tests --- .../modules/case/test/caseController/update.spec.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts index 33c470a55809..9e4621e97d68 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts @@ -406,7 +406,6 @@ describe('CaseController - Update', () => { const caseToUpdate = { courtCaseNumber } const policeCaseNumber1 = uuid() const policeCaseNumber2 = uuid() - const indictmentId = uuid() const criminalRecordId = uuid() const costBreakdownId = uuid() const uncategorisedId = uuid() @@ -468,25 +467,24 @@ describe('CaseController - Update', () => { type: MessageType.DELIVERY_TO_COURT_CASE_FILE, user, caseId, - elementId: indictmentId, + elementId: criminalRecordId, }, { type: MessageType.DELIVERY_TO_COURT_CASE_FILE, user, caseId, - elementId: criminalRecordId, + elementId: costBreakdownId, }, { type: MessageType.DELIVERY_TO_COURT_CASE_FILE, user, caseId, - elementId: costBreakdownId, + elementId: uncategorisedId, }, { - type: MessageType.DELIVERY_TO_COURT_CASE_FILE, + type: MessageType.DELIVERY_TO_COURT_INDICTMENT, user, caseId, - elementId: uncategorisedId, }, ]) }) From 3dc30987b16cce63300d6ec488a01f009bdb29bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Thu, 16 Jan 2025 13:49:09 +0000 Subject: [PATCH 64/68] Removes unused code --- .../app/modules/subpoena/subpoena.module.ts | 2 -- .../app/modules/subpoena/subpoena.service.ts | 26 ------------------- .../test/createTestingSubpoenaModule.ts | 6 ----- 3 files changed, 34 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts index 05be74045e18..06634dee2f5d 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts @@ -8,7 +8,6 @@ import { CourtModule } from '../court/court.module' import { DefendantModule } from '../defendant/defendant.module' import { Defendant } from '../defendant/models/defendant.model' import { EventModule } from '../event/event.module' -import { FileModule } from '../file/file.module' import { PoliceModule } from '../police/police.module' import { Subpoena } from './models/subpoena.model' import { InternalSubpoenaController } from './internalSubpoena.controller' @@ -20,7 +19,6 @@ import { SubpoenaService } from './subpoena.service' imports: [ forwardRef(() => CaseModule), forwardRef(() => PoliceModule), - forwardRef(() => FileModule), forwardRef(() => MessageModule), forwardRef(() => EventModule), forwardRef(() => DefendantModule), diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts index f3081a63dbbf..6993a5d67f05 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts @@ -20,10 +20,8 @@ import { MessageType, } from '@island.is/judicial-system/message' import { - CaseFileCategory, isFailedServiceStatus, isSuccessfulServiceStatus, - isTrafficViolationCase, ServiceStatus, SubpoenaNotificationType, type User as TUser, @@ -35,7 +33,6 @@ import { CourtDocumentFolder, CourtService } from '../court' import { DefendantService } from '../defendant/defendant.service' import { Defendant } from '../defendant/models/defendant.model' import { EventService } from '../event' -import { FileService } from '../file' import { PoliceService, SubpoenaInfo } from '../police' import { User } from '../user' import { UpdateSubpoenaDto } from './dto/updateSubpoena.dto' @@ -90,8 +87,6 @@ export class SubpoenaService { private readonly messageService: MessageService, @Inject(forwardRef(() => PoliceService)) private readonly policeService: PoliceService, - @Inject(forwardRef(() => FileService)) - private readonly fileService: FileService, private readonly eventService: EventService, private readonly defendantService: DefendantService, private readonly courtService: CourtService, @@ -292,27 +287,6 @@ export class SubpoenaService { }) } - async getIndictmentPdf(theCase: Case): Promise { - if (isTrafficViolationCase(theCase)) { - return await this.pdfService.getIndictmentPdf(theCase) - } - - const indictmentCaseFile = theCase.caseFiles?.find( - (caseFile) => - caseFile.category === CaseFileCategory.INDICTMENT && caseFile.key, - ) - - if (!indictmentCaseFile) { - // This shouldn't ever happen - this.logger.error( - `No indictment found for case ${theCase.id} so cannot deliver subpoena to police`, - ) - throw new Error(`No indictment found for case ${theCase.id}`) - } - - return await this.fileService.getCaseFileFromS3(theCase, indictmentCaseFile) - } - async deliverSubpoenaToPolice( theCase: Case, defendant: Defendant, diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts index c4982ece5817..af80ec74850e 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts @@ -16,7 +16,6 @@ import { CaseService, PdfService } from '../../case' import { CourtService } from '../../court' import { Defendant, DefendantService } from '../../defendant' import { EventService } from '../../event' -import { FileService } from '../../file' import { PoliceService } from '../../police' import { UserService } from '../../user' import { InternalSubpoenaController } from '../internalSubpoena.controller' @@ -30,7 +29,6 @@ jest.mock('../../user/user.service') jest.mock('../../case/case.service') jest.mock('../../case/pdf.service') jest.mock('../../police/police.service') -jest.mock('../../file/file.service') jest.mock('../../event/event.service') jest.mock('../../defendant/defendant.service') jest.mock('../../court/court.service') @@ -50,7 +48,6 @@ export const createTestingSubpoenaModule = async () => { CaseService, PdfService, PoliceService, - FileService, EventService, DefendantService, CourtService, @@ -95,8 +92,6 @@ export const createTestingSubpoenaModule = async () => { const policeService = subpoenaModule.get(PoliceService) - const fileService = subpoenaModule.get(FileService) - const courtService = subpoenaModule.get(CourtService) const subpoenaModel = await subpoenaModule.resolve( @@ -122,7 +117,6 @@ export const createTestingSubpoenaModule = async () => { userService, pdfService, policeService, - fileService, courtService, subpoenaModel, subpoenaService, From 04759009cdc3ef8c68a3ee3c6b947c7d32d4f3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Thu, 16 Jan 2025 20:35:37 +0000 Subject: [PATCH 65/68] Removes dead code --- .../src/app/formatters/confirmedPdf.ts | 174 ------------------ .../src/app/modules/case/case.service.ts | 12 -- .../modules/case/limitedAccessCase.service.ts | 2 - .../src/app/modules/file/file.service.ts | 87 ++------- .../modules/file/guards/caseFileCategory.ts | 1 - .../limitedAccessViewCaseFileGuard.spec.ts | 1 - .../uploadCaseFileToCourt.spec.ts | 1 - .../deliverCaseFileToCourt.spec.ts | 1 - .../IndictmentCaseFilesList.tsx | 6 - libs/judicial-system/types/src/lib/case.ts | 8 +- libs/judicial-system/types/src/lib/file.ts | 1 - 11 files changed, 19 insertions(+), 275 deletions(-) diff --git a/apps/judicial-system/backend/src/app/formatters/confirmedPdf.ts b/apps/judicial-system/backend/src/app/formatters/confirmedPdf.ts index d9c944f392b4..390f959b9b77 100644 --- a/apps/judicial-system/backend/src/app/formatters/confirmedPdf.ts +++ b/apps/judicial-system/backend/src/app/formatters/confirmedPdf.ts @@ -12,14 +12,12 @@ import { import { PDFKitCoatOfArms } from './PDFKitCoatOfArms' type ConfirmableCaseFileCategories = - | CaseFileCategory.INDICTMENT | CaseFileCategory.RULING | CaseFileCategory.COURT_RECORD // Colors const lightGray = rgb(0.9804, 0.9804, 0.9804) const darkGray = rgb(0.7961, 0.7961, 0.7961) -const gold = rgb(0.6784, 0.6392, 0.451) const white = rgb(1, 1, 1) // Spacing @@ -29,175 +27,6 @@ const coatOfArmsWidth = calculatePt(105) const confirmedByHeight = calculatePt(50) const titleX = coatOfArmsX + coatOfArmsWidth + calculatePt(8) -const createIndictmentConfirmation = async ( - confirmation: Confirmation, - pdfDoc: PDFDocument, -) => { - const pages = pdfDoc.getPages() - const doc = pages[0] - - const shadowHeight = calculatePt(90) - const { width, height } = doc.getSize() - const titleHeight = calculatePt(32) - const titleWidth = width - coatOfArmsWidth - 2 * coatOfArmsX - const confirmedByWidth = calculatePt(258) - const institutionWidth = confirmedByWidth + calculatePt(48) - - // Draw the shadow - doc.drawRectangle({ - x: pageMargin, - y: height - shadowHeight - pageMargin, - width: doc.getWidth() - 2 * pageMargin - calculatePt(16), - height: shadowHeight, - color: lightGray, - }) - - // Draw the box around the coat of arms - doc.drawRectangle({ - x: coatOfArmsX, - y: height - shadowHeight - pageMargin + calculatePt(8), - width: coatOfArmsWidth, - height: shadowHeight, - color: rgb(1, 1, 1), - borderColor: darkGray, - borderWidth: 1, - }) - - PDFKitCoatOfArms(doc, height) - - doc.drawRectangle({ - x: coatOfArmsX + coatOfArmsWidth, - y: height - pageMargin - titleHeight + calculatePt(8), - width: titleWidth, - height: titleHeight, - color: lightGray, - borderColor: darkGray, - borderWidth: 1, - }) - - const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman) - const timesRomanBoldFont = await pdfDoc.embedFont( - StandardFonts.TimesRomanBold, - ) - doc.drawText('Réttarvörslugátt', { - x: titleX, - y: height - pageMargin - titleHeight + calculatePt(20), - size: calculatePt(smallFontSize), - font: timesRomanBoldFont, - }) - - doc.drawText('Skjal samþykkt rafrænt', { - x: 158, - y: height - pageMargin - titleHeight + calculatePt(20), - size: calculatePt(smallFontSize), - font: timesRomanFont, - }) - - doc.drawSvgPath( - 'M0.763563 11.8047H7.57201C7.85402 11.8047 8.08264 11.5761 8.08264 11.2941V5.50692C8.08264 5.22492 7.85402 4.99629 7.57201 4.99629H7.06138V3.46439C7.06138 1.86887 5.76331 0.570801 4.16779 0.570801C2.57226 0.570801 1.2742 1.86887 1.2742 3.46439V4.99629H0.763563C0.481557 4.99629 0.25293 5.22492 0.25293 5.50692V11.2941C0.25293 11.5761 0.481557 11.8047 0.763563 11.8047ZM5.61394 8.03817L4.16714 9.48496C4.06743 9.58467 3.93674 9.63455 3.80609 9.63455C3.67543 9.63455 3.54471 9.58467 3.44504 9.48496L2.72164 8.76157C2.52222 8.56215 2.52222 8.23888 2.72164 8.03943C2.92102 7.84001 3.24436 7.84001 3.44378 8.03943L3.80612 8.40174L4.89187 7.31603C5.09125 7.11661 5.41458 7.11661 5.614 7.31603C5.81339 7.51549 5.81339 7.83875 5.61394 8.03817ZM2.29546 3.46439C2.29546 2.43199 3.13539 1.59207 4.16779 1.59207C5.20019 1.59207 6.04011 2.43199 6.04011 3.46439V4.99629H2.29546V3.46439Z', - { - color: gold, - x: width - 38, - y: height - pageMargin - titleHeight + calculatePt(33), - }, - ) - - // Draw the "Confirmed by" box - doc.drawRectangle({ - x: coatOfArmsX + coatOfArmsWidth, - y: height - pageMargin - titleHeight - confirmedByHeight, - width: confirmedByWidth, - height: shadowHeight - titleHeight, - color: white, - borderColor: darkGray, - borderWidth: 1, - }) - - doc.drawText('Staðfestingaraðili', { - x: titleX, - y: height - pageMargin - titleHeight - calculatePt(15), - size: calculatePt(smallFontSize), - font: timesRomanBoldFont, - }) - - if (confirmation?.actor) { - timesRomanFont.widthOfTextAtSize( - `${confirmation.actor}${ - confirmation.title ? `, ${lowercase(confirmation.title)}` : '' - }`, - calculatePt(smallFontSize), - ) - drawTextWithEllipsisPDFKit( - doc, - `${confirmation.actor}${ - confirmation.title ? `, ${lowercase(confirmation.title)}` : '' - }`, - { type: timesRomanFont, size: calculatePt(smallFontSize) }, - titleX, - height - pageMargin - titleHeight - calculatePt(29), - confirmedByWidth - 16, - ) - } - - // Draw the "Institution" box - doc.drawRectangle({ - x: coatOfArmsX + coatOfArmsWidth + confirmedByWidth, - y: height - pageMargin - titleHeight - confirmedByHeight, - width: institutionWidth, - height: shadowHeight - titleHeight, - color: white, - borderColor: darkGray, - borderWidth: 1, - }) - - doc.drawText('Embætti', { - x: titleX + confirmedByWidth, - y: height - pageMargin - titleHeight - calculatePt(15), - size: calculatePt(smallFontSize), - font: timesRomanBoldFont, - }) - - if (confirmation?.institution) { - doc.drawText(confirmation.institution, { - x: titleX + confirmedByWidth, - y: height - pageMargin - titleHeight - calculatePt(29), - font: timesRomanFont, - size: calculatePt(smallFontSize), - }) - } - - // Draw the "Indictment date" box - doc.drawRectangle({ - x: width - 90, - y: height - pageMargin - titleHeight - confirmedByHeight, - width: 70, - height: shadowHeight - titleHeight, - color: white, - borderColor: darkGray, - borderWidth: 1, - }) - - doc.drawText('Útgáfa ákæru', { - x: width - 72, - y: height - pageMargin - titleHeight - calculatePt(15), - size: calculatePt(smallFontSize), - font: timesRomanBoldFont, - }) - - if (confirmation?.date) { - const dateFormattedDate = formatDate(confirmation.date) - - if (dateFormattedDate) { - doc.drawText(dateFormattedDate, { - x: width - 62, - y: height - pageMargin - titleHeight - calculatePt(29), - font: timesRomanFont, - size: calculatePt(smallFontSize), - }) - } - } -} - const createRulingConfirmation = async ( confirmation: Confirmation, pdfDoc: PDFDocument, @@ -443,9 +272,6 @@ export const createConfirmedPdf = async ( const pdfDoc = await PDFDocument.load(pdf) switch (fileType) { - case CaseFileCategory.INDICTMENT: - await createIndictmentConfirmation(confirmation, pdfDoc) - break case CaseFileCategory.RULING: { await createRulingConfirmation(confirmation, pdfDoc) break diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index 3d70bd2a15f9..b151dbf818e1 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -385,7 +385,6 @@ export const include: Includeable[] = [ state: { [Op.not]: CaseFileState.DELETED }, category: { [Op.in]: [ - CaseFileCategory.INDICTMENT, CaseFileCategory.COURT_RECORD, CaseFileCategory.CRIMINAL_RECORD, CaseFileCategory.COST_BREAKDOWN, @@ -1840,10 +1839,6 @@ export class CaseService { ): Promise { const receivingCase = update.courtCaseNumber && theCase.state === CaseState.SUBMITTED - const returningIndictmentCase = - isIndictmentCase(theCase.type) && - update.state === CaseState.DRAFT && - theCase.state === CaseState.RECEIVED const completingIndictmentCaseWithoutRuling = isIndictmentCase(theCase.type) && update.state === CaseState.COMPLETED && @@ -1902,13 +1897,6 @@ export class CaseService { await this.fileService.resetCaseFileStates(theCase.id, transaction) } - if (returningIndictmentCase) { - await this.fileService.resetIndictmentCaseFileHashes( - theCase.id, - transaction, - ) - } - // Remove uploaded ruling files if an indictment case is completed without a ruling if (completingIndictmentCaseWithoutRuling && theCase.caseFiles) { await Promise.all( diff --git a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts index 53eb58b5ed7f..b81d51666d56 100644 --- a/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts @@ -227,7 +227,6 @@ export const include: Includeable[] = [ CaseFileCategory.APPEAL_RULING, CaseFileCategory.APPEAL_COURT_RECORD, CaseFileCategory.COURT_RECORD, - CaseFileCategory.INDICTMENT, CaseFileCategory.CRIMINAL_RECORD, CaseFileCategory.COST_BREAKDOWN, CaseFileCategory.CASE_FILE, @@ -276,7 +275,6 @@ export const include: Includeable[] = [ state: { [Op.not]: CaseFileState.DELETED }, category: { [Op.in]: [ - CaseFileCategory.INDICTMENT, CaseFileCategory.COURT_RECORD, CaseFileCategory.CRIMINAL_RECORD, CaseFileCategory.COST_BREAKDOWN, diff --git a/apps/judicial-system/backend/src/app/modules/file/file.service.ts b/apps/judicial-system/backend/src/app/modules/file/file.service.ts index fbf3b50a9d5e..784c6b2fdbaf 100644 --- a/apps/judicial-system/backend/src/app/modules/file/file.service.ts +++ b/apps/judicial-system/backend/src/app/modules/file/file.service.ts @@ -22,7 +22,6 @@ import { CaseFileCategory, CaseFileState, EventType, - hasIndictmentCaseBeenSubmittedToCourt, isCompletedCase, isIndictmentCase, } from '@island.is/judicial-system/types' @@ -107,24 +106,6 @@ export class FileService { return true } - if ( - isIndictmentCase(theCase.type) && - file.category === CaseFileCategory.INDICTMENT - ) { - // The file may have been confirmed - return this.awsS3Service - .deleteConfirmedIndictmentCaseObject(theCase.type, file.key) - .catch((reason) => { - // Tolerate failure, but log what happened - this.logger.error( - `Could not delete confirmed file ${file.id} of case ${file.caseId} from AWS S3`, - { reason }, - ) - - return false - }) - } - return this.awsS3Service .deleteObject(theCase.type, file.key) .catch((reason) => { @@ -142,7 +123,6 @@ export class FileService { let courtDocumentFolder: CourtDocumentFolder switch (file.category) { - case CaseFileCategory.INDICTMENT: case CaseFileCategory.CRIMINAL_RECORD: case CaseFileCategory.COST_BREAKDOWN: courtDocumentFolder = CourtDocumentFolder.INDICTMENT_DOCUMENTS @@ -177,6 +157,14 @@ export class FileService { file: CaseFile, pdf: Buffer, ): Promise { + if ( + !theCase.rulingDate || + (file.category !== CaseFileCategory.RULING && + file.category !== CaseFileCategory.COURT_RECORD) + ) { + return undefined + } + const confirmationEvent = theCase.eventLogs?.find( (event) => event.eventType === EventType.INDICTMENT_CONFIRMED, ) @@ -185,40 +173,16 @@ export class FileService { return undefined } - return this.userService - .findByNationalId(confirmationEvent.nationalId) - .then((user) => { - if (file.category === CaseFileCategory.INDICTMENT) { - return createConfirmedPdf( - { - actor: user.name, - title: user.title, - institution: user.institution?.name ?? '', - date: confirmationEvent.created, - }, - pdf, - CaseFileCategory.INDICTMENT, - ) - } - - if ( - (file.category === CaseFileCategory.RULING || - file.category === CaseFileCategory.COURT_RECORD) && - isCompletedCase(theCase.state) && - theCase.rulingDate - ) { - return createConfirmedPdf( - { - actor: theCase.judge?.name ?? '', - title: theCase.judge?.title, - institution: theCase.judge?.institution?.name ?? '', - date: theCase.rulingDate, - }, - pdf, - file.category, - ) - } - }) + return createConfirmedPdf( + { + actor: theCase.judge?.name ?? '', + title: theCase.judge?.title, + institution: theCase.judge?.institution?.name ?? '', + date: theCase.rulingDate, + }, + pdf, + file.category, + ) .then((confirmedPdf) => { if (!confirmedPdf) { throw new Error('Failed to create confirmed PDF') @@ -248,14 +212,6 @@ export class FileService { return false } - // Only indictments that have been submitted to court can be confirmed - if ( - file.category === CaseFileCategory.INDICTMENT && - hasIndictmentCaseBeenSubmittedToCourt(theCase.state) - ) { - return true - } - // Rulings and court records are only confirmed when a case is completed if ( (file.category === CaseFileCategory.RULING || @@ -572,13 +528,6 @@ export class FileService { ) } - resetIndictmentCaseFileHashes(caseId: string, transaction: Transaction) { - return this.fileModel.update( - { hash: null }, - { where: { caseId, category: CaseFileCategory.INDICTMENT }, transaction }, - ) - } - async deliverCaseFileToCourtOfAppeals( theCase: Case, file: CaseFile, diff --git a/apps/judicial-system/backend/src/app/modules/file/guards/caseFileCategory.ts b/apps/judicial-system/backend/src/app/modules/file/guards/caseFileCategory.ts index b6656ac08470..0de7a2d7a6f1 100644 --- a/apps/judicial-system/backend/src/app/modules/file/guards/caseFileCategory.ts +++ b/apps/judicial-system/backend/src/app/modules/file/guards/caseFileCategory.ts @@ -32,7 +32,6 @@ const defenderDefaultCaseFileCategoriesForIndictmentCases = [ const defenderCaseFileCategoriesForIndictmentCases = defenderDefaultCaseFileCategoriesForIndictmentCases.concat( - CaseFileCategory.INDICTMENT, CaseFileCategory.CRIMINAL_RECORD, CaseFileCategory.COST_BREAKDOWN, CaseFileCategory.CASE_FILE, diff --git a/apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts b/apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts index f333b338737f..bc472456ac25 100644 --- a/apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/file/guards/test/limitedAccessViewCaseFileGuard.spec.ts @@ -156,7 +156,6 @@ describe('Limited Access View Case File Guard', () => { const allowedCaseFileCategories = [ CaseFileCategory.COURT_RECORD, CaseFileCategory.RULING, - CaseFileCategory.INDICTMENT, CaseFileCategory.CRIMINAL_RECORD, CaseFileCategory.COST_BREAKDOWN, CaseFileCategory.CASE_FILE, diff --git a/apps/judicial-system/backend/src/app/modules/file/test/fileController/uploadCaseFileToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/file/test/fileController/uploadCaseFileToCourt.spec.ts index ac87c467f3b3..f109e3460ee1 100644 --- a/apps/judicial-system/backend/src/app/modules/file/test/fileController/uploadCaseFileToCourt.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/file/test/fileController/uploadCaseFileToCourt.spec.ts @@ -159,7 +159,6 @@ describe('FileController - Upload case file to court', () => { caseFileCategory | courtDocumentFolder ${CaseFileCategory.COURT_RECORD} | ${CourtDocumentFolder.COURT_DOCUMENTS} ${CaseFileCategory.RULING} | ${CourtDocumentFolder.COURT_DOCUMENTS} - ${CaseFileCategory.INDICTMENT} | ${CourtDocumentFolder.INDICTMENT_DOCUMENTS} ${CaseFileCategory.CRIMINAL_RECORD} | ${CourtDocumentFolder.INDICTMENT_DOCUMENTS} ${CaseFileCategory.COST_BREAKDOWN} | ${CourtDocumentFolder.INDICTMENT_DOCUMENTS} ${CaseFileCategory.CASE_FILE} | ${CourtDocumentFolder.CASE_DOCUMENTS} diff --git a/apps/judicial-system/backend/src/app/modules/file/test/internalFileController/deliverCaseFileToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/file/test/internalFileController/deliverCaseFileToCourt.spec.ts index 14f414936b66..2331c777d937 100644 --- a/apps/judicial-system/backend/src/app/modules/file/test/internalFileController/deliverCaseFileToCourt.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/file/test/internalFileController/deliverCaseFileToCourt.spec.ts @@ -140,7 +140,6 @@ describe('InternalFileController - Deliver case file to court', () => { caseFileCategory | courtDocumentFolder ${CaseFileCategory.COURT_RECORD} | ${CourtDocumentFolder.COURT_DOCUMENTS} ${CaseFileCategory.RULING} | ${CourtDocumentFolder.COURT_DOCUMENTS} - ${CaseFileCategory.INDICTMENT} | ${CourtDocumentFolder.INDICTMENT_DOCUMENTS} ${CaseFileCategory.CRIMINAL_RECORD} | ${CourtDocumentFolder.INDICTMENT_DOCUMENTS} ${CaseFileCategory.COST_BREAKDOWN} | ${CourtDocumentFolder.INDICTMENT_DOCUMENTS} ${CaseFileCategory.CASE_FILE} | ${CourtDocumentFolder.CASE_DOCUMENTS} diff --git a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx index abf898cd975c..af794c72c5b6 100644 --- a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx +++ b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx @@ -105,7 +105,6 @@ const useFilteredCaseFiles = (caseFiles?: CaseFile[] | null) => { } return { - indictments: filterByCategories(CaseFileCategory.INDICTMENT), criminalRecords: filterByCategories(CaseFileCategory.CRIMINAL_RECORD), costBreakdowns: filterByCategories(CaseFileCategory.COST_BREAKDOWN), others: filterByCategories(CaseFileCategory.CASE_FILE), @@ -174,11 +173,6 @@ const IndictmentCaseFilesList: FC = ({ {displayHeading && ( )} - {displayGeneratedPDFs && ( diff --git a/libs/judicial-system/types/src/lib/case.ts b/libs/judicial-system/types/src/lib/case.ts index 25beea51adcf..a6761b6af97b 100644 --- a/libs/judicial-system/types/src/lib/case.ts +++ b/libs/judicial-system/types/src/lib/case.ts @@ -376,13 +376,7 @@ export const isTrafficViolationCase = (theCase: { indictmentSubtypes?: IndictmentSubtypeMap caseFiles?: { category?: CaseFileCategory | null }[] | null }): boolean => { - if ( - theCase.type !== CaseType.INDICTMENT || - !theCase.indictmentSubtypes || - theCase.caseFiles?.some( - (file) => file.category === CaseFileCategory.INDICTMENT, - ) - ) { + if (theCase.type !== CaseType.INDICTMENT || !theCase.indictmentSubtypes) { return false } diff --git a/libs/judicial-system/types/src/lib/file.ts b/libs/judicial-system/types/src/lib/file.ts index 17b320bdfb52..6940ccb395db 100644 --- a/libs/judicial-system/types/src/lib/file.ts +++ b/libs/judicial-system/types/src/lib/file.ts @@ -7,7 +7,6 @@ export enum CaseFileState { export enum CaseFileCategory { COURT_RECORD = 'COURT_RECORD', RULING = 'RULING', - INDICTMENT = 'INDICTMENT', CRIMINAL_RECORD = 'CRIMINAL_RECORD', CRIMINAL_RECORD_UPDATE = 'CRIMINAL_RECORD_UPDATE', COST_BREAKDOWN = 'COST_BREAKDOWN', From 0ccbff3410d2479530bfab306034a0a62a83d4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Fri, 17 Jan 2025 10:06:43 +0000 Subject: [PATCH 66/68] Removes unused code --- .../backend/migrations/20241211095654-update-defendant.js | 2 +- .../case/test/caseController/createCourtCase.spec.ts | 1 - .../src/app/modules/file/limitedAccessFile.controller.ts | 6 +----- .../deliverSubpoenaToPolice.spec.ts | 3 +-- .../Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx | 1 - .../web/src/routes/Shared/Cases/ActiveCases.tsx | 5 +---- .../web/src/utils/hooks/useSections/index.ts | 3 --- 7 files changed, 4 insertions(+), 17 deletions(-) diff --git a/apps/judicial-system/backend/migrations/20241211095654-update-defendant.js b/apps/judicial-system/backend/migrations/20241211095654-update-defendant.js index f8d0249598cc..191abac0f30e 100644 --- a/apps/judicial-system/backend/migrations/20241211095654-update-defendant.js +++ b/apps/judicial-system/backend/migrations/20241211095654-update-defendant.js @@ -16,7 +16,7 @@ module.exports = { ]), ) }, - async down(queryInterface, Sequelize) { + async down(queryInterface) { return queryInterface.sequelize.transaction((t) => queryInterface.removeColumn('defendant', 'punishment_type', { transaction: t, diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts index 142af91b6a0b..97be863b28c4 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/createCourtCase.spec.ts @@ -294,7 +294,6 @@ describe('CaseController - Create court case', () => { const caseId = uuid() const policeCaseNumber1 = uuid() const policeCaseNumber2 = uuid() - const indictmentId = uuid() const criminalRecordId = uuid() const costBreakdownId = uuid() const uncategorisedId = uuid() diff --git a/apps/judicial-system/backend/src/app/modules/file/limitedAccessFile.controller.ts b/apps/judicial-system/backend/src/app/modules/file/limitedAccessFile.controller.ts index 5285a7aa0a70..61fab9e181c2 100644 --- a/apps/judicial-system/backend/src/app/modules/file/limitedAccessFile.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/file/limitedAccessFile.controller.ts @@ -37,11 +37,7 @@ import { LimitedAccessCaseExistsGuard, } from '../case' import { MergedCaseExistsGuard } from '../case/guards/mergedCaseExists.guard' -import { - CivilClaimant, - CivilClaimantExistsGuard, - CurrentCivilClaimant, -} from '../defendant' +import { CivilClaimantExistsGuard } from '../defendant' import { CreateFileDto } from './dto/createFile.dto' import { CreatePresignedPostDto } from './dto/createPresignedPost.dto' import { CurrentCaseFile } from './guards/caseFile.decorator' diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts index ff02a709d797..c2c523ce3da8 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts @@ -59,13 +59,12 @@ describe('InternalSubpoenaController - Deliver subpoena to police', () => { describe('subpoena delivered to police', () => { const subpoenaPdf = uuid() - let then: Then beforeEach(async () => { const mockGetSubpoenaPdf = mockPdfService.getSubpoenaPdf as jest.Mock mockGetSubpoenaPdf.mockResolvedValue(subpoenaPdf) - then = await givenWhenThen() + await givenWhenThen() }) it('should call deliverSubpoenaToPolice', () => { diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx index 0cb222be97c0..7601b4e95d23 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Defendant/PoliceCaseInfo/PoliceCaseInfo.tsx @@ -71,7 +71,6 @@ export const PoliceCaseInfo: FC = ({ updatePoliceCase, policeCaseNumberImmutable = false, updateIndictmentCount, - indictmentCount, }) => { const { formatMessage } = useIntl() diff --git a/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx b/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx index 29cdaa3286de..eba84c6b13f3 100644 --- a/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx +++ b/apps/judicial-system/web/src/routes/Shared/Cases/ActiveCases.tsx @@ -17,10 +17,7 @@ import { DefendantInfo, } from '@island.is/judicial-system-web/src/components/Table' import Table from '@island.is/judicial-system-web/src/components/Table/Table' -import { - CaseListEntry, - Defendant, -} from '@island.is/judicial-system-web/src/graphql/schema' +import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema' interface Props { cases: CaseListEntry[] diff --git a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts index f365d1b50fc9..7d0be60bbdc2 100644 --- a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts @@ -1,4 +1,3 @@ -import { useContext } from 'react' import { useIntl } from 'react-intl' import { useRouter } from 'next/router' @@ -18,7 +17,6 @@ import { isRestrictionCase, } from '@island.is/judicial-system/types' import { core, sections } from '@island.is/judicial-system-web/messages' -import { FeatureContext } from '@island.is/judicial-system-web/src/components' import { RouteSection } from '@island.is/judicial-system-web/src/components/PageLayout/PageLayout' import { formatCaseResult } from '@island.is/judicial-system-web/src/components/PageLayout/utils' import { @@ -61,7 +59,6 @@ const useSections = ( ) => { const { formatMessage } = useIntl() const router = useRouter() - const { features } = useContext(FeatureContext) const isActive = (pathname: string) => router.pathname.replace(/\/\[\w+\]/g, '') === pathname From 9486abc9879c94d58b38696704c790f64ddcd2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Fri, 17 Jan 2025 10:22:57 +0000 Subject: [PATCH 67/68] Renames client route constanst --- .../routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx | 2 +- .../Prosecutor/Indictments/Processing/Processing.tsx | 2 +- apps/judicial-system/web/src/utils/formHelper.ts | 4 ++-- .../web/src/utils/hooks/useSections/index.ts | 8 ++++---- libs/judicial-system/consts/src/lib/consts.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx index b3d2520d335e..bc76c7fd1cb2 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFiles/CaseFiles.tsx @@ -166,7 +166,7 @@ const CaseFiles = () => { handleNavigationTo(constants.INDICTMENTS_OVERVIEW_ROUTE) } diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx index a27679249bea..376bb0be3d61 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx @@ -660,7 +660,7 @@ const Processing: FC = () => { nextButtonIcon="arrowForward" previousUrl={`${constants.INDICTMENTS_CASE_FILE_ROUTE}/${workingCase.id}`} nextIsDisabled={!stepIsValid} - nextUrl={constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE} + nextUrl={constants.INDICTMENTS_INDICTMENT_ROUTE} /> diff --git a/apps/judicial-system/web/src/utils/formHelper.ts b/apps/judicial-system/web/src/utils/formHelper.ts index ff9aaa083224..5d1b73f97de5 100644 --- a/apps/judicial-system/web/src/utils/formHelper.ts +++ b/apps/judicial-system/web/src/utils/formHelper.ts @@ -173,7 +173,7 @@ export type stepValidationsType = { [constants.INVESTIGATION_CASE_POLICE_CONFIRMATION_ROUTE]: () => boolean [constants.INDICTMENTS_CASE_FILE_ROUTE]: () => boolean [constants.INDICTMENTS_PROCESSING_ROUTE]: (theCase: Case) => boolean - [constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE]: (theCase: Case) => boolean + [constants.INDICTMENTS_INDICTMENT_ROUTE]: (theCase: Case) => boolean [constants.INDICTMENTS_CASE_FILES_ROUTE]: (theCase: Case) => boolean [constants.RESTRICTION_CASE_RECEPTION_AND_ASSIGNMENT_ROUTE]: ( theCase: Case, @@ -255,7 +255,7 @@ export const stepValidations = (): stepValidationsType => { [constants.INDICTMENTS_CASE_FILE_ROUTE]: () => true, [constants.INDICTMENTS_PROCESSING_ROUTE]: (theCase: Case) => validations.isProcessingStepValidIndictments(theCase), - [constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE]: (theCase: Case) => + [constants.INDICTMENTS_INDICTMENT_ROUTE]: (theCase: Case) => validations.isIndictmentStepValid(theCase), [constants.INDICTMENTS_CASE_FILES_ROUTE]: () => true, [constants.INDICTMENTS_SUMMARY_ROUTE]: () => true, diff --git a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts index 7d0be60bbdc2..17b76a2bf529 100644 --- a/apps/judicial-system/web/src/utils/hooks/useSections/index.ts +++ b/apps/judicial-system/web/src/utils/hooks/useSections/index.ts @@ -501,10 +501,10 @@ const useSections = ( name: formatMessage( sections.indictmentCaseProsecutorSection.indictment, ), - href: `${constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE}/${id}`, - isActive: isActive(constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE), + href: `${constants.INDICTMENTS_INDICTMENT_ROUTE}/${id}`, + isActive: isActive(constants.INDICTMENTS_INDICTMENT_ROUTE), onClick: - !isActive(constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE) && + !isActive(constants.INDICTMENTS_INDICTMENT_ROUTE) && validateFormStepper( isValid, [ @@ -518,7 +518,7 @@ const useSections = ( onNavigationTo ? async () => await onNavigationTo( - constants.INDICTMENTS_TRAFFIC_VIOLATION_ROUTE, + constants.INDICTMENTS_INDICTMENT_ROUTE, ) : undefined, }, diff --git a/libs/judicial-system/consts/src/lib/consts.ts b/libs/judicial-system/consts/src/lib/consts.ts index a2dcfaeb522f..f13bde76f864 100644 --- a/libs/judicial-system/consts/src/lib/consts.ts +++ b/libs/judicial-system/consts/src/lib/consts.ts @@ -188,7 +188,7 @@ export const INDICTMENTS_DEFENDANT_ROUTE = '/akaera/akaerdi' export const INDICTMENTS_POLICE_CASE_FILES_ROUTE = '/akaera/malsgogn' export const INDICTMENTS_CASE_FILE_ROUTE = '/akaera/skjalaskra' export const INDICTMENTS_PROCESSING_ROUTE = '/akaera/malsmedferd' -export const INDICTMENTS_TRAFFIC_VIOLATION_ROUTE = '/akaera/akaera' +export const INDICTMENTS_INDICTMENT_ROUTE = '/akaera/akaera' export const INDICTMENTS_CASE_FILES_ROUTE = '/akaera/domskjol' export const INDICTMENTS_OVERVIEW_ROUTE = '/akaera/stadfesta' export const CLOSED_INDICTMENT_OVERVIEW_ROUTE = '/akaera/yfirlit' @@ -230,7 +230,7 @@ export const prosecutorIndictmentRoutes = [ INDICTMENTS_POLICE_CASE_FILES_ROUTE, INDICTMENTS_CASE_FILE_ROUTE, INDICTMENTS_PROCESSING_ROUTE, - INDICTMENTS_TRAFFIC_VIOLATION_ROUTE, + INDICTMENTS_INDICTMENT_ROUTE, INDICTMENTS_CASE_FILES_ROUTE, INDICTMENTS_OVERVIEW_ROUTE, ] From ea41a71550d01105cb9a49102450082244345cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Fri, 17 Jan 2025 10:30:30 +0000 Subject: [PATCH 68/68] Updates comments --- .../backend/src/app/modules/case/models/case.model.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/models/case.model.ts b/apps/judicial-system/backend/src/app/modules/case/models/case.model.ts index 96f58bc55d26..fd7493105df5 100644 --- a/apps/judicial-system/backend/src/app/modules/case/models/case.model.ts +++ b/apps/judicial-system/backend/src/app/modules/case/models/case.model.ts @@ -742,7 +742,7 @@ export class Case extends Model { crimeScenes?: CrimeSceneMap /********** - * The introduction to a traffic violation case + * The introduction to a indictment case **********/ @Column({ type: DataType.TEXT, allowNull: true }) @ApiPropertyOptional({ type: String }) @@ -1029,7 +1029,6 @@ export class Case extends Model { /********** * The md5 hash of the confirmed generated indictment - * Only used for traffic violation cases **********/ @Column({ type: DataType.STRING, allowNull: true }) @ApiPropertyOptional({ type: String })