Skip to content

Commit

Permalink
Use better types
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsson committed Jun 25, 2024
1 parent 3512ce8 commit dfc8aab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const PastCasesTable: React.FC<React.PropsWithChildren<Props>> = (props) => {
const { isOpeningCaseId, handleOpenCase, LoadingIndicator, showLoading } =
useCaseList()
const { sortedData, requestSort, getClassNamesFor, isActiveColumn } =
useSortCases('createdAt', 'descending', cases)
useSortCases('created', 'descending', cases)

const {
withdrawAppealMenuOption,
Expand Down Expand Up @@ -108,10 +108,10 @@ const PastCasesTable: React.FC<React.PropsWithChildren<Props>> = (props) => {
title={capitalize(
formatMessage(core.defendant, { suffix: 'i' }),
)}
onClick={() => requestSort('defendant')}
sortAsc={getClassNamesFor('defendant') === 'ascending'}
sortDes={getClassNamesFor('defendant') === 'descending'}
isActive={isActiveColumn('defendant')}
onClick={() => requestSort('defendants')}
sortAsc={getClassNamesFor('defendants') === 'ascending'}
sortDes={getClassNamesFor('defendants') === 'descending'}
isActive={isActiveColumn('defendants')}
/>
</th>
<TableHeaderText title={formatMessage(tables.type)} />
Expand All @@ -120,10 +120,10 @@ const PastCasesTable: React.FC<React.PropsWithChildren<Props>> = (props) => {
title={capitalize(
formatMessage(tables.created, { suffix: 'i' }),
)}
onClick={() => requestSort('createdAt')}
sortAsc={getClassNamesFor('createdAt') === 'ascending'}
sortDes={getClassNamesFor('createdAt') === 'descending'}
isActive={isActiveColumn('createdAt')}
onClick={() => requestSort('created')}
sortAsc={getClassNamesFor('created') === 'ascending'}
sortDes={getClassNamesFor('created') === 'descending'}
isActive={isActiveColumn('created')}
/>
</th>
<TableHeaderText title={formatMessage(tables.state)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const DefenderCasesTable: React.FC<React.PropsWithChildren<Props>> = (
const { formatMessage } = useIntl()
const { cases, showingCompletedCases, loading } = props
const { sortedData, requestSort, getClassNamesFor, isActiveColumn } =
useSortCases('createdAt', 'descending', cases)
useSortCases('created', 'descending', cases)
const { isOpeningCaseId, LoadingIndicator, showLoading, handleOpenCase } =
useCaseList()

Expand Down Expand Up @@ -77,10 +77,10 @@ export const DefenderCasesTable: React.FC<React.PropsWithChildren<Props>> = (
title={capitalize(
formatMessage(core.defendant, { suffix: 'i' }),
)}
onClick={() => requestSort('defendant')}
sortAsc={getClassNamesFor('defendant') === 'ascending'}
sortDes={getClassNamesFor('defendant') === 'descending'}
isActive={isActiveColumn('defendant')}
onClick={() => requestSort('defendants')}
sortAsc={getClassNamesFor('defendants') === 'ascending'}
sortDes={getClassNamesFor('defendants') === 'descending'}
isActive={isActiveColumn('defendants')}
dataTestid="accusedNameSortButton"
/>
</th>
Expand All @@ -94,10 +94,10 @@ export const DefenderCasesTable: React.FC<React.PropsWithChildren<Props>> = (
title={capitalize(
formatMessage(tables.created, { suffix: 'i' }),
)}
onClick={() => requestSort('createdAt')}
sortAsc={getClassNamesFor('createdAt') === 'ascending'}
sortDes={getClassNamesFor('createdAt') === 'descending'}
isActive={isActiveColumn('createdAt')}
onClick={() => requestSort('created')}
sortAsc={getClassNamesFor('created') === 'ascending'}
sortDes={getClassNamesFor('created') === 'descending'}
isActive={isActiveColumn('created')}
/>
</th>
<th className={cn(styles.th, styles.largeColumn)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sortableTableColumn } from '@island.is/judicial-system-web/src/types'
import { compareLocaleIS } from '@island.is/judicial-system-web/src/utils/sortHelper'

const useSortCases = (
defaultColumn: string,
defaultColumn: sortableTableColumn,
defaultDirection: 'ascending' | 'descending',
data: CaseListEntry[],
) => {
Expand All @@ -14,7 +14,7 @@ const useSortCases = (
direction: defaultDirection,
})

const requestSort = (column: string) => {
const requestSort = (column: sortableTableColumn) => {
let direction: 'ascending' | 'descending' = 'ascending'

if (sortConfig.column === column && sortConfig.direction === 'ascending') {
Expand All @@ -24,7 +24,7 @@ const useSortCases = (
setSortConfig({ column, direction })
}

const getClassNamesFor = (column: string) => {
const getClassNamesFor = (column: sortableTableColumn) => {
if (!sortConfig) {
return
}
Expand All @@ -43,7 +43,7 @@ const useSortCases = (
return [...data].sort((a, b) => {
const getColumnValue = (entry: CaseListEntry) => {
if (
sortConfig.column === 'defendant' &&
sortConfig.column === 'defendants' &&
entry.defendants &&
entry.defendants.length > 0
) {
Expand Down

0 comments on commit dfc8aab

Please sign in to comment.