Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera Preset Not Resetting on Re-selection Bug #9186

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,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",
Expand Down Expand Up @@ -1283,6 +1284,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CameraPreset>();
const [selectedPreset, setSelectedPreset] = useState<CameraPreset>();
Comment on lines 36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now confusing... so what does preset state store?

Copy link
Contributor Author

@Jacobjeevan Jacobjeevan Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now confusing... so what does preset state store?

selectedPreset specifically stores user's explicit selection, whereas preset is tied to the asset object.

const asset = preset?.asset_bed.asset_object;

const [showPresetSaveConfirmation, setShowPresetSaveConfirmation] =
useState(false);
const [isUpdatingPreset, setIsUpdatingPreset] = useState(false);
Expand Down Expand Up @@ -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);
}
},
});
Expand All @@ -126,6 +113,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
await presetsQuery.refetch();

setPreset(updated);
setSelectedPreset(updated);
setHasMoved(false);
setIsUpdatingPreset(false);
setShowPresetSaveConfirmation(false);
Expand Down Expand Up @@ -154,16 +142,16 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
}

if (!bed || !asset) {
return <span>No bed/asset linked allocated</span>;
return <span>{t("no_bed_asset_linked_allocated")}</span>;
}

const cannotSaveToPreset = !hasMoved || !preset?.id;

return (
<StillWatching>
<ConfirmDialog
title="Update Preset"
description="Are you sure you want to update this preset to the current location?"
title={t("update_preset")}
description={`Are you sure you want to update ${preset?.name} to the current location?`}
action="Confirm"
show={showPresetSaveConfirmation}
onClose={() => setShowPresetSaveConfirmation(false)}
Expand All @@ -180,11 +168,9 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
<CameraFeed
key={key}
asset={asset}
preset={preset?.position}
preset={selectedPreset?.position}
onMove={() => {
if (!preset) {
return;
}
setSelectedPreset(undefined);
setHasMoved(true);
setTimeout(async () => {
const { data } = await operate({ type: "get_status" });
Expand All @@ -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),
);
Expand Down Expand Up @@ -222,16 +207,17 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
<CameraPresetSelect
options={presets}
label={(obj) => 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 ? (
Expand Down Expand Up @@ -277,7 +263,6 @@ type LastAccessedPreset = {

type LastAccessedPosition = {
type: "position";
assetBed: string;
value: PTZPayload;
};

Expand Down
Loading