Skip to content

Commit 552243b

Browse files
[PRMP-859] Refactor upload to use doc config (other doc types)
1 parent cba93ca commit 552243b

30 files changed

+678
-271
lines changed

app/cypress/e2e/0-ndr-core-tests/auth_routes/auth_gp_clinical_path_access.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ describe('GP Clinical user role has access to the expected GP_CLINICAL workflow
4848
cy.url().should('eq', baseUrl + lloydGeorgeViewUrl);
4949
});
5050
});
51-
});
51+
});

app/package-lock.json

Lines changed: 37 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@testing-library/react": "16.3.0",
2929
"@testing-library/user-event": "14.6.1",
3030
"@vitejs/plugin-react-swc": "^4.2.2",
31+
"@zip.js/zip.js": "^2.8.11",
3132
"aws-rum-web": "^1.25.0",
3233
"axios": "^1.13.2",
3334
"dotenv": "^17.2.3",
@@ -79,8 +80,8 @@
7980
"@types/uuid": "^11.0.0",
8081
"@types/validator": "^13.15.10",
8182
"@vitest/coverage-v8": "^4.0.13",
82-
"@vitest/ui": "^4.0.13",
8383
"@vitest/spy": "^4.0.13",
84+
"@vitest/ui": "^4.0.13",
8485
"babel-plugin-named-exports-order": "^0.0.2",
8586
"cypress": "^15.7.0",
8687
"cypress-real-events": "^1.15.0",

app/src/components/blocks/_documentUpload/documentSelectOrderStage/DocumentSelectOrderStage.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../../../types/pages/UploadDocumentsPage/types';
88
import { MemoryRouter } from 'react-router-dom';
99
import { fileUploadErrorMessages } from '../../../../helpers/utils/fileUploadErrorMessages';
10-
import { buildLgFile } from '../../../../helpers/test/testBuilders';
10+
import { buildDocumentConfig, buildLgFile } from '../../../../helpers/test/testBuilders';
1111
import { Mock } from 'vitest';
1212
import { DOCUMENT_TYPE } from '../../../../helpers/utils/documentType';
1313

@@ -50,6 +50,8 @@ vi.mock('../documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
5050
},
5151
}));
5252

