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 8 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 @@ -208,43 +211,29 @@ function LloydGeorgeViewRecordStage({
<h1>{pageHeader}</h1>
<PatientSimpleSummary />
{!fullScreen ? (
<>
{showMenu ? (
<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">
<RecordCard
downloadStage={downloadStage}
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
isFullScreen={fullScreen}
refreshRecord={refreshRecord}
cloudFrontUrl={cloudFrontUrl}
/>
</div>
</div>
) : (
<div className="lloydgeorge_record-stage_flex">
<RecordMenuCard
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} />}
isFullScreen={fullScreen}
refreshRecord={refreshRecord}
cloudFrontUrl={cloudFrontUrl}
/>
)}
</>
</div>
</div>
) : (
<div className="lloydgeorge_record-stage_fs">
<RecordCard
downloadStage={downloadStage}
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
Expand Down Expand Up @@ -273,7 +262,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
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
18 changes: 3 additions & 15 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,29 +23,20 @@ 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>
);
}
return <PdfViewer fileUrl={cloudFrontUrl} />;
return cloudFrontUrl ? <PdfViewer fileUrl={cloudFrontUrl} /> : null;
};

const RecordLayout = ({ children }: { children: ReactNode }) => {
Expand Down
37 changes: 30 additions & 7 deletions app/src/components/generic/recordMenuCard/RecordMenuCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ describe('RecordMenuCard', () => {

describe('Rendering', () => {
it('renders menu', () => {
render(<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} />);
render(
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} 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 +82,11 @@ describe('RecordMenuCard', () => {
);

const { rerender } = render(
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinksUpdateOnly} />,
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinksUpdateOnly}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Upload files' })).toBeInTheDocument();
Expand All @@ -94,7 +100,11 @@ describe('RecordMenuCard', () => {
(link) => link.type === RECORD_ACTION.DOWNLOAD,
);
rerender(
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinksDownloadOnly} />,
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinksDownloadOnly}
showMenu={true}
/>,
);
expect(screen.getByRole('heading', { name: 'Download record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Download files' })).toBeInTheDocument();
Expand All @@ -108,13 +118,15 @@ 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={[]} 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} showMenu={true} />,
);
expect(
screen.getByRole('button', { name: 'Download and remove files' }),
).toBeInTheDocument();
Expand All @@ -125,11 +137,20 @@ describe('RecordMenuCard', () => {

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

it('Does not render the MenuCard if showMenu is false', () => {
const { container } = render(
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} 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} showMenu={true} />,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Upload files' })).toBeInTheDocument();
act(() => {
Expand All @@ -139,7 +160,9 @@ describe('RecordMenuCard', () => {
});

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

Expand Down
53 changes: 32 additions & 21 deletions app/src/components/generic/recordMenuCard/RecordMenuCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Card } from 'nhsuk-react-components';
import React, { Dispatch, SetStateAction } from 'react';
import React, { Dispatch, HTMLAttributes, SetStateAction } from 'react';
import { LGRecordActionLink, RECORD_ACTION } from '../../../types/blocks/lloydGeorgeActions';
import { Link, useNavigate } from 'react-router-dom';
import { LG_RECORD_STAGE } from '../../../types/blocks/lloydGeorgeStages';

type Props = {
export type Props = HTMLAttributes<HTMLDivElement> & {
recordLinks: Array<LGRecordActionLink>;
setStage: Dispatch<SetStateAction<LG_RECORD_STAGE>>;
showMenu: boolean;
className: string;
};

type SubSectionProps = {
Expand All @@ -15,33 +17,38 @@ type SubSectionProps = {
setStage: Dispatch<SetStateAction<LG_RECORD_STAGE>>;
};

function RecordMenuCard({ recordLinks, setStage }: Props) {
function RecordMenuCard({ recordLinks, setStage, showMenu, className }: Props) {
const updateActions = recordLinks.filter((link) => link.type === RECORD_ACTION.UPDATE);
RioKnightleyNHS marked this conversation as resolved.
Show resolved Hide resolved
const downloadActions = recordLinks.filter((link) => link.type === RECORD_ACTION.DOWNLOAD);

if (recordLinks.length === 0) {
return <></>;
}

if (!showMenu) {
return <></>;
}
RioKnightleyNHS marked this conversation as resolved.
Show resolved Hide resolved
return (
<Card className="lloydgeorge_record-stage_menu">
<Card.Content className="lloydgeorge_record-stage_menu-content">
{updateActions.length > 0 && (
<SideMenuSubSection
actionLinks={updateActions}
heading="Update record"
setStage={setStage}
/>
)}
{downloadActions.length > 0 && (
<SideMenuSubSection
actionLinks={downloadActions}
heading="Download record"
setStage={setStage}
/>
)}
</Card.Content>
</Card>
<div className={className} data-testid="record-menu-card">
<Card className="lloydgeorge_record-stage_menu">
<Card.Content className="lloydgeorge_record-stage_menu-content">
{updateActions.length > 0 && (
<SideMenuSubSection
actionLinks={updateActions}
heading="Update record"
setStage={setStage}
/>
)}
{downloadActions.length > 0 && (
<SideMenuSubSection
actionLinks={downloadActions}
heading="Download record"
setStage={setStage}
/>
)}
</Card.Content>
</Card>
</div>
);
}

Expand Down Expand Up @@ -90,4 +97,8 @@ const LinkItem = ({ link, setStage }: LinkItemProps) => {
);
}
};

RecordMenuCard.defaultProps = {
className: 'lloydgeorge_record-stage_flex-row',
};
export default RecordMenuCard;
Loading
Loading