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

chore(j-s): Use Table component for appealed cases #14764

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useMemo } from 'react'
import { useIntl } from 'react-intl'
import cn from 'classnames'
import { AnimatePresence } from 'framer-motion'

import { Box, Text } from '@island.is/island-ui/core'
import { theme } from '@island.is/island-ui/theme'
Expand All @@ -15,24 +13,17 @@ import {
CourtCaseNumber,
DefendantInfo,
getDurationDate,
SortButton,
TableContainer,
TableHeaderText,
} from '@island.is/judicial-system-web/src/components/Table'
import {
CaseDecision,
CaseListEntry,
CaseState,
Defendant,
} from '@island.is/judicial-system-web/src/graphql/schema'
import { CaseListEntry } from '@island.is/judicial-system-web/src/graphql/schema'
import {
useCaseList,
useSortAppealCases,
useViewport,
} from '@island.is/judicial-system-web/src/utils/hooks'

import { useContextMenu } from '../../ContextMenu/ContextMenu'
import Table, { TableWrapper } from '../Table'
import MobileAppealCase from './MobileAppealCase'
import * as styles from '../Table.css'

interface Props {
cases: CaseListEntry[]
Expand All @@ -43,10 +34,9 @@ interface Props {
const AppealCasesTable: React.FC<Props> = (props) => {
const { cases, loading, showingCompletedCases } = props
const { formatMessage } = useIntl()
const { isOpeningCaseId, handleOpenCase, LoadingIndicator, showLoading } =
useCaseList()
const { sortedData, requestSort, getClassNamesFor, isActiveColumn } =
useSortAppealCases('appealedDate', 'descending', cases)
const { isOpeningCaseId, handleOpenCase, showLoading } = useCaseList()
const { sortedData } = useSortAppealCases('appealedDate', 'descending', cases)
const { openCaseInNewTabMenuItem } = useContextMenu()
const activeCasesData = useMemo(
() =>
cases.sort((a: CaseListEntry, b: CaseListEntry) =>
Expand All @@ -70,7 +60,7 @@ const AppealCasesTable: React.FC<Props> = (props) => {
<Text fontWeight={'medium'} variant="small">
{isRestrictionCase(theCase.type)
? `${formatDate(theCase.rulingDate ?? '', 'd.M.y')} -
${formatDate(theCase.validToDate ?? '', 'd.M.y')}`
${formatDate(theCase.validToDate ?? '', 'd.M.y')}`
: ''}
</Text>
)}
Expand All @@ -79,101 +69,85 @@ const AppealCasesTable: React.FC<Props> = (props) => {
))}
</>
) : (
<TableContainer
loading={loading}
tableHeader={
<>
<TableHeaderText title={formatMessage(tables.caseNumber)} />
<th className={cn(styles.th, styles.largeColumn)}>
<SortButton
title={capitalize(formatMessage(core.defendant, { suffix: 'i' }))}
onClick={() => requestSort('defendant')}
sortAsc={getClassNamesFor('defendant') === 'ascending'}
sortDes={getClassNamesFor('defendant') === 'descending'}
isActive={isActiveColumn('defendant')}
/>
</th>
<TableHeaderText title={formatMessage(tables.type)} />
<TableHeaderText title={formatMessage(tables.state)} />
{showingCompletedCases ? (
<TableHeaderText title={formatMessage(tables.duration)} />
) : (
<th className={cn(styles.th, styles.largeColumn)}>
<SortButton
title={formatMessage(tables.appealDate)}
onClick={() => requestSort('appealedDate')}
sortAsc={getClassNamesFor('appealedDate') === 'ascending'}
sortDes={getClassNamesFor('appealedDate') === 'descending'}
isActive={isActiveColumn('appealedDate')}
/>
</th>
)}
<th></th>
</>
}
>
{sortedData.map((column) => {
return (
<tr
className={styles.row}
onClick={() => handleOpenCase(column.id)}
key={column.id}
>
<td>
<TableWrapper loading={loading}>
<Table
thead={[
{
title: formatMessage(tables.caseNumber),
},
{
title: capitalize(formatMessage(core.defendant, { suffix: 'i' })),
sortable: { isSortable: true, key: 'defendant' },
},
{
title: formatMessage(tables.type),
},
{ title: formatMessage(tables.state) },
{
title: showingCompletedCases
? formatMessage(tables.duration)
: formatMessage(tables.appealDate),
sortable: showingCompletedCases
? undefined
: { isSortable: true, key: 'appealedDate' },
},
]}
data={sortedData}
generateContextMenuItems={(row) => {
return [openCaseInNewTabMenuItem(row.id)]
}}
columns={[
{
cell: (row) => (
<CourtCaseNumber
courtCaseNumber={column.courtCaseNumber ?? ''}
policeCaseNumbers={column.policeCaseNumbers ?? []}
appealCaseNumber={column.appealCaseNumber ?? ''}
courtCaseNumber={row.courtCaseNumber ?? ''}
policeCaseNumbers={row.policeCaseNumbers ?? []}
appealCaseNumber={row.appealCaseNumber ?? ''}
/>
</td>
<td className={cn(styles.td, styles.largeColumn)}>
<DefendantInfo defendants={column.defendants as Defendant[]} />
</td>
<td>
),
},
{
cell: (row) => <DefendantInfo defendants={row.defendants} />,
},
{
cell: (row) => (
<ColumnCaseType
type={column.type}
decision={column.decision as CaseDecision}
parentCaseId={column.parentCaseId ?? ''}
type={row.type}
decision={row.decision}
parentCaseId={row.parentCaseId ?? ''}
/>
</td>
<td>
),
},
{
cell: (row) => (
<TagAppealState
appealState={column.appealState}
appealRulingDecision={column.appealRulingDecision}
appealCaseNumber={column.appealCaseNumber}
appealState={row.appealState}
appealRulingDecision={row.appealRulingDecision}
appealCaseNumber={row.appealCaseNumber}
/>
</td>
<td>
{showingCompletedCases ? (
<Text>
{isRestrictionCase(column.type)
),
},
{
cell: (row) => (
<Text>
{showingCompletedCases
? isRestrictionCase(row.type)
? getDurationDate(
column.state as CaseState,
column.validToDate,
column.initialRulingDate,
column.rulingDate,
row.state,
row.validToDate,
row.initialRulingDate,
row.rulingDate,
)
: ''}
</Text>
) : (
<Text>
{column.appealedDate
? formatDate(column.appealedDate, 'd.M.y')
: '-'}
</Text>
)}
</td>
<td className={styles.loadingContainer}>
<AnimatePresence>
{isOpeningCaseId === column.id && showLoading && (
<LoadingIndicator />
)}
</AnimatePresence>
</td>
</tr>
)
})}
</TableContainer>
: ''
: row.appealedDate
? formatDate(row.appealedDate, 'd.M.y')
: '-'}
</Text>
),
},
]}
/>
</TableWrapper>
)
}

Expand Down
6 changes: 5 additions & 1 deletion apps/judicial-system/web/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export enum LoginErrorCodes {
}

export type directionType = 'ascending' | 'descending'
export type sortableTableColumn = 'defendant' | 'createdAt' | 'courtDate'
export type sortableTableColumn =
| 'defendant'
| 'createdAt'
| 'courtDate'
| 'appealedDate'

export interface SortConfig {
column: sortableTableColumn
Expand Down
Loading