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

PRMP-1035 Remove duplicate stitch lambda call #452

Merged
merged 19 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
33b9aa2
[PRMP-1035] Removed duplicate stitch call
steph-torres-nhs Oct 17, 2024
7438c7d
[PRMP-1035] update jsx and css to handle new showMenu logic position
steph-torres-nhs Oct 18, 2024
588cbd6
[PRMP-1035] fix jest unit tests
steph-torres-nhs Oct 18, 2024
7737785
[PRMP-1035] remove logs
steph-torres-nhs Oct 18, 2024
438a469
[PRMP-1035] remove unused React hooks from RecordCard and LGRecordPage
steph-torres-nhs Oct 18, 2024
9a17ddd
revert some test changes
steph-torres-nhs Oct 18, 2024
3ae8345
[PRMP-1035] add showMenu is false test case to RecordMenuCard tests
steph-torres-nhs Oct 18, 2024
a40f848
[prmp-1035] PR changes
NogaNHS Oct 22, 2024
bd43803
[prmp-1035] change prop default
NogaNHS Oct 23, 2024
9a8ff4a
[PMRP-1035] add resetDocStage to RecordCard, stop reusing old cloudfr…
steph-torres-nhs Oct 28, 2024
fa7b25d
[PRMP-1035] resetDocState on RecordCard load
steph-torres-nhs Oct 28, 2024
5145107
[PRMP-1035] fix eslint failure for pipeline
steph-torres-nhs Oct 28, 2024
cb7e1ec
[PRMP-1035] remove duplicate resetDocState call
steph-torres-nhs Oct 29, 2024
cc04150
Merge branch 'main' into prmp-1035
steph-torres-nhs Oct 29, 2024
532d208
Merge branch 'main' into prmp-1035
steph-torres-nhs Oct 29, 2024
c7cba71
Merge branch 'main' into prmp-1035
steph-torres-nhs Oct 30, 2024
2b5d7bd
[PRMP-1035] resetDocStage is needed on fullscreen click
steph-torres-nhs Oct 30, 2024
fdccd57
Merge branch 'main' into prmp-1035
steph-torres-nhs Oct 31, 2024
1fb0533
Merge branch 'main' into prmp-1035
steph-torres-nhs Oct 31, 2024
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
Expand Up @@ -20,6 +20,7 @@ import LloydGeorgeViewRecordStage, { Props } from './LloydGeorgeViewRecordStage'
import { createMemoryHistory } from 'history';
import { LG_RECORD_STAGE } from '../../../../types/blocks/lloydGeorgeStages';
import * as ReactRouter from 'react-router-dom';
import { useRef } from 'react';
const mockPdf = buildLgSearchResult();
const mockPatientDetails = buildPatientDetails();
jest.mock('../../../../helpers/hooks/useRole');
Expand Down Expand Up @@ -83,6 +84,7 @@ describe('LloydGeorgeViewRecordStage', () => {
async (stage) => {
renderComponent({
downloadStage: stage,
cloudFrontUrl: '',
});

expect(screen.getByRole('progressbar', { name: 'Loading...' })).toBeInTheDocument();
Expand Down Expand Up @@ -447,6 +449,7 @@ const renderComponent = (propsOverride?: Partial<Props>) => {
totalFileSizeInByte: mockPdf.total_file_size_in_byte,
refreshRecord: jest.fn(),
cloudFrontUrl: 'http://test.com',
showMenu: true,
...propsOverride,
};
render(<TestApp {...props} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import useTitle from '../../../../helpers/hooks/useTitle';
import { routeChildren } from '../../../../types/generic/routes';
import { useNavigate } from 'react-router-dom';
import PatientSimpleSummary from '../../../generic/patientSimpleSummary/PatientSimpleSummary';
import ProgressBar from '../../../generic/progressBar/ProgressBar';

export type Props = {
downloadStage: DOWNLOAD_STAGE;
Expand All @@ -39,6 +40,7 @@ export type Props = {
stage: LG_RECORD_STAGE;
refreshRecord: () => void;
cloudFrontUrl: string;
showMenu: boolean;
};

function LloydGeorgeViewRecordStage({
Expand All @@ -49,6 +51,7 @@ function LloydGeorgeViewRecordStage({
setStage,
refreshRecord,
cloudFrontUrl,
showMenu,
}: Props) {
const navigate = useNavigate();
const [fullScreen, setFullScreen] = useState(false);
Expand Down Expand Up @@ -80,8 +83,6 @@ function LloydGeorgeViewRecordStage({
hasRecordInStorage,
onClickFunctionForDownloadAndRemove: handleDownloadAndRemoveRecordButton,
});
const showMenu = recordLinksToShow.length > 0;

// @ts-ignore
const handleConfirmDownloadAndRemoveButton = () => {
navigate(routeChildren.LLOYD_GEORGE_DOWNLOAD_IN_PROGRESS);
Expand All @@ -101,6 +102,8 @@ function LloydGeorgeViewRecordStage({
const pageHeader = 'Available records';
useTitle({ pageTitle: pageHeader });

const menuClass = showMenu ? '--menu' : '--upload';

return (
<div className="lloydgeorge_record-stage">
{formState.errors.confirmDownloadRemove && (
Expand Down Expand Up @@ -209,17 +212,19 @@ function LloydGeorgeViewRecordStage({
<PatientSimpleSummary />
{!fullScreen ? (
<>
{showMenu ? (
<>
NogaNHS marked this conversation as resolved.
Show resolved Hide resolved
<div className="lloydgeorge_record-stage_flex">
<div className="lloydgeorge_record-stage_flex-row">
<RecordMenuCard
recordLinks={recordLinksToShow}
setStage={setStage}
/>
</div>
<div className="lloydgeorge_record-stage_flex-row">
<RecordMenuCard
className="lloydgeorge_record-stage_flex-row"
recordLinks={recordLinksToShow}
setStage={setStage}
showMenu={showMenu}
/>

<div
className={`lloydgeorge_record-stage_flex-row lloydgeorge_record-stage_flex-row${menuClass}`}
>
<RecordCard
downloadStage={downloadStage}
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
Expand All @@ -229,30 +234,21 @@ function LloydGeorgeViewRecordStage({
/>
</div>
</div>
) : (
</>
</>
) : (
<>
<div className="lloydgeorge_record-stage_fs">
<RecordCard
downloadStage={downloadStage}
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
isFullScreen={fullScreen}
refreshRecord={refreshRecord}
cloudFrontUrl={cloudFrontUrl}
/>
)}
</div>
</>
) : (
<div className="lloydgeorge_record-stage_fs">
<RecordCard
downloadStage={downloadStage}
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
isFullScreen={fullScreen}
refreshRecord={refreshRecord}
cloudFrontUrl={cloudFrontUrl}
/>
</div>
)}
</div>
);
Expand All @@ -273,7 +269,7 @@ const RecordDetails = ({
case DOWNLOAD_STAGE.INITIAL:
case DOWNLOAD_STAGE.PENDING:
case DOWNLOAD_STAGE.REFRESH:
return null;
return <ProgressBar status="Loading..." />;
case DOWNLOAD_STAGE.SUCCEEDED: {
const detailsProps = {
lastUpdated,
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/generic/pdfViewer/PdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Props = { fileUrl: String };
const PdfViewer = ({ fileUrl }: Props) => {
useEffect(() => {
const pdfObject = require('pdfobject');
pdfObject.embed(fileUrl + '#toolbar=0', '#pdf-viewer');
pdfObject.embed(fileUrl + '#toolbar', '#pdf-viewer');
NogaNHS marked this conversation as resolved.
Show resolved Hide resolved
}, [fileUrl]);

if (!fileUrl) return null;
Expand Down
13 changes: 3 additions & 10 deletions app/src/components/generic/recordCard/RecordCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import useConfig from '../../../helpers/hooks/useConfig';
import useBaseAPIUrl from '../../../helpers/hooks/useBaseAPIUrl';
import useBaseAPIHeaders from '../../../helpers/hooks/useBaseAPIHeaders';
import getLloydGeorgeRecord from '../../../helpers/requests/getLloydGeorgeRecord';
import { DOWNLOAD_STAGE } from '../../../types/generic/downloadStage';
import { render, screen, waitFor } from '@testing-library/react';
import RecordCard, { Props } from './RecordCard';
import { buildLgSearchResult } from '../../../helpers/test/testBuilders';
Expand Down Expand Up @@ -41,7 +40,6 @@ describe('RecordCard Component', () => {
heading: 'Mock Header Record',
fullScreenHandler: mockFullScreenHandler,
detailsElement: <div>Mock Details Element</div>,
downloadStage: DOWNLOAD_STAGE.INITIAL,
isFullScreen: false,
refreshRecord: jest.fn(),
cloudFrontUrl: 'https://test.com',
Expand Down Expand Up @@ -109,9 +107,9 @@ describe('RecordCard Component', () => {
});
});

it('renders ProgressBar while isLoading is true', async () => {
render(<RecordCard {...props} />);
expect(screen.getByText('Loading...')).toBeInTheDocument();
it('renders nothing while no cloudFrontUrl', async () => {
render(<RecordCard {...props} cloudFrontUrl="" />);
expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument();
});

it('removes ProgressBar once loading is complete', async () => {
Expand Down Expand Up @@ -165,11 +163,6 @@ describe('RecordCard Component', () => {
expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument();
expect(screen.queryByTestId('full-screen-btn')).not.toBeInTheDocument();
});

it('does not render PdfViewer when downloadStage is FAILED', async () => {
render(<RecordCard {...props} downloadStage={DOWNLOAD_STAGE.FAILED} />);
expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument();
});
});

describe('Navigation', () => {
Expand Down
17 changes: 4 additions & 13 deletions app/src/components/generic/recordCard/RecordCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Card } from 'nhsuk-react-components';
import React, { ReactNode, useEffect, useRef, useState } from 'react';
import { DOWNLOAD_STAGE } from '../../../types/generic/downloadStage';
import React, { ReactNode, useEffect, useRef } from 'react';
import PdfViewer from '../pdfViewer/PdfViewer';
import useRole from '../../../helpers/hooks/useRole';
import { REPOSITORY_ROLE } from '../../../types/generic/authRole';
import ProgressBar from '../progressBar/ProgressBar';

export type Props = {
heading: string;
fullScreenHandler: (clicked: true) => void;
detailsElement: ReactNode;
downloadStage: DOWNLOAD_STAGE;
isFullScreen: boolean;
refreshRecord: () => void;
cloudFrontUrl: string;
Expand All @@ -26,27 +23,21 @@ function RecordCard({
}: Props) {
const role = useRole();
const userIsGpClinical = role === REPOSITORY_ROLE.GP_CLINICAL;
const [isLoading, setIsLoading] = useState(true);
const mounted = useRef(false);

useEffect(() => {
const onPageLoad = async () => {
await refreshRecord();
setIsLoading(false);
};
if (!mounted.current) {
onPageLoad();
mounted.current = true;
void onPageLoad();
}
}, [refreshRecord]);

const Record = () => {
if (isLoading) {
return (
<div className="pl-7">
<ProgressBar status="Loading..." />
</div>
);
if (!cloudFrontUrl) {
AndyFlintNHS marked this conversation as resolved.
Show resolved Hide resolved
return null;
}
return <PdfViewer fileUrl={cloudFrontUrl} />;
};
Expand Down
71 changes: 64 additions & 7 deletions app/src/components/generic/recordMenuCard/RecordMenuCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const mockLinks: Array<LGRecordActionLink> = [
},
];

const className = 'lloydgeorge_record-stage_flex-row';
AndyFlintNHS marked this conversation as resolved.
Show resolved Hide resolved

jest.mock('react-router-dom', () => ({
Link: (props: LinkProps) => <a {...props} role="link" />,
useNavigate: () => mockedUseNavigate,
Expand All @@ -66,7 +68,14 @@ describe('RecordMenuCard', () => {

describe('Rendering', () => {
it('renders menu', () => {
render(<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} />);
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Download record' })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Remove files' })).toBeInTheDocument();
Expand All @@ -80,7 +89,12 @@ describe('RecordMenuCard', () => {
);

const { rerender } = render(
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinksUpdateOnly} />,
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinksUpdateOnly}
className={className}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Upload files' })).toBeInTheDocument();
Expand All @@ -94,7 +108,12 @@ describe('RecordMenuCard', () => {
(link) => link.type === RECORD_ACTION.DOWNLOAD,
);
rerender(
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinksDownloadOnly} />,
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinksDownloadOnly}
className={className}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Download record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Download files' })).toBeInTheDocument();
Expand All @@ -108,13 +127,25 @@ describe('RecordMenuCard', () => {

it('does not render anything if the given record links array is empty', () => {
const { container } = render(
<RecordMenuCard setStage={mockSetStage} recordLinks={[]} />,
<RecordMenuCard
setStage={mockSetStage}
recordLinks={[]}
className={className}
showMenu={false}
/>,
);
expect(container).toBeEmptyDOMElement();
});

it('render menu item as a <button> if link item does not have stage or href', () => {
render(<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} />);
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
);
expect(
screen.getByRole('button', { name: 'Download and remove files' }),
).toBeInTheDocument();
Expand All @@ -125,11 +156,30 @@ describe('RecordMenuCard', () => {

expect(mockShowDownloadAndRemoveConfirmation).toBeCalledTimes(1);
});

it('Does not render the MenuCard if showMenu is false', () => {
const { container } = render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={false}
/>,
);
expect(container).toBeEmptyDOMElement();
});
});

describe('Navigation', () => {
it('navigates to href when clicked', () => {
render(<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} />);
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Upload files' })).toBeInTheDocument();
act(() => {
Expand All @@ -139,7 +189,14 @@ describe('RecordMenuCard', () => {
});

it('change stage when clicked', () => {
render(<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} />);
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Remove files' })).toBeInTheDocument();

Expand Down
Loading
Loading