Skip to content

Commit

Permalink
(fix) O3-4004 - ward app - better way to fix patient action menu butt…
Browse files Browse the repository at this point in the history
…on in workspace (#1346)

* add depedency in use effect

* undo changes in o3-4004

* correct type
  • Loading branch information
kb019 authored Oct 15, 2024
1 parent 6f337de commit d5c2f3e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
2 changes: 2 additions & 0 deletions packages/esm-ward-app/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,5 @@ export interface WardViewContext {
export interface MaternalWardViewContext {
motherChildrenRelationshipsByPatient: Map<string, MotherAndChild[]>;
}

export type PatientWorkspaceAdditionalProps = Omit<WardPatientWorkspaceProps, keyof DefaultWorkspaceProps>;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,12 +18,11 @@ const WardPatientCard: React.FC<Props> = ({ children, wardPatient }) => {
<button
className={styles.wardPatientCardButton}
onClick={() => {
setPatientWorkspaceProps({
launchWorkspace<PatientWorkspaceAdditionalProps>('ward-patient-workspace', {
wardPatient,
WardPatientHeader,
WardPatientHeader
});
launchPatientWorkspace();
}}>
}}>
{/* Name will not be displayed; just there for a11y */}
{getPatientName(patient.person)}
</button>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -12,7 +12,7 @@ export default function WardPatientActionButton() {
getIcon={(props) => <UserAvatarIcon {...props} />}
label={t('Patient', 'patient')}
iconDescription={t('Patient', 'patient')}
handler={() => launchPatientWorkspace()}
handler={() => launchWorkspace<WardPatientWorkspaceProps>('ward-patient-workspace')}
type={'ward'}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, <PatientWorkspaceTitle key={patient.uuid} patient={patient} />);
}, [patient.uuid]);
if (wardPatient) {
const { patient } = wardPatient;
setTitle(patient.person.display, <PatientWorkspaceTitle key={patient.uuid} patient={patient} />);
}
}, [wardPatient]);

return (
<div className={styles.workspaceContainer}>
<WardPatientWorkspaceView patient={patient} />
</div>
<>
{wardPatient && (
<div className={styles.workspaceContainer}>
<WardPatientWorkspaceView patient={wardPatient.patient} />
</div>
)}
</>
);
}

Expand Down

0 comments on commit d5c2f3e

Please sign in to comment.