Skip to content

Commit

Permalink
Merge branch 'develop' into useQuery-migrations/file-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 authored Feb 14, 2024
2 parents 41aae98 + 5e0727d commit 4e77a1e
Show file tree
Hide file tree
Showing 30 changed files with 259 additions and 260 deletions.
2 changes: 0 additions & 2 deletions cypress/e2e/assets_spec/asset_homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ describe("Asset Tab", () => {
it("Filter Asset", () => {
assetFilters.filterAssets(
"Dummy Facility 40",
"INTERNAL",
"ACTIVE",
"ONVIF Camera",
"Camera Loc"
);
assetFilters.clickadvancefilter();
assetFilters.clickslideoverbackbutton(); // to verify the back button doesn't clear applied filters
assetFilters.assertFacilityText("Dummy Facility 40");
assetFilters.assertAssetTypeText("INTERNAL");
assetFilters.assertAssetClassText("ONVIF");
assetFilters.assertStatusText("ACTIVE");
assetFilters.assertLocationText("Camera Loc");
Expand Down
4 changes: 0 additions & 4 deletions cypress/e2e/assets_spec/assets_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe("Asset", () => {
assetPage.clickCreateAsset();

assetPage.verifyEmptyAssetNameError();
assetPage.verifyEmptyAssetTypeError();
assetPage.verifyEmptyLocationError();
assetPage.verifyEmptyStatusError();
assetPage.verifyEmptyPhoneError();
Expand All @@ -41,7 +40,6 @@ describe("Asset", () => {
assetPage.createAsset();
assetPage.selectFacility("Dummy Facility 40");
assetPage.selectLocation("Camera Loc");
assetPage.selectAssetType("Internal");
assetPage.selectAssetClass("ONVIF Camera");

const qr_id_1 = uuidv4();
Expand All @@ -68,7 +66,6 @@ describe("Asset", () => {
const qr_id_2 = uuidv4();

assetPage.selectLocation("Camera Loc");
assetPage.selectAssetType("Internal");
assetPage.selectAssetClass("ONVIF Camera");
assetPage.enterAssetDetails(
"New Test Asset 2",
Expand Down Expand Up @@ -141,7 +138,6 @@ describe("Asset", () => {
assetPage.createAsset();
assetPage.selectFacility("Dummy Facility 40");
assetPage.selectLocation("Camera Loc");
assetPage.selectAssetType("Internal");
assetPage.selectAssetClass("HL7 Vitals Monitor");

const qr_id_1 = uuidv4();
Expand Down
7 changes: 0 additions & 7 deletions cypress/e2e/sample_test_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ describe("Sample Filter", () => {
.click();
});

it("Filter by Asset Type", () => {
cy.get("#result").click();
cy.get("li[role='option']")
.contains(/^POSITIVE$/)
.click();
});

it("Filter by sample type", () => {
cy.get("#sample_type").click();
cy.get("li[role='option']")
Expand Down
15 changes: 0 additions & 15 deletions cypress/pageobject/Asset/AssetCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ export class AssetPage {
});
}

selectAssetType(assetType: string) {
cy.get("[data-testid=asset-type-input] button")
.click()
.then(() => {
cy.get("[role='option']").contains(assetType).click();
});
}

selectAssetClass(assetClass: string) {
cy.get("[data-testid=asset-class-input] button")
.click()
Expand Down Expand Up @@ -205,13 +197,6 @@ export class AssetPage {
);
}

verifyEmptyAssetTypeError() {
cy.get("[data-testid=asset-type-input] span").should(
"contain",
"Select an asset type"
);
}

verifyEmptyStatusError() {
cy.get("[data-testid=asset-working-status-input] span").should(
"contain",
Expand Down
9 changes: 0 additions & 9 deletions cypress/pageobject/Asset/AssetFilters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export class AssetFilters {
filterAssets(
facilityName: string,
assetType: string,
assetStatus: string,
assetClass: string,
assetLocation: string
Expand All @@ -13,11 +12,6 @@ export class AssetFilters {
.then(() => {
cy.get("[role='option']").contains(facilityName).click();
});
cy.get("#asset-type")
.click()
.then(() => {
cy.get("[role='option']").contains(assetType).click();
});
cy.get("#asset-status")
.click()
.then(() => {
Expand Down Expand Up @@ -65,9 +59,6 @@ export class AssetFilters {
assertFacilityText(text) {
cy.get("[data-testid=Facility]").should("contain", text);
}
assertAssetTypeText(text) {
cy.get("[data-testid='Asset Type']").should("contain", text);
}
assertAssetClassText(text) {
cy.get("[data-testid='Asset Class']").should("contain", text);
}
Expand Down
16 changes: 0 additions & 16 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ const getDate = (value: any) =>
function AssetFilter(props: any) {
const { filter, onChange, closeFilter, removeFilters } = props;
const [facility, setFacility] = useState<FacilityModel | null>(null);
const [asset_type, setAssetType] = useState<string>(
filter.asset_type ? filter.asset_type : ""
);
const [asset_status, setAssetStatus] = useState<string>(filter.status || "");
const [asset_class, setAssetClass] = useState<string>(
filter.asset_class || ""
Expand Down Expand Up @@ -61,7 +58,6 @@ function AssetFilter(props: any) {
const applyFilter = () => {
const data = {
facility: facilityId,
asset_type: asset_type ?? "",
asset_class: asset_class ?? "",
status: asset_status ?? "",
location: locationId ?? "",
Expand Down Expand Up @@ -125,18 +121,6 @@ function AssetFilter(props: any) {
</div>
)}

<SelectFormField
label="Asset Type"
errorClassName="hidden"
id="asset-type"
name="asset_type"
options={["EXTERNAL", "INTERNAL"]}
optionLabel={(o) => o}
optionValue={(o) => o}
value={asset_type}
onChange={({ value }) => setAssetType(value)}
/>

<SelectFormField
id="asset-status"
name="asset_status"
Expand Down
12 changes: 6 additions & 6 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ const AssetManage = (props: AssetManageProps) => {
{asset?.description}
</div>
<div className="flex flex-wrap gap-2">
{asset?.asset_type === "INTERNAL" ? (
<Chip text="Internal" startIcon="l-building" />
) : (
<Chip text="External" startIcon="l-globe" />
)}
{asset?.status === "ACTIVE" ? (
<Chip text="Active" startIcon="l-check" />
) : (
Expand Down Expand Up @@ -503,7 +498,12 @@ const AssetManage = (props: AssetManageProps) => {
</div>
{asset?.id &&
asset?.asset_class &&
asset?.asset_class != AssetClass.NONE && <Uptime assetId={asset?.id} />}
asset?.asset_class != AssetClass.NONE && (
<Uptime
route={routes.listAssetAvailability}
params={{ external_id: asset.id }}
/>
)}
<div className="mb-4 mt-8 text-xl font-semibold">Service History</div>
<div
className="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg"
Expand Down
11 changes: 3 additions & 8 deletions src/Components/Assets/AssetTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,11 @@ export interface AssetsResponse {
results: AssetData[];
}

export interface AssetUptimeRecord {
id: string;
asset: {
id: string;
name: string;
};
export interface AvailabilityRecord {
linked_id: string;
linked_model: string;
status: string;
timestamp: string;
created_date: string;
modified_date: string;
}

export interface AssetTransaction {
Expand Down
7 changes: 0 additions & 7 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const AssetsList = () => {
const [isScannerActive, setIsScannerActive] = useState(false);
const [totalCount, setTotalCount] = useState(0);
const [facility, setFacility] = useState<FacilityModel>();
const [asset_type, setAssetType] = useState<string>();
const [status, setStatus] = useState<string>();
const [asset_class, setAssetClass] = useState<string>();
const [importAssetModalOpen, setImportAssetModalOpen] = useState(false);
Expand All @@ -60,7 +59,6 @@ const AssetsList = () => {
offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage,
search_text: qParams.search || "",
facility: qParams.facility || "",
asset_type: qParams.asset_type || "",
asset_class: qParams.asset_class || "",
location: qParams.facility ? qParams.location || "" : "",
status: qParams.status || "",
Expand Down Expand Up @@ -91,10 +89,6 @@ const AssetsList = () => {
prefetch: !!qParams.facility,
});

useEffect(() => {
setAssetType(qParams.asset_type);
}, [qParams.asset_type]);

useEffect(() => {
setStatus(qParams.status);
}, [qParams.status]);
Expand Down Expand Up @@ -387,7 +381,6 @@ const AssetsList = () => {
qParams.facility && facilityObject?.name
),
badge("Name/Serial No./QR ID", "search"),
value("Asset Type", "asset_type", asset_type ?? ""),
value("Asset Class", "asset_class", asset_class ?? ""),
value("Status", "status", status?.replace(/_/g, " ") ?? ""),
value(
Expand Down
41 changes: 21 additions & 20 deletions src/Components/Common/Uptime.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Popover } from "@headlessui/react";
import { useEffect, useRef, useState } from "react";
import { AssetStatus, AssetUptimeRecord } from "../Assets/AssetTypes";
import { AssetStatus, AvailabilityRecord } from "../Assets/AssetTypes";
import { classNames } from "../../Utils/utils";
import dayjs from "../../Utils/dayjs";
import useQuery from "../../Utils/request/useQuery.js";
import routes from "../../Redux/api.js";
import { PaginatedResponse, QueryRoute } from "../../Utils/request/types";

const STATUS_COLORS = {
Operational: "bg-green-500",
Expand Down Expand Up @@ -37,7 +37,7 @@ function UptimeInfo({
records,
date,
}: {
records: AssetUptimeRecord[];
records: AvailabilityRecord[];
date: string;
}) {
const incidents =
Expand Down Expand Up @@ -66,7 +66,7 @@ function UptimeInfo({
let endTimestamp;
let ongoing = false;

if (prevIncident?.id) {
if (prevIncident?.linked_id) {
endTimestamp = dayjs(prevIncident.timestamp);
} else if (dayjs(incident.timestamp).isSame(now, "day")) {
endTimestamp = dayjs();
Expand Down Expand Up @@ -141,7 +141,7 @@ function UptimeInfoPopover({
date,
numDays,
}: {
records: AssetUptimeRecord[];
records: AvailabilityRecord[];
day: number;
date: string;
numDays: number;
Expand All @@ -165,12 +165,17 @@ function UptimeInfoPopover({
);
}

export default function Uptime(props: { assetId: string }) {
export default function Uptime(
props: Readonly<{
route: QueryRoute<PaginatedResponse<AvailabilityRecord>>;
params?: Record<string, string | number>;
}>
) {
const [summary, setSummary] = useState<{
[key: number]: AssetUptimeRecord[];
[key: number]: AvailabilityRecord[];
}>([]);
const { data, loading } = useQuery(routes.listAssetAvailability, {
query: { external_id: props.assetId },
const { data, loading } = useQuery(props.route, {
pathParams: props.params,
onResponse: ({ data }) => setUptimeRecord(data?.results.reverse() ?? []),
});
const availabilityData = data?.results ?? [];
Expand All @@ -186,8 +191,8 @@ export default function Uptime(props: { assetId: string }) {
setNumDays(Math.min(newNumDays, 100));
};

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

records.forEach((record) => {
const timestamp = dayjs(record.timestamp).startOf("day");
Expand All @@ -207,10 +212,8 @@ export default function Uptime(props: { assetId: string }) {
recordsByDayBefore[i] = [];
if (statusToCarryOver) {
recordsByDayBefore[i].push({
id: "",
asset: { id: "", name: "" },
created_date: "",
modified_date: "",
linked_id: "",
linked_model: "",
status: statusToCarryOver,
timestamp: dayjs()
.subtract(i, "days")
Expand All @@ -225,10 +228,8 @@ export default function Uptime(props: { assetId: string }) {
).length === 0
) {
recordsByDayBefore[i].unshift({
id: "",
asset: { id: "", name: "" },
created_date: "",
modified_date: "",
linked_id: "",
linked_model: "",
status: statusToCarryOver,
timestamp: dayjs()
.subtract(i, "days")
Expand Down Expand Up @@ -284,7 +285,7 @@ export default function Uptime(props: { assetId: string }) {
const statusColors: (typeof STATUS_COLORS)[keyof typeof STATUS_COLORS][] =
[];
let dayUptimeScore = 0;
const recordsInPeriodCache: { [key: number]: AssetUptimeRecord[] } = {};
const recordsInPeriodCache: { [key: number]: AvailabilityRecord[] } = {};
for (let i = 0; i < 3; i++) {
const start = i * 8;
const end = (i + 1) * 8;
Expand Down
Loading

0 comments on commit 4e77a1e

Please sign in to comment.