From ee5d5e1f23d2ff70eae65dc2fac549c6a9dadfad Mon Sep 17 00:00:00 2001 From: Pranshu1902 Date: Sat, 30 Dec 2023 17:09:47 +0530 Subject: [PATCH 1/4] Show Asset Downtime on assets lists page --- src/Components/Assets/AssetsList.tsx | 32 +++++++++++++++++++++++++++- src/Redux/api.tsx | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index 3fc9c9f9f14..f0443d14e76 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -1,7 +1,7 @@ import QrReader from "react-qr-reader"; import * as Notification from "../../Utils/Notifications.js"; import { listAssets } from "../../Redux/actions"; -import { assetClassProps, AssetData } from "./AssetTypes"; +import { assetClassProps, AssetData, AssetUptimeRecord } from "./AssetTypes"; import { useState, useEffect, lazy } from "react"; import { Link, navigate } from "raviger"; import AssetFilter from "./AssetFilter"; @@ -50,6 +50,9 @@ const AssetsList = () => { const [importAssetModalOpen, setImportAssetModalOpen] = useState(false); const assetsExist = assets.length > 0 && Object.keys(assets[0]).length > 0; const [showFacilityDialog, setShowFacilityDialog] = useState(false); + const [availabilityData, setAvailabilityData] = useState( + [] + ); const [selectedFacility, setSelectedFacility] = useState({ name: "", }); @@ -128,6 +131,20 @@ const AssetsList = () => { } }; + useEffect(() => { + const fetchAvailabilityData = async () => { + const assetAvailabilityData = await request( + routes.listAssetAvailability, + {} + ); + if (assetAvailabilityData?.data) { + setAvailabilityData(assetAvailabilityData.data.results); + } + }; + + fetchAvailabilityData(); + }, []); + const checkValidAssetId = async (assetId: string) => { const { data: assetData } = await request(routes.getAsset, { pathParams: { id: assetId }, @@ -239,6 +256,19 @@ const AssetsList = () => { )} {warrantyAmcValidityChip(asset.warranty_amc_end_of_validity)} + {availabilityData && + availabilityData.length > 0 && + availabilityData.map((data: any) => { + if (data.asset.id === asset.id) { + return ( + + ); + } + })} diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 2b8d4f8f51b..4fe21379e91 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -27,6 +27,7 @@ import { AssetServiceUpdate, AssetTransaction, AssetUpdate, + AssetUptimeRecord, } from "../Components/Assets/AssetTypes"; import { CapacityModal, @@ -1225,6 +1226,7 @@ const routes = { listAssetAvailability: { path: "/api/v1/asset_availability/", method: "GET", + TRes: Type>(), }, getAssetAvailability: { path: "/api/v1/asset_availability/{id}", From b216883bc3b19d0dfb9852c78e30b1da2d325f19 Mon Sep 17 00:00:00 2001 From: Pranshu1902 Date: Sun, 7 Jan 2024 16:04:19 +0530 Subject: [PATCH 2/4] fetch downtime from asset api --- src/Components/Assets/AssetTypes.tsx | 1 + src/Components/Assets/AssetsList.tsx | 35 ++++------------------------ src/Redux/api.tsx | 2 -- 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/Components/Assets/AssetTypes.tsx b/src/Components/Assets/AssetTypes.tsx index 436c9370dd8..4279a593319 100644 --- a/src/Components/Assets/AssetTypes.tsx +++ b/src/Components/Assets/AssetTypes.tsx @@ -99,6 +99,7 @@ export interface AssetData { manufacturer: string; warranty_amc_end_of_validity: string; resolved_middleware?: ResolvedMiddleware; + down: boolean; last_service: AssetService; meta?: { [key: string]: any; diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index f0443d14e76..c5817e080ed 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -1,7 +1,7 @@ import QrReader from "react-qr-reader"; import * as Notification from "../../Utils/Notifications.js"; import { listAssets } from "../../Redux/actions"; -import { assetClassProps, AssetData, AssetUptimeRecord } from "./AssetTypes"; +import { assetClassProps, AssetData } from "./AssetTypes"; import { useState, useEffect, lazy } from "react"; import { Link, navigate } from "raviger"; import AssetFilter from "./AssetFilter"; @@ -50,9 +50,6 @@ const AssetsList = () => { const [importAssetModalOpen, setImportAssetModalOpen] = useState(false); const assetsExist = assets.length > 0 && Object.keys(assets[0]).length > 0; const [showFacilityDialog, setShowFacilityDialog] = useState(false); - const [availabilityData, setAvailabilityData] = useState( - [] - ); const [selectedFacility, setSelectedFacility] = useState({ name: "", }); @@ -131,20 +128,6 @@ const AssetsList = () => { } }; - useEffect(() => { - const fetchAvailabilityData = async () => { - const assetAvailabilityData = await request( - routes.listAssetAvailability, - {} - ); - if (assetAvailabilityData?.data) { - setAvailabilityData(assetAvailabilityData.data.results); - } - }; - - fetchAvailabilityData(); - }, []); - const checkValidAssetId = async (assetId: string) => { const { data: assetData } = await request(routes.getAsset, { pathParams: { id: assetId }, @@ -256,19 +239,9 @@ const AssetsList = () => { )} {warrantyAmcValidityChip(asset.warranty_amc_end_of_validity)} - {availabilityData && - availabilityData.length > 0 && - availabilityData.map((data: any) => { - if (data.asset.id === asset.id) { - return ( - - ); - } - })} + {asset?.down && ( + + )}{" "} diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 4fe21379e91..2b8d4f8f51b 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -27,7 +27,6 @@ import { AssetServiceUpdate, AssetTransaction, AssetUpdate, - AssetUptimeRecord, } from "../Components/Assets/AssetTypes"; import { CapacityModal, @@ -1226,7 +1225,6 @@ const routes = { listAssetAvailability: { path: "/api/v1/asset_availability/", method: "GET", - TRes: Type>(), }, getAssetAvailability: { path: "/api/v1/asset_availability/{id}", From e67cece68e2bf8fbc2ca4a47340ae3cda626f5a5 Mon Sep 17 00:00:00 2001 From: Pranshu1902 Date: Mon, 8 Jan 2024 00:07:27 +0530 Subject: [PATCH 3/4] update icon --- src/Components/Assets/AssetsList.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index c5817e080ed..509a7c5007b 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -240,7 +240,11 @@ const AssetsList = () => { )} {warrantyAmcValidityChip(asset.warranty_amc_end_of_validity)} {asset?.down && ( - + )}{" "} From 1e21e1ac6c387deabe1e7e40fb11b3a64d7ea8cb Mon Sep 17 00:00:00 2001 From: Pranshu1902 Date: Sat, 20 Jan 2024 11:32:57 +0530 Subject: [PATCH 4/4] update to new api variable --- src/Components/Assets/AssetTypes.tsx | 2 +- src/Components/Assets/AssetsList.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Components/Assets/AssetTypes.tsx b/src/Components/Assets/AssetTypes.tsx index 4279a593319..ffabae679df 100644 --- a/src/Components/Assets/AssetTypes.tsx +++ b/src/Components/Assets/AssetTypes.tsx @@ -99,7 +99,7 @@ export interface AssetData { manufacturer: string; warranty_amc_end_of_validity: string; resolved_middleware?: ResolvedMiddleware; - down: boolean; + latest_status: string; last_service: AssetService; meta?: { [key: string]: any; diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index 509a7c5007b..e00dfd239e6 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -239,11 +239,11 @@ const AssetsList = () => { )} {warrantyAmcValidityChip(asset.warranty_amc_end_of_validity)} - {asset?.down && ( + {asset?.latest_status === "Down" && ( )}{" "}