From 2d9669e75f4f5a04b803d64bfaae2e1d1fb2a0d9 Mon Sep 17 00:00:00 2001 From: Jacob John Jeevan <40040905+Jacobjeevan@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:22:44 +0530 Subject: [PATCH] Camera Preset Not Resetting on Re-selection Bug (#9186) --- public/locale/en.json | 2 + .../ConsultationFeedTab.tsx | 39 ++++++------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index cd921bef06a..7e92d927a64 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -945,6 +945,7 @@ "next_sessions": "Next Sessions", "no": "No", "no_attachments_found": "This communication has no attachments.", + "no_bed_asset_linked_allocated": "No bed/asset linked allocated", "no_bed_types_found": "No Bed Types found", "no_beds_available": "No beds available", "no_changes": "No changes", @@ -1364,6 +1365,7 @@ "update_facility_middleware_success": "Facility middleware updated successfully", "update_log": "Update Log", "update_patient_details": "Update Patient Details", + "update_preset": "Update Preset", "update_preset_position_to_current": "Update preset's position to camera's current position", "update_record": "Update Record", "update_record_for_asset": "Update record for asset", diff --git a/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx b/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx index 21c6f304cb5..bc518feb02f 100644 --- a/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx +++ b/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx @@ -34,6 +34,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { const bed = props.consultationData.current_bed?.bed_object; const feedStateSessionKey = `encounterFeedState[${props.consultationId}]`; const [preset, setPreset] = useState(); + const [selectedPreset, setSelectedPreset] = useState(); const [showPresetSaveConfirmation, setShowPresetSaveConfirmation] = useState(false); const [isUpdatingPreset, setIsUpdatingPreset] = useState(false); @@ -78,28 +79,14 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { return presets.find((obj) => obj.id === lastState.value); } if (lastState.type === "position") { - const assetBedObj = presets.find( - (p) => p.asset_bed.id === lastState.assetBed, - )?.asset_bed; - - if (!assetBedObj) { - return; - } - - return { - ...presets[0], - id: "", - asset_bed: assetBedObj, - position: lastState.value, - } satisfies CameraPreset; + return; } } })() ?? presets[0]; - console.log({ preset, presets }); - if (preset) { setPreset(preset); + setSelectedPreset(preset); } }, }); @@ -126,6 +113,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { await presetsQuery.refetch(); setPreset(updated); + setSelectedPreset(updated); setHasMoved(false); setIsUpdatingPreset(false); setShowPresetSaveConfirmation(false); @@ -154,7 +142,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { } if (!bed || !asset) { - return No bed/asset linked allocated; + return {t("no_bed_asset_linked_allocated")}; } const cannotSaveToPreset = !hasMoved || !preset?.id; @@ -162,8 +150,8 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { return ( setShowPresetSaveConfirmation(false)} @@ -180,11 +168,9 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { { - if (!preset) { - return; - } + setSelectedPreset(undefined); setHasMoved(true); setTimeout(async () => { const { data } = await operate({ type: "get_status" }); @@ -193,7 +179,6 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { feedStateSessionKey, JSON.stringify({ type: "position", - assetBed: preset.asset_bed.id, value: (data as GetStatusResponse).result.position, } satisfies LastAccessedPosition), ); @@ -222,16 +207,17 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { obj.name} - value={preset} + value={selectedPreset} onChange={(value) => { triggerGoal("Camera Preset Clicked", { - presetName: preset?.name, + presetName: selectedPreset?.name, consultationId: props.consultationId, userId: authUser.id, result: "success", }); setHasMoved(false); setPreset(value); + setSelectedPreset(value); }} /> {isUpdatingPreset ? ( @@ -277,7 +263,6 @@ type LastAccessedPreset = { type LastAccessedPosition = { type: "position"; - assetBed: string; value: PTZPayload; };