Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(j-s): Add punishment type tag column in prison cases overview table #17285

Merged
merged 11 commits into from
Dec 19, 2024
Merged
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
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
}
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':
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
return entry.defendants?.[0]?.punishmentType ?? ''
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -119,3 +120,34 @@ export const getIndictmentRulingDecisionTag = (
return { color: 'darkerBlue', text: strings.complete }
}
}

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,
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
text: getPunishmentTypeLabel(punishmentType),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
titles,
} from '@island.is/judicial-system-web/messages'
import {
CaseTag,
Logo,
PageHeader,
SectionHeading,
Expand All @@ -31,12 +32,14 @@ import {
getDurationDate,
} from '@island.is/judicial-system-web/src/components/Table'
import Table from '@island.is/judicial-system-web/src/components/Table/Table'
import { 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 @@ -181,6 +184,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 @@ -211,6 +218,20 @@ export const PrisonCases: FC = () => {
{
cell: (row) => <ColumnCaseType type={row.type} />,
},
{
cell: (row) => {
const punishmentType = isNonEmptyArray(row.defendants)
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
? row.defendants[0].punishmentType
: undefined
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
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,7 +28,9 @@ query Cases {
defenderChoice
verdictViewDate
isSentToPrisonAdmin
punishmentType
}
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
}
courtDate
isValidToDateInThePast
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: true },
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
]
testCases.forEach(({ input, expected }) => {
it(`should return ${expected} for input ${input}`, () => {
expect(isEmptyArray(input)).toBe(expected)
})
})
})

describe('isEmptyArray', () => {
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)
})
})
})
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
})
8 changes: 8 additions & 0 deletions apps/judicial-system/web/src/utils/arrayHelpers.ts
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved
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 && Array.isArray(arr)
thorhildurt marked this conversation as resolved.
Show resolved Hide resolved

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
Loading