Skip to content

Commit

Permalink
Refactored FileUpload component (#8329)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker authored Aug 23, 2024
1 parent 10a991e commit 0daadf2
Show file tree
Hide file tree
Showing 37 changed files with 1,498 additions and 2,377 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/patient_spec/patient_fileupload.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function runTests(testDescription, visitPatientFileUploadSection) {
cy.verifyNotification("File Uploaded Successfully");
patientFileUpload.verifyUploadFilePresence(cypressAudioName);
// Verify the download of the audio file
cy.get("button").contains("DOWNLOAD").click();
cy.get("button").contains("Download").click();
cy.verifyNotification("Downloading file...");
});

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/patient_spec/patient_logupdate.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => {
cy.verifyNotification("Brief Update log created successfully");
cy.closeNotification();
// edit the card and verify the data.
cy.contains("Daily Rounds").click();
cy.contains("button", "Daily Rounds").click();
patientLogupdate.clickLogupdateCard("#dailyround-entry", patientCategory);
cy.verifyContentPresence("#consultation-preview", [
patientCategory,
Expand All @@ -110,7 +110,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => {
patientLogupdate.typeDiastolic(patientModifiedDiastolic);
cy.submitButton("Continue");
cy.verifyNotification("Brief Update log updated successfully");
cy.contains("Daily Rounds").click();
cy.contains("button", "Daily Rounds").click();
patientLogupdate.clickLogupdateCard("#dailyround-entry", patientCategory);
cy.verifyContentPresence("#consultation-preview", [
patientModifiedDiastolic,
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/shifting_spec/shifting.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ describe("Shifting Page", () => {

it("switch between active/archived", () => {
cy.intercept(/\/api\/v1\/shift/).as("shifting");
cy.contains("Archived").click().wait("@shifting");
cy.contains("Active").should("have.class", "text-primary-500");
cy.contains("Archived").should("have.class", "text-white");
cy.contains("button", "Archived").click().wait("@shifting");
cy.contains("button", "Active").should("have.class", "text-primary-500");
cy.contains("button", "Archived").should("have.class", "text-white");
cy.intercept(/\/api\/v1\/shift/).as("shifting");
cy.contains("Active").click().wait("@shifting");
cy.contains("Active").should("have.class", "text-white");
cy.contains("Archived").should("have.class", "text-primary-500");
cy.contains("button", "Active").click().wait("@shifting");
cy.contains("button", "Active").should("have.class", "text-white");
cy.contains("button", "Archived").should("have.class", "text-primary-500");
});

afterEach(() => {
Expand Down
37 changes: 20 additions & 17 deletions cypress/pageobject/Patient/PatientFileupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ export class PatientFileUpload {
}

typeAudioName(name: string) {
cy.get("#consultation_audio_file").clear();
cy.get("#consultation_audio_file").click().type(name);
cy.get("#upload-file-name").clear();
cy.get("#upload-file-name").click().type(name);
}

clickFileTab() {
cy.verifyAndClickElement("#consultation_tab_nav", "Files");
}

typeFileName(name: string) {
cy.get("#consultation_file").clear();
cy.get("#consultation_file").click().type(name);
cy.get("#upload-file-name").clear();
cy.get("#upload-file-name").click().type(name);
}

recordAudio() {
cy.get("#record-audio").click();
cy.wait(5000);
cy.get("#stop-recording").click();
cy.wait(1000);
cy.get("#save-recording").click();
}

clickUploadAudioFile() {
cy.intercept("POST", "**/api/v1/files/").as("uploadAudioFile");
cy.verifyAndClickElement("#upload_audio_file", "Save");
cy.verifyAndClickElement("#upload_file_button", "Upload");
cy.wait("@uploadAudioFile").its("response.statusCode").should("eq", 201);
}

Expand All @@ -52,8 +54,8 @@ export class PatientFileUpload {
}

archiveFile() {
cy.get("button").contains("ARCHIVE").click().scrollIntoView();
cy.get("#editFileName").clear().type("Cypress File Archive");
cy.get("#file-div button").contains("Archive").click().scrollIntoView();
cy.get("#archive-file-reason").clear().type("Cypress File Archive");
}

clickSaveArchiveFile() {
Expand All @@ -63,27 +65,28 @@ export class PatientFileUpload {
}

verifyArchiveFile(fileName: string) {
cy.get("#archived-files").click();
cy.get("button").contains("MORE DETAILS").click().scrollIntoView();
cy.get("#archive-file-name").should("contain.text", fileName);
cy.get("#archive-file-reason").then(($reason) => {
expect($reason.text().split(":")[1]).to.contain("Cypress File Archive");
});
cy.get("button").contains("Archived Files").click();
cy.get("button").contains("More Info").click().scrollIntoView();
cy.get('[data-archive-info="File Name"]').should("contain.text", fileName);
cy.get('[data-archive-info="Archive Reason"]').should(
"contain.text",
"Cypress File Archive",
);
}

verifyFileRenameOption(status: boolean) {
cy.get("#file-div").then(($fileDiv) => {
if (status) {
expect($fileDiv.text()).to.contain("RENAME");
expect($fileDiv.text()).to.contain("Rename");
} else {
expect($fileDiv.text()).to.not.contain("RENAME");
expect($fileDiv.text()).to.not.contain("Rename");
}
});
}

renameFile(newFileName: string) {
cy.get("button").contains("RENAME").click().scrollIntoView();
cy.get("#editFileName").clear().type(newFileName);
cy.get("button").contains("Rename").click().scrollIntoView();
cy.get("#edit-file-name").clear().type(newFileName);
}

clickSaveFileName() {
Expand Down
12 changes: 6 additions & 6 deletions cypress/pageobject/Resource/ResourcePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ class ResourcePage {
}

clickCompletedResources() {
cy.contains("Completed").click();
cy.contains("button", "Completed").click();
}

verifyCompletedResources() {
cy.wait("@resource").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.contains("Active").should("have.class", "text-primary-500");
cy.contains("Completed").should("have.class", "text-white");
cy.contains("button", "Active").should("have.class", "text-primary-500");
cy.contains("button", "Completed").should("have.class", "text-white");
}

clickActiveResources() {
cy.contains("Active").click();
cy.contains("button", "Active").click();
}

verifyActiveResources() {
cy.wait("@resource").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.contains("Active").should("have.class", "text-white");
cy.contains("Completed").should("have.class", "text-primary-500");
cy.contains("button", "Active").should("have.class", "text-white");
cy.contains("button", "Completed").should("have.class", "text-primary-500");
}

clickListViewButton() {
Expand Down
57 changes: 57 additions & 0 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1660,3 +1660,60 @@ export const PressureSoreTissueTypeOptions = [
"Slough",
"Necrotic",
] as const;

export const FILE_EXTENSIONS = {
IMAGE: ["jpeg", "jpg", "png", "gif", "svg", "bmp", "webp", "jfif"],
AUDIO: ["mp3", "wav"],
VIDEO: [
"webm",
"mpg",
"mp2",
"mpeg",
"mpe",
"mpv",
"ogg",
"mp4",
"m4v",
"avi",
"wmv",
"mov",
"qt",
"flv",
"swf",
],
PRESENTATION: ["pptx"],
DOCUMENT: ["pdf", "docx"],
} as const;

export const PREVIEWABLE_FILE_EXTENSIONS = [
"html",
"htm",
"pdf",
"mp4",
"webm",
"jpg",
"jpeg",
"png",
"gif",
"webp",
] as const;

export const HEADER_CONTENT_TYPES = {
pdf: "application/pdf",
txt: "text/plain",
jpeg: "image/jpeg",
jpg: "image/jpeg",
doc: "application/msword",
xls: "application/vnd.ms-excel",
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
epub: "application/epub+zip",
gif: "image/gif",
html: "text/html",
htm: "text/html",
mp4: "video/mp4",
png: "image/png",
ppt: "application/vnd.ms-powerpoint",
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
svg: "image/svg+xml",
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
} as const;
2 changes: 1 addition & 1 deletion src/Components/Common/FilePreviewDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CircularProgress from "./components/CircularProgress";
import { useTranslation } from "react-i18next";
import { StateInterface } from "../Patient/FileUpload";
import { StateInterface } from "../Files/FileUpload";
import { Dispatch, ReactNode, SetStateAction, useState } from "react";
import CareIcon, { IconName } from "../../CAREUI/icons/CareIcon";
import ButtonV2, { Cancel } from "./components/ButtonV2";
Expand Down
46 changes: 0 additions & 46 deletions src/Components/Common/components/SwitchTabs.tsx

This file was deleted.

70 changes: 70 additions & 0 deletions src/Components/Common/components/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useEffect, useRef, type ReactNode } from "react";
import { classNames } from "../../../Utils/utils";
import useWindowDimensions from "../../../Common/hooks/useWindowDimensions";

export default function Tabs(props: {
className?: string;
currentTab: string | number;
onTabChange: (value: string | number) => void;
tabs: { text: ReactNode; value: string | number }[];
}) {
const { className, currentTab, onTabChange, tabs } = props;
const ref = useRef<HTMLDivElement>(null);
const tabSwitcherRef = useRef<HTMLDivElement>(null);

const dimensions = useWindowDimensions();

useEffect(() => {
const currentTabIndex = tabs.findIndex((t) => t.value === currentTab);
if (
typeof currentTabIndex != "number" ||
!ref.current ||
!tabSwitcherRef.current
)
return;
const tabButton = ref.current.querySelectorAll("button")[currentTabIndex];
if (!tabButton) return;
tabSwitcherRef.current.style.width = tabButton.clientWidth + "px";
tabSwitcherRef.current.style.left =
tabButton.getBoundingClientRect().left -
ref.current.getBoundingClientRect().left +
ref.current.scrollLeft +
"px";
}, [currentTab, tabSwitcherRef.current, ref.current, dimensions]);

return (
<div
className={classNames(
"relative inline-flex w-full items-center justify-between overflow-auto rounded-md bg-primary-500/10 p-2 md:w-auto",
className,
)}
ref={ref}
>
<div
className="absolute inset-y-2 z-10 rounded bg-primary-500 transition-all"
ref={tabSwitcherRef}
style={{ left: 0 }}
/>
{/* There has to be a better way of handling this... */}
{tabs.map((tab, i) => (
<div
key={i}
className={`flex-1 whitespace-nowrap px-6 py-2 text-sm font-semibold text-transparent transition-all`}
>
{tab.text}
</div>
))}
<div className="absolute inset-2 z-10 flex items-center justify-between">
{tabs.map((tab, i) => (
<button
key={i}
onClick={() => onTabChange(tab.value)}
className={`${currentTab === tab.value ? "text-white" : "text-primary-500 hover:text-primary-600"} flex-1 whitespace-nowrap px-6 py-2 text-sm font-semibold transition-all`}
>
{tab.text}
</button>
))}
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { ConsultationTabProps } from "./index";
import { FileUpload } from "../../Patient/FileUpload";
import { FileUpload } from "../../Files/FileUpload";

export const ConsultationFilesTab = (props: ConsultationTabProps) => {
return (
<div>
<div className="p-4">
<FileUpload
facilityId={props.facilityId}
patientId={props.patientId}
consultationId={props.consultationId}
type="CONSULTATION"
hideBack={true}
audio={true}
unspecified={true}
allowAudio
/>
</div>
);
Expand Down
Loading

0 comments on commit 0daadf2

Please sign in to comment.