Skip to content

Commit

Permalink
feat(j-s): Allow multiple subtypes in indictments (#17192)
Browse files Browse the repository at this point in the history
* Add frontend changes for selecting indictment subtypes in indictment count

* Create migration

* Update DB on change

* Refactor

* Refactor

* chore: nx format:write update dirty files

* Add feature flag

* Refactor

* Refactor

* Add featur flag

* Remove console.log()

* Checkpoint

* Refactor

* Refactor

* Fix tests

* Fix lint

* Add hasOnlyOneItemInSubArrays to utils

* Add hasOnlyOneItemInSubArrays to utils

* Strip offence when removing traffic violation

* Add headings

* Fixes

* Refactor

* Remove all indictmentCountSubtypes on remove

* Refactor

* Fix lint

* Cleanup

* Refactor

* Refactor

* Refactor

* Rename import -- stepHelper to utils

* Break down a complex ternary statement into if statemetns

* Improve validation on indictment screen

* Improve type safety

* Remove unused code

* Refactor util

* Cleanup state on remove traffic violation

* Improve validation

* Refactor validation

* Fix imports

* Fix imports

* Remove console.log

* Fix issue with rendering traffic violation fields

* Fix issues with autofill

* Fix validation

* Add tests

* Add tests for isTrafficViolationStepValidIndictments validation function

* Add tests

* Refactor validation functionality

* Refactor validation functionality

* Refactor validation functionality

* Refactor variable setup

* Rename variables

* Refactor validation

* Merge

* Always use traffic violation description if traffic violation is selected

* Fix tests

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: Guðjón Guðjónsson <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2025
1 parent 048e423 commit acfeb49
Show file tree
Hide file tree
Showing 30 changed files with 848 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const caseEvent: Record<CaseEvent, string> = {
[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ð',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/stepHelper'
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/stepHelper'
import {
FormContextWrapper,
IntlProviderWrapper,
} from '@island.is/judicial-system-web/src/utils/testHelpers'
import * as utils from '@island.is/judicial-system-web/src/utils/utils'

import Summary from './Summary'

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -115,7 +114,7 @@ const Defendant = () => {
} = useDefendants()
const router = useRouter()

const { updateIndictmentCount } = useIndictmentCounts()
const { updateIndictmentCount, deleteIndictmentCount } = useIndictmentCounts()

const [policeCases, setPoliceCases] = useState<PoliceCase[]>([])

Expand Down Expand Up @@ -249,6 +248,12 @@ const Defendant = () => {
workingCase,
setWorkingCase,
)

const indictmentCountId = workingCase.indictmentCounts?.[index]?.id

if (indictmentCountId) {
deleteIndictmentCount(workingCase.id, indictmentCountId)
}
}

const handleUpdatePoliceCase = (
Expand Down Expand Up @@ -279,20 +284,28 @@ const Defendant = () => {
const handleUpdateIndictmentCount = (
policeCaseNumber: string,
crimeScene: CrimeScene,
subtypes?: Record<string, IndictmentSubtype[]>,
) => {
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,
} as UpdateIndictmentCount)
...(subtypes && {
indictmentCountSubtypes: subtypes[policeCaseNumber],
}),
})
})
}
}
Expand Down Expand Up @@ -506,6 +519,11 @@ const Defendant = () => {
workingCase.origin === CaseOrigin.LOKE && index === 0
}
updateIndictmentCount={handleUpdateIndictmentCount}
indictmentCount={workingCase.indictmentCounts?.find(
(indictmentCount) =>
indictmentCount.policeCaseNumber ===
workingCase.policeCaseNumbers?.[index],
)}
/>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
DateTime,
UserContext,
} from '@island.is/judicial-system-web/src/components'
import { TempIndictmentCount } from '@island.is/judicial-system-web/src/types'
import {
removeErrorMessageIfValid,
validateAndSetErrorMessage,
Expand Down Expand Up @@ -53,8 +54,10 @@ interface Props {
updateIndictmentCount: (
policeCaseNumber: string,
crimeScene: CrimeScene,
subtypes?: Record<string, IndictmentSubtype[]>,
) => void
policeCaseNumberImmutable: boolean
indictmentCount?: TempIndictmentCount
}

export const PoliceCaseInfo: FC<Props> = ({
Expand All @@ -68,6 +71,7 @@ export const PoliceCaseInfo: FC<Props> = ({
updatePoliceCase,
policeCaseNumberImmutable = false,
updateIndictmentCount,
indictmentCount,
}) => {
const { formatMessage } = useIntl()

Expand All @@ -82,6 +86,8 @@ export const PoliceCaseInfo: FC<Props> = ({
const [policeCaseNumberErrorMessage, setPoliceCaseNumberErrorMessage] =
useState<string>('')

const subtypesArray = subtypes || []

useEffect(() => {
if (policeCaseNumbers[index] !== originalPoliceCaseNumber) {
// This component is now handling a new police case number
Expand Down Expand Up @@ -208,10 +214,15 @@ export const PoliceCaseInfo: FC<Props> = ({
label={formatMessage(policeCaseInfo.indictmentTypeLabel)}
placeholder={formatMessage(policeCaseInfo.indictmentTypePlaceholder)}
onChange={(selectedOption) => {
const indictmentSubtype = selectedOption?.value as IndictmentSubtype
updatePoliceCase(index, {
subtypes: [...(subtypes || []), indictmentSubtype],
})
const indictmentSubtype = selectedOption?.value

if (!indictmentSubtype) {
return
}

const subtypes = [...subtypesArray, indictmentSubtype]

updatePoliceCase(index, { subtypes })
}}
value={null}
required
Expand All @@ -231,8 +242,21 @@ export const PoliceCaseInfo: FC<Props> = ({
variant="darkerBlue"
onClick={() => {
updatePoliceCase(index, {
policeCaseNumber: policeCaseNumbers[index],
subtypes: subtypes.filter((s) => s !== subtype),
})

updateIndictmentCount(
policeCaseNumbers[index],
crimeScene || {},
{
[policeCaseNumbers[index]]: subtypes.filter(
(s) =>
s !== subtype &&
indictmentCount?.indictmentCountSubtypes?.includes(s),
),
},
)
}}
aria-label={formatMessage(policeCaseInfo.removeSubtype, {
subtype: indictmentSubtypes[subtypes[0]],
Expand Down Expand Up @@ -261,10 +285,11 @@ export const PoliceCaseInfo: FC<Props> = ({
}}
onBlur={(event) => {
updatePoliceCase()
updateIndictmentCount(policeCaseNumbers[index], {
...crimeScene,
place: event.target.value,
})
updateIndictmentCount(
policeCaseNumbers[index],
{ ...crimeScene, place: event.target.value },
{ [policeCaseNumbers[index]]: subtypesArray },
)
}}
/>
</Box>
Expand All @@ -280,10 +305,11 @@ export const PoliceCaseInfo: FC<Props> = ({
crimeScene: { ...crimeScene, date: date },
})

updateIndictmentCount(policeCaseNumbers[index], {
...crimeScene,
date: date,
})
updateIndictmentCount(
policeCaseNumbers[index],
{ ...crimeScene, date: date },
{ [policeCaseNumbers[index]]: subtypesArray },
)
}
}}
/>
Expand Down
Loading

0 comments on commit acfeb49

Please sign in to comment.