53+
const docConfig = buildDocumentConfig();
54+
5355
describe('DocumentSelectOrderStage', () => {
5456
let documents: UploadDocument[] = [];
5557

@@ -128,7 +130,7 @@ describe('DocumentSelectOrderStage', () => {
128130
renderSut(documents);
129131

130132
await waitFor(() => {
131-
expect(screen.getByText('Preview this Lloyd George record')).toBeInTheDocument();
133+
expect(screen.getByText(docConfig.content.previewUploadTitle as string)).toBeInTheDocument();
132134
expect(screen.getByTestId('lloyd-george-preview')).toBeInTheDocument();
133135
});
134136
});
@@ -817,6 +819,7 @@ function renderSutWithExistingDocs(
817819
setDocuments={mockSetDocuments}
818820
setMergedPdfBlob={mockSetMergedPdfBlob}
819821
existingDocuments={existingDocuments}
822+
documentConfig={docConfig}
820823
/>
821824
</MemoryRouter>,
822825
);
@@ -830,6 +833,7 @@ function renderSut(documents: UploadDocument[]): void {
830833
setDocuments={mockSetDocuments}
831834
setMergedPdfBlob={mockSetMergedPdfBlob}
832835
existingDocuments={[]}
836+
documentConfig={docConfig}
833837
/>
834838
</MemoryRouter>,
835839
);

app/src/components/blocks/_documentUpload/documentSelectOrderStage/DocumentSelectOrderStage.tsx

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import PatientSummary, { PatientInfo } from '../../../generic/patientSummary/Pat
2121
import ErrorBox from '../../../layout/errorBox/ErrorBox';
2222
import DocumentUploadLloydGeorgePreview from '../documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
2323
import SpinnerButton from '../../../generic/spinnerButton/SpinnerButton';
24-
import { DOCUMENT_TYPE } from '../../../../helpers/utils/documentType';
24+
import { DOCUMENT_TYPE, DOCUMENT_TYPE_CONFIG } from '../../../../helpers/utils/documentType';
2525

2626
type Props = {
2727
documents: UploadDocument[];
2828
setDocuments: SetUploadDocuments;
2929
setMergedPdfBlob: Dispatch<SetStateAction<Blob | undefined>>;
3030
existingDocuments: UploadDocument[] | undefined;
31+
documentConfig: DOCUMENT_TYPE_CONFIG;
3132
};
3233

3334
type FormData = {
@@ -41,10 +42,14 @@ const DocumentSelectOrderStage = ({
4142
setDocuments,
4243
setMergedPdfBlob,
4344
existingDocuments,
45+
documentConfig,
4446
}: Readonly<Props>): JSX.Element => {
4547
const navigate = useEnhancedNavigate();
4648
const journey = getJourney();
4749
const [stitchedBlobLoaded, setStitchedBlobLoaded] = useState(false);
50+
const [currentPreviewDocument, setCurrentPreviewDocument] = useState<
51+
UploadDocument | undefined
52+
>(documents.find((doc) => doc.file.type === 'application/pdf'));
4853

4954
const documentPositionKey = (documentId: string): string => {
5055
return `${documentId}`;
@@ -209,11 +214,17 @@ const DocumentSelectOrderStage = ({
209214
})
210215
.filter((item) => item !== undefined);
211216

212-
const viewPdfFile = async (file: File): Promise<void> => {
213-
const blob = await getMergedPdfBlob([file]);
214-
const url = URL.createObjectURL(blob);
217+
const viewPdfFile = async (document: UploadDocument): Promise<void> => {
218+
if (documentConfig.stitched) {
219+
const blob = await getMergedPdfBlob([document.file]);
220+
const url = URL.createObjectURL(blob);
215221

216-
window.open(url);
222+
window.open(url);
223+
224+
return;
225+
}
226+
227+
setCurrentPreviewDocument(document);
217228
};
218229

219230
type FileRowParams = {
@@ -246,12 +257,12 @@ const DocumentSelectOrderStage = ({
246257
{!ableToReposition && position}
247258
</Table.Cell>
248259
<Table.Cell className="view-cell">
249-
{document && (
260+
{document && document.file.type === 'application/pdf' && (
250261
<button
251262
type="button"
252263
className="link-button"
253-
onClick={(): Promise<void> => viewPdfFile(document.file)}
254-
aria-label="Preview - opens in a new tab"
264+
onClick={(): Promise<void> => viewPdfFile(document)}
265+
aria-label={`Preview${documentConfig.stitched ? ' - opens in a new tab' : ''}`}
255266
data-testid={`document-preview-${document.id}`}
256267
>
257268
View
@@ -290,6 +301,22 @@ const DocumentSelectOrderStage = ({
290301
});
291302
};
292303

304+
const getDocumentsForPreview = (): UploadDocument[] => {
305+
const docs = [];
306+
307+
if (documentConfig.stitched) {
308+
if (journey === 'update') {
309+
docs.push(...existingDocuments!);
310+
}
311+
312+
docs.push(...documents);
313+
} else if (currentPreviewDocument) {
314+
docs.push(currentPreviewDocument);
315+
}
316+
317+
return docs.sort((a, b) => a.position! - b.position!);
318+
};
319+
293320
return (
294321
<>
295322
<BackButton />
@@ -410,7 +437,7 @@ const DocumentSelectOrderStage = ({
410437
</Table>
411438

412439
<div>
413-
<h2>Preview this Lloyd George record</h2>
440+
<h2>{documentConfig.content.previewUploadTitle}</h2>
414441
<p>
415442
This shows how the final record will look when combined into a single
416443
document.{' '}
@@ -424,7 +451,11 @@ const DocumentSelectOrderStage = ({
424451

425452
<DocumentUploadLloydGeorgePreview
426453
documents={getDocumentsForPreview()}
427-
setMergedPdfBlob={setMergedPdfBlob}
454+
setMergedPdfBlob={(blob) => {
455+
if (documentConfig.stitched) {
456+
setMergedPdfBlob(blob);
457+
}
458+
}}
428459
stitchedBlobLoaded={(loaded: boolean): void => {
429460
setStitchedBlobLoaded(loaded);
430461
}}
@@ -452,18 +483,6 @@ const DocumentSelectOrderStage = ({
452483
</form>
453484
</>
454485
);
455-
456-
function getDocumentsForPreview(): UploadDocument[] {
457-
if (journey !== 'update' || !existingDocuments || existingDocuments.length === 0) {
458-
return documents
459-
.filter((doc) => doc.docType === DOCUMENT_TYPE.LLOYD_GEORGE)
460-
.sort((a, b) => a.position! - b.position!);
461-
}
462-
463-
return [...existingDocuments, ...documents]
464-
.filter((doc) => doc.docType === DOCUMENT_TYPE.LLOYD_GEORGE)
465-
.sort((a, b) => a.position! - b.position!);
466-
}
467486
};
468487

469488
export default DocumentSelectOrderStage;

0 commit comments

Comments
 (0)