Skip to content

Commit

Permalink
Merge branch 'develop' into useQuery-fix-abort-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored Feb 28, 2024
2 parents 2aefb8e + 9a53d70 commit 7cf8067
Show file tree
Hide file tree
Showing 29 changed files with 521 additions and 435 deletions.
32 changes: 32 additions & 0 deletions cypress/e2e/auth_spec/redirect.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { cy, describe, it, beforeEach, Cypress } from "local-cypress";
import LoginPage from "../../pageobject/Login/LoginPage";

describe("redirect", () => {
const loginPage = new LoginPage();

beforeEach(() => {
cy.log("Logging in the user devdistrictadmin");
});

it("Check if login redirects to the right url", () => {
cy.awaitUrl("/resource/board", true);
loginPage.loginManuallyAsDistrictAdmin();
loginPage.ensureLoggedIn();
cy.url().should("include", "/resource/board");
});

it("Check if the redirect param works", () => {
const baseUrl = Cypress.config("baseUrl");
cy.awaitUrl(`login?redirect=${baseUrl}/resource/board`, true);
loginPage.loginManuallyAsDistrictAdmin();
loginPage.ensureLoggedIn();
cy.url().should("include", "/resource/board");
});

it("Check to ensure that redirect is the same origin", () => {
cy.awaitUrl("login?redirect=https://google.com", true);
loginPage.loginManuallyAsDistrictAdmin();
loginPage.ensureLoggedIn();
cy.url().should("include", "/facility");
});
});
14 changes: 14 additions & 0 deletions cypress/pageobject/Login/LoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ class LoginPage {
cy.loginByApi("devdoctor", "Coronasafe@123");
}

loginAsStaff(): void {
cy.loginByApi("staffdev", "Coronasafe@123");
}

loginManuallyAsDistrictAdmin(): void {
cy.get("input[id='username']").type("devdistrictadmin");
cy.get("input[id='password']").type("Coronasafe@123");
cy.get("button").contains("Login").click();
}

login(username: string, password: string): void {
cy.loginByApi(username, password);
}

ensureLoggedIn(): void {
cy.get("p").contains("Sign Out").should("exist");
}
}

export default LoginPage;
10 changes: 5 additions & 5 deletions src/CAREUI/interactive/LegendInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CareIcon from "../icons/CareIcon";
import { classNames } from "../../Utils/utils";
import { RefObject, useRef, useState, useEffect } from "react";

