From 780d6ce564dfe0299184530921fb213314aa973b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Wed, 16 Oct 2024 11:34:54 +0000 Subject: [PATCH 1/2] Fixes case files record filtering by police case number --- .../Indictments/CaseFile/CaseFile.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx index e86149181923..eac2d8431a0d 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx @@ -25,12 +25,17 @@ const CaseFile = () => { useContext(FormContext) const caseFiles = useMemo(() => { - return ( - workingCase.caseFiles?.filter( - (caseFile) => caseFile.category === CaseFileCategory.CASE_FILE_RECORD, - ) ?? [] + return new Map( + workingCase.policeCaseNumbers?.map((policeCaseNumber) => [ + policeCaseNumber, + workingCase.caseFiles?.filter( + (caseFile) => + caseFile.policeCaseNumber === policeCaseNumber && + caseFile.category === CaseFileCategory.CASE_FILE_RECORD, + ), + ]), ) - }, [workingCase.caseFiles]) + }, [workingCase.caseFiles, workingCase.policeCaseNumbers]) const { formatMessage } = useIntl() const [editCount, setEditCount] = useState(0) @@ -73,7 +78,7 @@ const CaseFile = () => { caseId={workingCase.id} policeCaseNumber={policeCaseNumber} shouldStartExpanded={index === 0} - caseFiles={caseFiles} + caseFiles={caseFiles.get(policeCaseNumber) ?? []} subtypes={workingCase.indictmentSubtypes} crimeScenes={workingCase.crimeScenes} setEditCount={setEditCount} From d5e8c5229105b95e6dcc43614a8401d673e132aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Wed, 16 Oct 2024 12:00:13 +0000 Subject: [PATCH 2/2] Improves type safety --- .../routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx index eac2d8431a0d..8170d9b93f44 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/Indictments/CaseFile/CaseFile.tsx @@ -16,7 +16,10 @@ import { PdfButton, ProsecutorCaseInfo, } from '@island.is/judicial-system-web/src/components' -import { CaseFileCategory } from '@island.is/judicial-system-web/src/graphql/schema' +import { + CaseFile as TCaseFile, + CaseFileCategory, +} from '@island.is/judicial-system-web/src/graphql/schema' import { caseFile as m } from './CaseFile.strings' @@ -25,14 +28,14 @@ const CaseFile = () => { useContext(FormContext) const caseFiles = useMemo(() => { - return new Map( + return new Map( workingCase.policeCaseNumbers?.map((policeCaseNumber) => [ policeCaseNumber, workingCase.caseFiles?.filter( (caseFile) => caseFile.policeCaseNumber === policeCaseNumber && caseFile.category === CaseFileCategory.CASE_FILE_RECORD, - ), + ) ?? [], ]), ) }, [workingCase.caseFiles, workingCase.policeCaseNumbers])