From 2cc66f08e2f49d9dadf21fd038e724e9bfadbd5d Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:51:53 +0530 Subject: [PATCH] Update Uptime endpoint for AssetUptime (#7210) * Track uptime for Locations * Refactor Uptime component to accept route and params * Remove unused import in api.tsx --- src/Components/Assets/AssetManage.tsx | 7 ++++- src/Components/Assets/AssetTypes.tsx | 11 ++----- src/Components/Common/Uptime.tsx | 41 ++++++++++++++------------- src/Redux/api.tsx | 25 +++++++--------- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Components/Assets/AssetManage.tsx b/src/Components/Assets/AssetManage.tsx index 0da432eccb6..77bb88da3a8 100644 --- a/src/Components/Assets/AssetManage.tsx +++ b/src/Components/Assets/AssetManage.tsx @@ -498,7 +498,12 @@ const AssetManage = (props: AssetManageProps) => { {asset?.id && asset?.asset_class && - asset?.asset_class != AssetClass.NONE && } + asset?.asset_class != AssetClass.NONE && ( + + )}
Service History
>; + params?: Record; + }> +) { 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 ?? []; @@ -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"); @@ -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") @@ -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") @@ -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; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index eed17ad3b4b..40c842adc07 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -27,7 +27,7 @@ import { AssetService, AssetServiceUpdate, AssetTransaction, - AssetUptimeRecord, + AvailabilityRecord, PatientAssetBed, } from "../Components/Assets/AssetTypes"; import { @@ -371,6 +371,11 @@ const routes = { path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/", method: "PATCH", }, + getFacilityAssetLocationAvailability: { + path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/availability/", + method: "GET", + TRes: Type>(), + }, // Asset bed listAssetBeds: { @@ -1116,6 +1121,11 @@ const routes = { TRes: Type(), TBody: Type>(), }, + listAssetAvailability: { + path: "/api/v1/asset/{external_id}/availability/", + method: "GET", + TRes: Type>(), + }, // Asset transaction endpoints @@ -1290,19 +1300,6 @@ const routes = { }, }, - // Asset Availability endpoints - - listAssetAvailability: { - path: "/api/v1/asset_availability/", - method: "GET", - TRes: Type>(), - }, - getAssetAvailability: { - path: "/api/v1/asset_availability/{id}", - method: "GET", - TRes: Type(), - }, - // Prescription endpoints listPrescriptions: {