From dfc8aab25e14bac85baeb58633fd2512c3d698fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Tue, 25 Jun 2024 13:18:09 +0000 Subject: [PATCH] Use better types --- .../Table/PastCasesTable/PastCasesTable.tsx | 18 +++++++++--------- .../Cases/components/DefenderCasesTable.tsx | 18 +++++++++--------- .../src/utils/hooks/useSort/useSortCases.ts | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx b/apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx index c790a0965991..d37095f23706 100644 --- a/apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx +++ b/apps/judicial-system/web/src/components/Table/PastCasesTable/PastCasesTable.tsx @@ -53,7 +53,7 @@ const PastCasesTable: React.FC> = (props) => { const { isOpeningCaseId, handleOpenCase, LoadingIndicator, showLoading } = useCaseList() const { sortedData, requestSort, getClassNamesFor, isActiveColumn } = - useSortCases('createdAt', 'descending', cases) + useSortCases('created', 'descending', cases) const { withdrawAppealMenuOption, @@ -108,10 +108,10 @@ const PastCasesTable: React.FC> = (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')} /> @@ -120,10 +120,10 @@ const PastCasesTable: React.FC> = (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')} /> diff --git a/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx b/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx index 53357ebb4dc9..844888424542 100644 --- a/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx +++ b/apps/judicial-system/web/src/routes/Defender/Cases/components/DefenderCasesTable.tsx @@ -48,7 +48,7 @@ export const DefenderCasesTable: React.FC> = ( 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() @@ -77,10 +77,10 @@ export const DefenderCasesTable: React.FC> = ( 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" /> @@ -94,10 +94,10 @@ export const DefenderCasesTable: React.FC> = ( 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')} /> diff --git a/apps/judicial-system/web/src/utils/hooks/useSort/useSortCases.ts b/apps/judicial-system/web/src/utils/hooks/useSort/useSortCases.ts index b6912209a5c9..9fa8023ba261 100644 --- a/apps/judicial-system/web/src/utils/hooks/useSort/useSortCases.ts +++ b/apps/judicial-system/web/src/utils/hooks/useSort/useSortCases.ts @@ -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[], ) => { @@ -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') { @@ -24,7 +24,7 @@ const useSortCases = ( setSortConfig({ column, direction }) } - const getClassNamesFor = (column: string) => { + const getClassNamesFor = (column: sortableTableColumn) => { if (!sortConfig) { return } @@ -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 ) {