From d5c2f3ecc82ade34ee5ea9e3dcf9c40249876ac5 Mon Sep 17 00:00:00 2001 From: Bhargav kodali <115476530+kb019@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:29:55 -0700 Subject: [PATCH] (fix) O3-4004 - ward app - better way to fix patient action menu button in workspace (#1346) * add depedency in use effect * undo changes in o3-4004 * correct type --- packages/esm-ward-app/src/types/index.ts | 2 ++ .../ward-patient-card.component.tsx | 12 +++++------- .../ward-patient-resource.ts | 16 ---------------- .../ward-patient-action-button.extension.tsx | 4 ++-- .../ward-patient.workspace.tsx | 19 +++++++++++++------ 5 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 packages/esm-ward-app/src/ward-patient-card/ward-patient-resource.ts diff --git a/packages/esm-ward-app/src/types/index.ts b/packages/esm-ward-app/src/types/index.ts index 92fc41166..0492839f9 100644 --- a/packages/esm-ward-app/src/types/index.ts +++ b/packages/esm-ward-app/src/types/index.ts @@ -231,3 +231,5 @@ export interface WardViewContext { export interface MaternalWardViewContext { motherChildrenRelationshipsByPatient: Map; } + +export type PatientWorkspaceAdditionalProps = Omit; \ No newline at end of file diff --git a/packages/esm-ward-app/src/ward-patient-card/ward-patient-card.component.tsx b/packages/esm-ward-app/src/ward-patient-card/ward-patient-card.component.tsx index 0916a5f4a..a6ed06ec0 100644 --- a/packages/esm-ward-app/src/ward-patient-card/ward-patient-card.component.tsx +++ b/packages/esm-ward-app/src/ward-patient-card/ward-patient-card.component.tsx @@ -1,8 +1,7 @@ -import { getPatientName, useAppContext } from '@openmrs/esm-framework'; +import { getPatientName, launchWorkspace, useAppContext } from '@openmrs/esm-framework'; import React, { type ReactNode } from 'react'; -import { type WardViewContext, type WardPatient } from '../types'; +import { type WardViewContext, type WardPatient,type PatientWorkspaceAdditionalProps } from '../types'; import styles from './ward-patient-card.scss'; -import { launchPatientWorkspace, setPatientWorkspaceProps } from './ward-patient-resource'; interface Props { children: ReactNode; @@ -19,12 +18,11 @@ const WardPatientCard: React.FC = ({ children, wardPatient }) => { diff --git a/packages/esm-ward-app/src/ward-patient-card/ward-patient-resource.ts b/packages/esm-ward-app/src/ward-patient-card/ward-patient-resource.ts deleted file mode 100644 index f1284471a..000000000 --- a/packages/esm-ward-app/src/ward-patient-card/ward-patient-resource.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { type DefaultWorkspaceProps, launchWorkspace } from '@openmrs/esm-framework'; -import { type WardPatientWorkspaceProps } from '../types'; - -type PatientWorkspaceAdditionalProps = Omit; - -// workspaces launched from workspace action menu buttons sometimes lose -// access to their props. This serves as a workaround. -// See: https://openmrs.atlassian.net/browse/O3-4004 -let props: PatientWorkspaceAdditionalProps = null; -export function setPatientWorkspaceProps(newProps: PatientWorkspaceAdditionalProps) { - props = newProps; -} - -export function launchPatientWorkspace() { - launchWorkspace('ward-patient-workspace', props); -} diff --git a/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient-action-button.extension.tsx b/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient-action-button.extension.tsx index be36c5403..7be3a9a86 100644 --- a/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient-action-button.extension.tsx +++ b/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient-action-button.extension.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { UserAvatarIcon } from '@openmrs/esm-framework'; import { ActionMenuButton, launchWorkspace } from '@openmrs/esm-framework'; -import { launchPatientWorkspace } from '../../ward-patient-card/ward-patient-resource'; +import type { WardPatientWorkspaceProps } from '../../types'; export default function WardPatientActionButton() { const { t } = useTranslation(); @@ -12,7 +12,7 @@ export default function WardPatientActionButton() { getIcon={(props) => } label={t('Patient', 'patient')} iconDescription={t('Patient', 'patient')} - handler={() => launchPatientWorkspace()} + handler={() => launchWorkspace('ward-patient-workspace')} type={'ward'} /> ); diff --git a/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient.workspace.tsx b/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient.workspace.tsx index cfd9e51ee..f96cf342a 100644 --- a/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient.workspace.tsx +++ b/packages/esm-ward-app/src/ward-workspace/patient-details/ward-patient.workspace.tsx @@ -7,15 +7,22 @@ import { getGender } from '../../ward-patient-card/row-elements/ward-patient-gen attach('ward-patient-workspace-header-slot', 'patient-vitals-info'); -export default function WardPatientWorkspace({ setTitle, wardPatient: { patient } }: WardPatientWorkspaceProps) { +export default function WardPatientWorkspace({ setTitle, wardPatient }: WardPatientWorkspaceProps) { useEffect(() => { - setTitle(patient.person.display, ); - }, [patient.uuid]); + if (wardPatient) { + const { patient } = wardPatient; + setTitle(patient.person.display, ); + } + }, [wardPatient]); return ( -
- -
+ <> + {wardPatient && ( +
+ +
+ )} + ); }