Skip to content

Commit

Permalink
feat(j-s): Add punishment type tag column in prison cases overview ta…
Browse files Browse the repository at this point in the history
…ble (#17285)

* feat(j-s): js web utility array function

* feat(j-s): add punishment type columns in prison cases overview

* fix(j-s): fix sort by punishement type

* fix(j-s): format and clean-up

* fix(j-s): Address auto code review feedback

* fix(j-s): fix tests

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent b3d7757 commit b76b7dd
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CourtSessionType,
IndictmentCaseReviewDecision,
IndictmentDecision,
PunishmentType,
} from '@island.is/judicial-system/types'

import { Defendant } from '../../defendant'
Expand Down Expand Up @@ -142,4 +143,10 @@ export class CaseListEntry {

@Field(() => String, { nullable: true })
readonly indictmentCompletedDate?: string

// TEMP: Use with caution! This key will never be populated.
// It was added to bypass table component type checks for a required custom sort key
// until we have a resolution on how to handle multiple defendants in the case list
@Field(() => PunishmentType, { nullable: true })
readonly defendantsPunishmentType?: PunishmentType
}
5 changes: 5 additions & 0 deletions apps/judicial-system/web/messages/Core/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const tables = defineMessages({
defaultMessage: 'Dómstóll',
description: 'Notaður sem titill fyrir dómstóll dálk í lista yfir mál.',
},
punishmentType: {
id: 'judicial.system.core:tables.punishment_type',
defaultMessage: 'Refsitegund',
description: 'Notaður sem titill fyrir refsitegund dálk í lista yfir mál.',
},
sentencingDate: {
id: 'judicial.system.core:tables.sentencing_date',
defaultMessage: 'Dómsuppkvaðning',
Expand Down
2 changes: 2 additions & 0 deletions apps/judicial-system/web/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ const Table: FC<TableProps> = (props) => {
switch (column) {
case 'defendants':
return entry.defendants?.[0]?.name ?? ''
case 'defendantsPunishmentType':
return entry.defendants?.[0]?.punishmentType ?? ''
case 'courtCaseNumber':
return courtAbbreviation
? `${courtAbbreviation}: ${entry.courtCaseNumber}`
Expand Down
25 changes: 25 additions & 0 deletions apps/judicial-system/web/src/components/Tags/CaseTag.strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,29 @@ export const strings = defineMessages({
defaultMessage: 'Afturkallað',
description: 'Notað fyrir "Afturkallað" tagg',
},
punishmentTypeImprisonment: {
id: 'judicial.system.core:case_tag.punishment_type_imprisonment',
defaultMessage: 'Óskb.',
description: 'Notað fyrir "Óskilorðsbundið" tagg',
},
punishmentTypeProbation: {
id: 'judicial.system.core:case_tag.punishment_type_probation',
defaultMessage: 'Skb.',
description: 'Notað fyrir "Skilorðsbundið" tagg',
},
punishmentTypeFine: {
id: 'judicial.system.core:case_tag.punishment_type_fine',
defaultMessage: 'Sekt',
description: 'Notað fyrir "Sekt" tagg',
},
punishmentTypeIndictmentRulingDecisionFine: {
id: 'judicial.system.core:case_tag.punishment_type_indictment_ruling_decision_fine',
defaultMessage: 'VL',
description: 'Notað fyrir "Viðurlagaákvörðun" tagg',
},
punishmentTypeSignedFineInvitation: {
id: 'judicial.system.core:case_tag.punishment_type_signed_fine_invitation',
defaultMessage: 'ÁS',
description: 'Notað fyrir "Áritað sektarboð" tagg',
},
})
32 changes: 32 additions & 0 deletions apps/judicial-system/web/src/components/Tags/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TagVariant } from '@island.is/island-ui/core'
import {
isDistrictCourtUser,
isPublicProsecutorUser,
PunishmentType,
} from '@island.is/judicial-system/types'

import {
Expand Down Expand Up @@ -120,6 +121,37 @@ export const getIndictmentRulingDecisionTag = (
}
}

export const getPunishmentTypeTag = (
punishmentType?: PunishmentType | null,
): {
color: TagVariant
text: { id: string; defaultMessage: string; description: string }
} | null => {
if (!punishmentType) return null

const getPunishmentTypeLabel = (punishmentType?: PunishmentType | null) => {
switch (punishmentType) {
case PunishmentType.IMPRISONMENT:
return strings.punishmentTypeImprisonment
case PunishmentType.PROBATION:
return strings.punishmentTypeProbation
case PunishmentType.FINE:
return strings.punishmentTypeFine
case PunishmentType.INDICTMENT_RULING_DECISION_FINE:
return strings.punishmentTypeIndictmentRulingDecisionFine
case PunishmentType.SIGNED_FINE_INVITATION:
return strings.punishmentTypeSignedFineInvitation
default:
return strings.unknown
}
}

return {
color: 'red' as TagVariant,
text: getPunishmentTypeLabel(punishmentType),
}
}

export const getPrisonCaseStateTag = (
prisonCaseState: CaseState,
): {
Expand Down
24 changes: 23 additions & 1 deletion apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import {
getDurationDate,
} from '@island.is/judicial-system-web/src/components/Table'
import Table from '@island.is/judicial-system-web/src/components/Table/Table'
import { getPrisonCaseStateTag } from '@island.is/judicial-system-web/src/components/Tags/utils'
import {
getPrisonCaseStateTag,
getPunishmentTypeTag,
} from '@island.is/judicial-system-web/src/components/Tags/utils'
import {
CaseListEntry,
CaseState,
CaseType,
InstitutionType,
} from '@island.is/judicial-system-web/src/graphql/schema'
import { isNonEmptyArray } from '@island.is/judicial-system-web/src/utils/arrayHelpers'

import { usePrisonCasesQuery } from './prisonCases.generated'
import { cases as m } from './Cases.strings'
Expand Down Expand Up @@ -183,6 +187,10 @@ export const PrisonCases: FC = () => {
{
title: formatMessage(tables.court),
},
{
title: formatMessage(tables.punishmentType),
sortable: { isSortable: true, key: 'defendantsPunishmentType' },
},
{
title: capitalize(formatMessage(tables.sentencingDate)),
},
Expand Down Expand Up @@ -213,6 +221,20 @@ export const PrisonCases: FC = () => {
{
cell: (row) => <ColumnCaseType type={row.type} />,
},
{
cell: (row) => {
const punishmentType = isNonEmptyArray(row.defendants)
? row.defendants[0].punishmentType
: undefined
const punishmentTypeTag = getPunishmentTypeTag(punishmentType)
return punishmentTypeTag ? (
<CaseTag
color={punishmentTypeTag.color}
text={formatMessage(punishmentTypeTag.text)}
/>
) : null
},
},
{
cell: (row) => (
<CreatedDate created={row.indictmentCompletedDate} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ query Cases {
defenderChoice
verdictViewDate
isSentToPrisonAdmin
punishmentType
openedByPrisonAdminDate
}
defendantsPunishmentType
courtDate
isValidToDateInThePast
initialRulingDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ query PrisonCases {
name
noNationalId
defenderChoice
punishmentType
openedByPrisonAdminDate
}
courtDate
Expand Down
45 changes: 45 additions & 0 deletions apps/judicial-system/web/src/utils/arrayHelpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { isEmptyArray, isNonEmptyArray, isPresentArray } from './arrayHelpers'

describe('arrayHelpers', () => {
describe('isPresentArray', () => {
const testCases = [
{ input: undefined, expected: false },
{ input: null, expected: false },
{ input: [], expected: true },
{ input: [1], expected: true },
]
testCases.forEach(({ input, expected }) => {
it(`should return ${expected} for input ${input}`, () => {
expect(isPresentArray(input)).toBe(expected)
})
})
})

describe('isEmptyArray', () => {
const testCases = [
{ input: undefined, expected: false },
{ input: null, expected: false },
{ input: [], expected: true },
{ input: [1], expected: false },
]
testCases.forEach(({ input, expected }) => {
it(`should return ${expected} for input ${input}`, () => {
expect(isEmptyArray(input)).toBe(expected)
})
})
})

describe('isNonEmptyArray', () => {
const testCases = [
{ input: undefined, expected: false },
{ input: null, expected: false },
{ input: [], expected: false },
{ input: [1], expected: true },
]
testCases.forEach(({ input, expected }) => {
it(`should return ${expected} for input ${input}`, () => {
expect(isNonEmptyArray(input)).toBe(expected)
})
})
})
})
8 changes: 8 additions & 0 deletions apps/judicial-system/web/src/utils/arrayHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const isPresentArray = <T>(arr: T[] | undefined | null): arr is T[] =>
arr !== undefined && arr !== null && Array.isArray(arr)

export const isEmptyArray = <T>(arr: T[] | undefined | null): arr is T[] =>
isPresentArray(arr) && arr?.length === 0

export const isNonEmptyArray = <T>(arr: T[] | undefined | null): arr is T[] =>
isPresentArray(arr) && arr.length > 0

0 comments on commit b76b7dd

Please sign in to comment.