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): Table for reviewed cases #14778

Merged
merged 9 commits into from
May 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CaseDecision,
CaseState,
CaseType,
IndictmentCaseReviewDecision,
} from '@island.is/judicial-system/types'

import { Defendant } from '../../defendant'
Expand Down Expand Up @@ -108,6 +109,9 @@ export class CaseListEntry {
@Field(() => User, { nullable: true })
readonly indictmentReviewer?: User

@Field(() => IndictmentCaseReviewDecision, { nullable: true })
readonly indictmentReviewDecision?: IndictmentCaseReviewDecision

@Field(() => String, { nullable: true })
readonly indictmentAppealDeadline?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class CaseListInterceptor implements NestInterceptor {
theCase.explanatoryComments,
)?.comment,
indictmentReviewer: theCase.indictmentReviewer,
indictmentReviewDecision: theCase.indictmentReviewDecision,
}
}),
),
Expand Down
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 @@ -92,4 +92,9 @@ export const tables = defineMessages({
defaultMessage: 'Frestur',
description: 'Notaður sem titill fyrir frestur dálk í lista yfir mál.',
},
reviewDecision: {
id: 'judicial.system.core:tables.review_decision',
defaultMessage: 'Ákvörðun',
description: 'Notaður sem titill fyrir ákvörðun dálk í lista yfir mál.',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
PageHeader,
SharedPageLayout,
} from '@island.is/judicial-system-web/src/components'
import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema'

import { useCasesQuery } from '../../Shared/Cases/cases.generated'
import CasesForReview from '../Tables/CasesForReview'
import CasesReviewComplete from '../Tables/CasesReviewed'
import * as styles from '../../Shared/Cases/Cases.css'

export const PublicProsecutorCases: React.FC = () => {
Expand All @@ -24,8 +26,25 @@ export const PublicProsecutorCases: React.FC = () => {

const resCases = data?.cases

const casesForReview = useMemo(() => {
return resCases?.filter((c) => c.state && isCompletedCase(c.state)) || []
const { casesForReview, reviewedCases } = useMemo(() => {
return (resCases || []).reduce(
(acc, c) => {
if (
c.state &&
isCompletedCase(c.state) &&
!c.indictmentReviewDecision
) {
acc.casesForReview.push(c)
} else if (c.indictmentReviewDecision) {
acc.reviewedCases.push(c)
}
return acc
},
{ casesForReview: [], reviewedCases: [] } as {
casesForReview: CaseListEntry[]
reviewedCases: CaseListEntry[]
},
)
}, [resCases])

return (
Expand All @@ -44,7 +63,10 @@ export const PublicProsecutorCases: React.FC = () => {
/>
</div>
) : (
<CasesForReview cases={casesForReview} loading={loading} />
<>
<CasesForReview cases={casesForReview} loading={loading} />
<CasesReviewComplete cases={reviewedCases} loading={loading} />
</>
)}
</SharedPageLayout>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineMessages } from 'react-intl'

export const strings = defineMessages({
title: {
id: 'judicial.system.core:public_prosecutor.tables.cases_reviewed.title',
defaultMessage: 'Yfirlesin mál',
description: 'Notaður sem titill á yfirlesin mál málalista',
},
reviewTagAppealed: {
id: 'judicial.system.core:public_prosecutor.tables.cases_reviewed.review_tag_appealed',
defaultMessage: 'Áfrýjun',
description:
'Notað sem texti á tagg fyrir "Áfrýjun" tillögu í yfirlesin mál málalista',
},
reviewTagAccepted: {
id: 'judicial.system.core:public_prosecutor.tables.cases_reviewed.review_tag_completed',
defaultMessage: 'Unun',
description:
'Notað sem texti á tagg fyrir "Unun" tillögu í yfirlesin mál málalista',
},
infoContainerMessage: {
id: 'judicial.system.core:public_prosecutor.tables.cases_reviewed.info_container_message',
defaultMessage: 'Engin yfirlesin mál.',
description:
'Notaður sem skilaboð í upplýsingaglugga ef engin yfirlesin mál eru til.',
},
infoContainerTitle: {
id: 'judicial.system.core:public_prosecutor.tables.cases_reviewed.info_container_title',
defaultMessage: 'Engin mál',
description:
'Notaður sem titill á upplýsingaglugga ef engin yfirlesin mál eru til.',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { FC } from 'react'
import { 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 { 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'
import {
CourtCaseNumber,
DefendantInfo,
} from '@island.is/judicial-system-web/src/components/Table'
import Table, {
TableWrapper,
} from '@island.is/judicial-system-web/src/components/Table/Table'
import TableInfoContainer from '@island.is/judicial-system-web/src/components/Table/TableInfoContainer/TableInfoContainer'
import {
CaseListEntry,
IndictmentCaseReviewDecision,
} from '@island.is/judicial-system-web/src/graphql/schema'

import { strings } from './CasesReviewed.strings'

interface Props {
loading: boolean
cases: CaseListEntry[]
}

const CasesReviewed: FC<Props> = ({ loading, cases }) => {
const { formatMessage } = useIntl()
const { openCaseInNewTabMenuItem } = useContextMenu()

const decisionMapping = {
[IndictmentCaseReviewDecision.ACCEPT]: formatMessage(
strings.reviewTagAccepted,
),
[IndictmentCaseReviewDecision.APPEAL]: formatMessage(
strings.reviewTagAppealed,
),
}

return (
<>
<SectionHeading title={formatMessage(strings.title)} />
<AnimatePresence initial={false}>
<TableWrapper loading={loading}>
{cases.length > 0 ? (
<Table
thead={[
{
title: formatMessage(tables.caseNumber),
},
{
title: capitalize(
formatMessage(core.defendant, { suffix: 'i' }),
),
sortable: { isSortable: true, key: 'defendant' },
},
{ title: formatMessage(tables.reviewDecision) },
{ title: formatMessage(tables.prosecutorName) },
]}
data={cases}
generateContextMenuItems={(row) => {
return [openCaseInNewTabMenuItem(row.id)]
}}
columns={[
{
cell: (row) => (
<CourtCaseNumber
courtCaseNumber={row.courtCaseNumber ?? ''}
policeCaseNumbers={row.policeCaseNumbers ?? []}
appealCaseNumber={row.appealCaseNumber ?? ''}
/>
),
},
{
cell: (row) => <DefendantInfo defendants={row.defendants} />,
},
{
cell: (row) => (
<Tag variant="darkerBlue" outlined disabled truncate>
{row.indictmentReviewDecision &&
decisionMapping[row.indictmentReviewDecision]}
</Tag>
),
},
{
cell: (row: CaseListEntry) => (
<Text>{row.indictmentReviewer?.name}</Text>
),
},
]}
/>
) : (
<TableInfoContainer
title={formatMessage(strings.infoContainerTitle)}
message={formatMessage(strings.infoContainerMessage)}
/>
)}
</TableWrapper>
</AnimatePresence>
</>
)
}

export default CasesReviewed
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ query Cases {
id
name
}
indictmentReviewDecision
indictmentAppealDeadline
}
}
Loading