import { useTranslation } from "react-i18next";
type InputProps = {
id?: string;
name: string;
Expand All @@ -19,7 +19,7 @@ type InputProps = {
onKeyDown?: (e: any) => void;
onKeyPress?: (e: any) => void;
disabled?: boolean;
error?: boolean;
error?: string;
className?: string;
outerClassName?: string;
size?: "small" | "medium" | "large";
Expand All @@ -30,6 +30,7 @@ export default function LegendInput(props: InputProps) {
/**
* Useful for small input forms. Should only be used in special cases.
*/
const { t } = useTranslation();
const [showPassword, setShowPassword] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
const ref = props.ref || inputRef;
Expand Down Expand Up @@ -66,7 +67,6 @@ export default function LegendInput(props: InputProps) {
useEffect(() => {
ref.current && testAutoFill(ref.current);
}, [ref.current]);

return (
<div className={props.outerClassName}>
{props.label && (
Expand Down Expand Up @@ -149,8 +149,8 @@ export default function LegendInput(props: InputProps) {
</button>
)}
</div>
{props.error && (
<div className="mt-1 text-xs text-red-500">{props.error}</div>
{!!props.error && (
<div className="mt-1 text-xs text-red-500">{t(props.error)}</div>
)}
</div>
);
Expand Down
10 changes: 0 additions & 10 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,6 @@ export const NOTIFICATION_EVENTS: NotificationEvent[] = [
text: "Patient Updated",
icon: "l-edit",
},
{
id: "PATIENT_DELETED",
text: "Patient Deleted",
icon: "l-user-minus",
},
{
id: "PATIENT_CONSULTATION_CREATED",
text: "Patient Consultation Created",
Expand All @@ -580,11 +575,6 @@ export const NOTIFICATION_EVENTS: NotificationEvent[] = [
text: "Patient Consultation Updated",
icon: "l-heart-medical",
},
{
id: "PATIENT_CONSULTATION_DELETED",
text: "Patient Consultation Deleted",
icon: "l-heartbeat",
},
{
id: "INVESTIGATION_SESSION_CREATED",
text: "Investigation Session Created",
Expand Down
4 changes: 4 additions & 0 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ const AssetManage = (props: AssetManageProps) => {
<Uptime
route={routes.listAssetAvailability}
params={{ external_id: asset.id }}
header={
<div className="text-xl font-semibold">Availability History</div>
}
parentClassNames="mt-8 flex w-full flex-col bg-white p-4 shadow-sm sm:rounded-lg"
/>
)}
<div className="mb-4 mt-8 text-xl font-semibold">Service History</div>
Expand Down
9 changes: 8 additions & 1 deletion src/Components/Assets/AssetType/HL7Monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ const HL7Monitor = (props: HL7MonitorProps) => {
)}

{assetType === "HL7MONITOR" && (
<HL7PatientVitalsMonitor key={socketUrl} socketUrl={socketUrl} />
<HL7PatientVitalsMonitor
key={socketUrl}
socketUrl={socketUrl}
hideHeader={true}
hideFooter={true}
/>
)}
{assetType === "VENTILATOR" && (
<VentilatorPatientVitalsMonitor
key={socketUrl}
socketUrl={socketUrl}
hideHeader={true}
hideFooter={true}
/>
)}
</div>
Expand Down
10 changes: 6 additions & 4 deletions src/Components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ export const Login = (props: { forgot?: boolean }) => {
) {
if (!form[key].match(/\w/)) {
hasError = true;
err[key] = t("field_required");
err[key] = "field_required";
}
}
if (!form[key]) {
hasError = true;
err[key] = t("field_required");
err[key] = "field_required";
}
});
if (hasError) {
setErrors(err);
return false;
}

return form;
};

Expand All @@ -92,6 +93,7 @@ export const Login = (props: { forgot?: boolean }) => {

const handleSubmit = async (e: any) => {
e.preventDefault();

setLoading(true);
FiltersCache.invaldiateAll();
const validated = validateData();
Expand All @@ -111,12 +113,12 @@ export const Login = (props: { forgot?: boolean }) => {
if (typeof form.username === "string") {
if (!form.username.match(/\w/)) {
hasError = true;
err.username = t("field_required");
err.username = "field_required";
}
}
if (!form.username) {
hasError = true;
err.username = t("field_required");
err.username = "field_required";
}

if (hasError) {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Common/LanguageSelectorLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { LANGUAGE_NAMES } from "../../Locale/config";
import { classNames } from "../../Utils/utils";

export const LanguageSelectorLogin = () => {
const { i18n } = useTranslation();

const { i18n, t } = useTranslation();
useEffect(() => {
document.documentElement.setAttribute("lang", i18n.language);
}, [i18n]);
Expand All @@ -20,7 +19,7 @@ export const LanguageSelectorLogin = () => {

return (
<div className="mt-8 flex flex-col items-center text-sm text-gray-800">
Available in:
{t("available_in")}
<br />
<div className="inline-flex flex-wrap gap-3">
{Object.keys(LANGUAGE_NAMES).map((e: string) => (
Expand Down
29 changes: 16 additions & 13 deletions src/Components/Common/Uptime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export default function Uptime(
props: Readonly<{
route: QueryRoute<PaginatedResponse<AvailabilityRecord>>;
params?: Record<string, string | number>;
header?: React.ReactNode;
parentClassNames?: string;
centerInfoPanel?: boolean;
}>
) {
const [summary, setSummary] = useState<{
Expand All @@ -191,6 +194,8 @@ export default function Uptime(
setNumDays(Math.min(newNumDays, 100));
};

const centerInfoPanel = props.centerInfoPanel ?? false;

const setUptimeRecord = (records: AvailabilityRecord[]): void => {
const recordsByDayBefore: { [key: number]: AvailabilityRecord[] } = {};

Expand Down Expand Up @@ -361,10 +366,10 @@ export default function Uptime(
);
} else if (summary) {
return (
<div className="mt-8 flex w-full flex-col bg-white p-4 shadow-sm sm:rounded-lg">
<div className="mx-2 w-full">
<div className={props.parentClassNames}>
<div className="w-full">
<div className="grid grid-cols-1">
<div className="text-xl font-semibold">Availability History</div>
{props.header}
<div>
<div className="mt-2 overflow-x-clip px-5">
<div className="mb-1 mt-2 flex justify-center text-xs text-gray-700 opacity-70">
Expand Down Expand Up @@ -407,15 +412,13 @@ export default function Uptime(
}`}
></div>
</span>
{hoveredDay === index && (
<>
<UptimeInfoPopover
records={summary[index]}
day={index}
date={formatDateBeforeDays[index]}
numDays={numDays}
/>
</>
{hoveredDay === index && !centerInfoPanel && (
<UptimeInfoPopover
records={summary[index]}
day={index}
date={formatDateBeforeDays[index]}
numDays={numDays}
/>
)}
</>
);
Expand All @@ -432,7 +435,7 @@ export default function Uptime(
</div>
</div>
{hoveredDay !== -1 && (
<div className="relative sm:hidden">
<div className={`relative ${!centerInfoPanel && "sm:hidden"}`}>
<UptimeInfo
records={summary[hoveredDay]}
date={formatDateBeforeDays[hoveredDay]}
Expand Down
3 changes: 3 additions & 0 deletions src/Components/ExternalResult/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export interface IExternalResult {
sample_collection_date: string;
patient_category: string;
srf_id: string;
permanent_address: string;
test_id: string;
village: string;
district_object: {
id: number;
name: string;
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Facility/CentralNursingStation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export default function CentralNursingStation({ facilityId }: Props) {
?.start_date
}
key={`${props.patientAssetBed?.bed.id}-${hash}`}
{...props}
patientAssetBed={props.patientAssetBed}
socketUrl={props.socketUrl || ""}
config={config}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
meta: monitorBedData?.asset_object?.meta,
}}
socketUrl={hl7SocketUrl}
hideHeader={true}
/>
</div>
<div className="min-h-[400px] flex-1">
Expand All @@ -122,6 +123,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
meta: ventilatorBedData?.asset_object?.meta,
}}
socketUrl={ventilatorSocketUrl}
hideHeader={true}
/>
</div>
</div>
Expand Down Expand Up @@ -157,6 +159,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
}}
socketUrl={hl7SocketUrl}
config={vitals.config}
hideHeader={true}
/>
</div>
)}
Expand All @@ -173,6 +176,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
}}
socketUrl={ventilatorSocketUrl}
config={vitals.config}
hideHeader={true}
/>
</div>
)}
Expand Down
19 changes: 18 additions & 1 deletion src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import request from "../../Utils/request/request";
import * as Notification from "../../Utils/Notifications.js";
import ConfirmDialog from "../Common/ConfirmDialog";
import DialogModal from "../Common/Dialog";
import Uptime from "../Common/Uptime";

const Loading = lazy(() => import("../Common/Loading"));

Expand All @@ -19,6 +20,7 @@ interface Props {
}

interface LocationProps extends LocationModel {
facilityId: string;
setShowDeletePopup: (e: { open: boolean; name: string; id: string }) => void;
}

Expand Down Expand Up @@ -109,7 +111,11 @@ export default function LocationManagement({ facilityId }: Props) {
</PaginatedList.WhenLoading>
<PaginatedList.Items<LocationModel> className="my-8 grid gap-3 @4xl:grid-cols-2 @6xl:grid-cols-3 @[100rem]:grid-cols-4 lg:mx-8">
{(item) => (
<Location setShowDeletePopup={setShowDeletePopup} {...item} />
<Location
setShowDeletePopup={setShowDeletePopup}
facilityId={facilityId}
{...item}
/>
)}
</PaginatedList.Items>
</div>
Expand Down Expand Up @@ -208,6 +214,7 @@ const Location = ({
modified_date,
id,
setShowDeletePopup,
facilityId,
}: LocationProps) => (
<div className="flex h-full w-full flex-col rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400">
<div className="flex-1">
Expand Down Expand Up @@ -241,6 +248,16 @@ const Location = ({
>
{middleware_address || "-"}
</p>
<Uptime
route={routes.listFacilityAssetLocationAvailability}
params={{ external_id: id, facility_external_id: facilityId }}
header={
<p className="mt-3 text-sm font-semibold text-gray-700">
Middleware Uptime
</p>
}
centerInfoPanel
/>
</div>

<ButtonV2
Expand Down
Loading

0 comments on commit 7cf8067

Please sign in to comment.