From 27eb459e3cdf9f22008956f2dcf54ee049e70a46 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Tue, 5 Nov 2024 07:41:37 +0100 Subject: [PATCH] OZG-6949 put nachrichtId in file api request --- client/src/api/attachments/attachmentsAPI.spec.ts | 4 ++-- client/src/api/attachments/attachmentsAPI.ts | 4 ++-- .../Compositions/MessageBody/MessageBody.test.tsx | 4 ++++ .../Compositions/MessageBody/MessageBody.tsx | 3 +++ .../AttachmentList/AttachmentList.test.tsx | 10 ++++++++-- .../Data Display/AttachmentList/AttachmentList.tsx | 9 +++++++-- client/src/routes/detail/DetailPage.tsx | 2 ++ 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/client/src/api/attachments/attachmentsAPI.spec.ts b/client/src/api/attachments/attachmentsAPI.spec.ts index d7242eb..fa7b590 100644 --- a/client/src/api/attachments/attachmentsAPI.spec.ts +++ b/client/src/api/attachments/attachmentsAPI.spec.ts @@ -66,7 +66,7 @@ describe("Attachments API tests", () => { }); test("attachment download success", async () => { const mockDownloadAttachment = jest.spyOn(axios, "get").mockReturnValue(Promise.resolve({ data: "asdf" })); - const result = await downloadAttachment("1", "2"); + const result = await downloadAttachment("1", "2", "3"); console.log("what", result); const resultText = await result.text(); expect(resultText).toEqual("asdf"); @@ -74,7 +74,7 @@ describe("Attachments API tests", () => { }); test("attachment download error", async () => { const mockDownloadAttachment = jest.spyOn(axios, "get").mockRejectedValue("some network error"); - await expect(downloadAttachment("1", "2")).rejects.toEqual(Error("attachments.error.network")); + await expect(downloadAttachment("1", "2", "3")).rejects.toEqual(Error("attachments.error.network")); expect(mockDownloadAttachment).toBeCalledTimes(1); }); test("trigger file save for downloaded file", () => { diff --git a/client/src/api/attachments/attachmentsAPI.ts b/client/src/api/attachments/attachmentsAPI.ts index 2c38d8e..c83bbc7 100644 --- a/client/src/api/attachments/attachmentsAPI.ts +++ b/client/src/api/attachments/attachmentsAPI.ts @@ -69,9 +69,9 @@ export async function uploadAttachment(vorgangId: string, nachrichtEventId: stri * @returns a Promise that resolves on successful download (with the file) and rejects on download * errors (with a localization key as the Error's message) */ -export async function downloadAttachment(nachrichtEventId: string, fileId: string): Promise<Blob> { +export async function downloadAttachment(nachrichtEventId: string, nachrichtId: string, fileId: string): Promise<Blob> { try { - const response = await axios.get(`/api/file/${nachrichtEventId}/${fileId}`, { + const response = await axios.get(`/api/file/${nachrichtEventId}/${nachrichtId}/${fileId}`, { responseType: "blob", timeout: 300000 }); diff --git a/client/src/components/Compositions/MessageBody/MessageBody.test.tsx b/client/src/components/Compositions/MessageBody/MessageBody.test.tsx index 0a926d7..3590a0a 100644 --- a/client/src/components/Compositions/MessageBody/MessageBody.test.tsx +++ b/client/src/components/Compositions/MessageBody/MessageBody.test.tsx @@ -28,6 +28,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" message="Message of clerk" attachments={[]} ariaLabel="message body" @@ -40,6 +41,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" message={`Message with\nline breaks`} attachments={[]} ariaLabel="message body" @@ -54,6 +56,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" message="Message of clerk with attachments" attachments={[ { id: "1", fileName: "file1.pdf", fileSize: 512000, contentType: "application/pdf" }, @@ -78,6 +81,7 @@ describe("Message body tests", () => { render( <MessageBody nachrichtEventId="1" + nachrichtId="2" index={2} message={"message"} attachments={[]} diff --git a/client/src/components/Compositions/MessageBody/MessageBody.tsx b/client/src/components/Compositions/MessageBody/MessageBody.tsx index ed7d3a5..74a2acb 100644 --- a/client/src/components/Compositions/MessageBody/MessageBody.tsx +++ b/client/src/components/Compositions/MessageBody/MessageBody.tsx @@ -30,6 +30,7 @@ const cyIdsPrefix = "message-body-"; interface MessageBodyProps extends React.HTMLAttributes<HTMLDivElement> { nachrichtEventId: string; + nachrichtId: string; message: string; attachments: AttachmentItem[]; // optionally pass an index that will be included in this component's data-cy attributes @@ -45,6 +46,7 @@ interface MessageBodyProps extends React.HTMLAttributes<HTMLDivElement> { */ export function MessageBody({ nachrichtEventId, + nachrichtId, message, attachments, index, @@ -73,6 +75,7 @@ export function MessageBody({ {attachments && !!attachments.length && ( <AttachmentList nachrichtEventId={nachrichtEventId} + nachrichtId={nachrichtId} attachments={attachments} closeIconLabel={closeIconLabel} /> diff --git a/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx b/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx index 997f9f1..4499e1a 100644 --- a/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx +++ b/client/src/components/Data Display/AttachmentList/AttachmentList.test.tsx @@ -28,6 +28,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[{ id: "1", fileName: "file.pdf", fileSize: 1572864, contentType: "application/pdf" }]} /> ); @@ -40,6 +41,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[{ id: "2", fileName: "file.pdf", fileSize: 1572864, contentType: "application/pdf" }]} /> ); @@ -51,6 +53,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[ { id: "3", @@ -69,6 +72,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[ { id: "4", @@ -87,6 +91,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[{ id: "5", fileName: "file.png", fileSize: 1572864, contentType: "image/png" }]} /> ); @@ -98,6 +103,7 @@ describe("Attachment tests", () => { render( <AttachmentList nachrichtEventId="1" + nachrichtId="2" attachments={[ { id: "6", fileName: "file1.png", fileSize: 1572864, contentType: "image/png" }, { id: "7", fileName: "file2.png", fileSize: 1572864, contentType: "image/png" }, @@ -119,7 +125,7 @@ describe("Attachment tests", () => { const onRemove = (fileId: string) => { attachments = attachments.filter((a) => a.id !== fileId); }; - render(<AttachmentList nachrichtEventId="1" attachments={attachments} onRemove={onRemove} />); + render(<AttachmentList nachrichtEventId="1" nachrichtId="2" attachments={attachments} onRemove={onRemove} />); fireEvent.click(screen.getAllByTestId("close").at(0)!!); expect(attachments).toHaveLength(1); @@ -134,7 +140,7 @@ describe("Attachment tests", () => { const onRemove = (fileId: string) => { attachments = attachments.filter((a) => a.id !== fileId); }; - render(<AttachmentList nachrichtEventId="1" attachments={attachments} onRemove={onRemove} />); + render(<AttachmentList nachrichtEventId="1" nachrichtId="2" attachments={attachments} onRemove={onRemove} />); fireEvent.keyDown(screen.getAllByTestId("close").at(0)!!, { key: "Enter", code: 13, charCode: 13 }); expect(attachments).toHaveLength(1); diff --git a/client/src/components/Data Display/AttachmentList/AttachmentList.tsx b/client/src/components/Data Display/AttachmentList/AttachmentList.tsx index efea1d4..6caedde 100644 --- a/client/src/components/Data Display/AttachmentList/AttachmentList.tsx +++ b/client/src/components/Data Display/AttachmentList/AttachmentList.tsx @@ -44,6 +44,8 @@ interface AttachmentListProps { attachments: AttachmentItem[]; /** The id of the nachricht event the nachricht header belongs to */ nachrichtEventId?: string; + /** The id of the nachricht the attachment belongs to */ + nachrichtId?: string; /** If this function is defined the attachments can be removed. */ onRemove?: (fileName: string) => void; /** Accessibility label for the close icon */ @@ -53,6 +55,7 @@ interface AttachmentListProps { interface AttachmentProps extends React.HTMLAttributes<HTMLDivElement> { nachrichtEventId?: string; + nachrichtId?: string; attachment: AttachmentItem; onRemove?: (fileId: string) => void; hasBorder?: boolean; @@ -78,6 +81,7 @@ export function AttachmentList(props: AttachmentListProps) { key={attachment.fileName} closeIconLabel={props.closeIconLabel} nachrichtEventId={props.nachrichtEventId} + nachrichtId={props.nachrichtId} disableDeleteButton={props.disableDeleteButton || attachment.isUploading} /> ))} @@ -97,6 +101,7 @@ function Attachment({ hasBorder, closeIconLabel, nachrichtEventId, + nachrichtId, disableDeleteButton, ...props }: AttachmentProps) { @@ -148,13 +153,13 @@ function Attachment({ return ( <> - {nachrichtEventId ? ( + {nachrichtEventId && nachrichtId ? ( <StyledLink $disabled={isDownloading} onClick={() => { if (!isDownloading) { setIsDownloading(true); - downloadAttachment(nachrichtEventId, attachment.id) + downloadAttachment(nachrichtEventId, nachrichtId, attachment.id) .then((blob) => saveDownloadedAttachmentToFile(blob, attachment.fileName)) .catch(() => {}) // TODO: no error handling is specified .finally(() => setIsDownloading(false)); diff --git a/client/src/routes/detail/DetailPage.tsx b/client/src/routes/detail/DetailPage.tsx index c27753b..a771e98 100644 --- a/client/src/routes/detail/DetailPage.tsx +++ b/client/src/routes/detail/DetailPage.tsx @@ -226,6 +226,7 @@ export function DetailPage() { </GridDiv> <MessageBody nachrichtEventId={selectedRueckfrage.nachricht.nachrichtEventId} + nachrichtId={selectedRueckfrage.id!} closeIconLabel={translate("common.close")} data-cy={`${cyIdsPrefix}clerk-message`} ariaLabel={translate("detailPage.messageBody")} @@ -240,6 +241,7 @@ export function DetailPage() { </Heading> <MessageBody nachrichtEventId={response.nachrichtEventId} + nachrichtId={response.id} closeIconLabel={translate("common.close")} data-cy={`${cyIdsPrefix}user-message-${i}`} ariaLabel={translate("detailPage.messageBody")} -- GitLab