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): Show district court abbreviation on mobile #17075

Merged
merged 12 commits into from
Dec 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export class CaseListEntry {
@Field(() => String, { nullable: true })
readonly prosecutorPostponedAppealDate?: string

@Field(() => Institution, { nullable: true })
readonly court?: Institution

@Field(() => User, { nullable: true })
readonly creatingProsecutor?: User

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ export const include: Includeable[] = [
]

export const caseListInclude: Includeable[] = [
{ model: Institution, as: 'court' },
{ model: Institution, as: 'prosecutorsOffice' },
{
model: Defendant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class CaseListInterceptor implements NestInterceptor {
// WARNING: Be careful when adding to this list. No sensitive information should be returned.
// If you need to add sensitive information, then you should consider adding a new endpoint
// for defenders and other user roles that are not allowed to see sensitive information.

return {
id: theCase.id,
created: theCase.created,
Expand Down Expand Up @@ -65,6 +64,7 @@ export class CaseListInterceptor implements NestInterceptor {
indictmentRulingDecision: theCase.indictmentRulingDecision,
courtSessionType: theCase.courtSessionType,
eventLogs: theCase.eventLogs,
court: theCase.court,
}
}),
),
Expand Down
40 changes: 24 additions & 16 deletions apps/judicial-system/web/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { AnimatePresence, motion } from 'framer-motion'

import { Box, Text } from '@island.is/island-ui/core'
import { theme } from '@island.is/island-ui/theme'
import { formatDate } from '@island.is/judicial-system/formatters'
import {
districtCourtAbbreviation,
formatDate,
} from '@island.is/judicial-system/formatters'
import {
CaseType,
isCompletedCase,
Expand Down Expand Up @@ -168,25 +171,30 @@ const Table: FC<TableProps> = (props) => {
return null
}

const getColumnValue = (
entry: CaseListEntry,
column: keyof CaseListEntry,
) => {
const courtAbbreviation = districtCourtAbbreviation(entry.court?.name)

switch (column) {
case 'defendants':
return entry.defendants?.[0]?.name ?? ''
case 'courtCaseNumber':
return courtAbbreviation
? `${courtAbbreviation}: ${entry.courtCaseNumber}`
: entry.courtCaseNumber ?? ''
default:
return entry[column]?.toString() ?? ''
}
}

useMemo(() => {
if (sortConfig) {
data.sort((a: CaseListEntry, b: CaseListEntry) => {
const getColumnValue = (entry: CaseListEntry) => {
if (
sortConfig.column === 'defendants' &&
entry.defendants &&
entry.defendants.length > 0 &&
entry.defendants[0].name
) {
return entry.defendants[0].name
}

return entry[sortConfig.column]?.toString()
}

const compareResult = compareLocaleIS(
getColumnValue(a),
getColumnValue(b),
getColumnValue(a, sortConfig.column),
getColumnValue(b, sortConfig.column),
oddsson marked this conversation as resolved.
Show resolved Hide resolved
)

return sortConfig.direction === 'ascending'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { useIntl } from 'react-intl'
import { AnimatePresence } from 'framer-motion'

import { Text } from '@island.is/island-ui/core'
import { capitalize, formatDate } from '@island.is/judicial-system/formatters'
import {
capitalize,
districtCourtAbbreviation,
formatDate,
} from '@island.is/judicial-system/formatters'
import { core, tables } from '@island.is/judicial-system-web/messages'
import { SectionHeading } from '@island.is/judicial-system-web/src/components'
import { useContextMenu } from '@island.is/judicial-system-web/src/components/ContextMenu/ContextMenu'
Expand Down Expand Up @@ -41,6 +45,10 @@ const CasesForReview: FC<CasesForReviewTableProps> = ({ loading, cases }) => {
thead={[
{
title: formatMessage(tables.caseNumber),
sortable: {
isSortable: true,
key: 'courtCaseNumber',
},
},
{
title: capitalize(
Expand All @@ -67,13 +75,21 @@ const CasesForReview: FC<CasesForReviewTableProps> = ({ loading, cases }) => {
}}
columns={[
{
cell: (row) => (
<CourtCaseNumber
courtCaseNumber={row.courtCaseNumber ?? ''}
policeCaseNumbers={row.policeCaseNumbers ?? []}
appealCaseNumber={row.appealCaseNumber ?? ''}
/>
),
cell: (row) => {
const courtAbbreviation = districtCourtAbbreviation(
row.court?.name,
)

return (
<CourtCaseNumber
courtCaseNumber={`${
courtAbbreviation ? `${courtAbbreviation}: ` : ''
}${row.courtCaseNumber ?? ''}`}
policeCaseNumbers={row.policeCaseNumbers ?? []}
appealCaseNumber={row.appealCaseNumber ?? ''}
/>
)
},
},
{
cell: (row) => <DefendantInfo defendants={row.defendants} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { MessageDescriptor, useIntl } from 'react-intl'
import { AnimatePresence } from 'framer-motion'

import { Tag, Text } from '@island.is/island-ui/core'
import { capitalize } from '@island.is/judicial-system/formatters'
import {
capitalize,
districtCourtAbbreviation,
} from '@island.is/judicial-system/formatters'
import { CaseIndictmentRulingDecision } from '@island.is/judicial-system/types'
import { core, tables } from '@island.is/judicial-system-web/messages'
import { SectionHeading } from '@island.is/judicial-system-web/src/components'
Expand Down Expand Up @@ -89,6 +92,10 @@ const CasesReviewed: FC<Props> = ({ loading, cases }) => {
thead={[
{
title: formatMessage(tables.caseNumber),
sortable: {
isSortable: true,
key: 'courtCaseNumber',
},
},
{
title: capitalize(
Expand All @@ -106,13 +113,21 @@ const CasesReviewed: FC<Props> = ({ loading, cases }) => {
}}
columns={[
{
cell: (row) => (
<CourtCaseNumber
courtCaseNumber={row.courtCaseNumber ?? ''}
policeCaseNumbers={row.policeCaseNumbers ?? []}
appealCaseNumber={row.appealCaseNumber ?? ''}
/>
),
cell: (row) => {
const courtAbbreviation = districtCourtAbbreviation(
row.court?.name,
)

return (
<CourtCaseNumber
courtCaseNumber={`${
courtAbbreviation ? `${courtAbbreviation}: ` : ''
}${row.courtCaseNumber ?? ''}`}
policeCaseNumbers={row.policeCaseNumbers ?? []}
appealCaseNumber={row.appealCaseNumber ?? ''}
/>
)
},
},
{
cell: (row) => <DefendantInfo defendants={row.defendants} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ query Cases {
initialRulingDate
rulingDate
rulingSignatureDate
court {
oddsson marked this conversation as resolved.
Show resolved Hide resolved
id
name
}
judge {
id
created
Expand Down
23 changes: 23 additions & 0 deletions libs/judicial-system/formatters/src/lib/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,29 @@ export const indictmentSubtypes: IndictmentSubtypes = {
THEFT: 'þjófnaður',
}

export const districtCourtAbbreviation = (courtName?: string | null) => {
switch (courtName) {
case 'Héraðsdómur Reykjavíkur':
return 'HDR'
case 'Héraðsdómur Reykjaness':
return 'HDRN'
case 'Héraðsdómur Vesturlands':
return 'HDV'
case 'Héraðsdómur Suðurlands':
return 'HDS'
case 'Héraðsdómur Norðurlands eystra':
return 'HDNE'
case 'Héraðsdómur Norðurlands vestra':
return 'HDNV'
case 'Héraðsdómur Austurlands':
return 'HDA'
case 'Héraðsdómur Vestfjarða':
return 'HDVF'
default:
return ''
}
}

export const getAppealResultTextByValue = (
value?: CaseAppealRulingDecision | null,
) => {
Expand Down
Loading