Skip to content

Commit

Permalink
Merge branch 'main' into (refactor)O3-2815
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen authored Feb 23, 2024
2 parents c126e8c + ff152cf commit f311587
Show file tree
Hide file tree
Showing 36 changed files with 215 additions and 144 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ If you notice that your local version of the application is not working or that

```bash
# Upgrade core libraries
yarn up openmrs @openmrs/esm-framework
yarn up openmrs@next @openmrs/esm-framework@next

# Reset version specifiers to `next`. Don't commit actual version numbers.
git checkout package.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const FormRenderer: React.FC<FormRendererProps> = ({
patientUuid,
visit,
closeWorkspace,
closeWorkspaceWithSavedChanges,
encounterUuid,
mode,
}) => {
Expand Down Expand Up @@ -52,7 +53,7 @@ const FormRenderer: React.FC<FormRendererProps> = ({
visit={visit}
formJson={schema}
handleClose={closeWorkspace}
onSubmit={() => closeWorkspace({ ignoreChanges: true })}
onSubmit={closeWorkspaceWithSavedChanges}
mode={mode}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('FormRenderer', () => {
formUuid: 'test-form-uuid',
patientUuid: 'test-patient-uuid',
closeWorkspace: jest.fn(),
closeWorkspaceWithSavedChanges: jest.fn(),
promptBeforeClosing: jest.fn(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type AllergyFormData = {
};

function AllergyForm(props: DefaultWorkspaceProps) {
const { closeWorkspace, patientUuid, promptBeforeClosing } = props;
const { closeWorkspace, patientUuid, promptBeforeClosing, closeWorkspaceWithSavedChanges } = props;
const { t } = useTranslation();
const { concepts } = useConfig();
const isTablet = useLayoutType() === 'tablet';
Expand Down Expand Up @@ -166,7 +166,7 @@ function AllergyForm(props: DefaultWorkspaceProps) {
(response: FetchResponse) => {
if (response.status === 201) {
mutate();
closeWorkspace({ ignoreChanges: true });
closeWorkspaceWithSavedChanges();
showSnackbar({
isLowContrast: true,
kind: 'success',
Expand All @@ -186,7 +186,7 @@ function AllergyForm(props: DefaultWorkspaceProps) {
)
.finally(() => abortController.abort());
},
[otherConceptUuid, patientUuid, closeWorkspace, t, mutate],
[otherConceptUuid, patientUuid, closeWorkspaceWithSavedChanges, t, mutate],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ describe('AllergyForm ', () => {
function renderAllergyForm() {
const testProps = {
closeWorkspace: () => {},
closeWorkspaceWithSavedChanges: () => {},
promptBeforeClosing: () => {},
patient: mockPatient,
patientUuid: mockPatient.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PastVisitOverview from './past-visit-overview.component';

const testProps = {
closeWorkspace: jest.fn(),
closeWorkspaceWithSavedChanges: jest.fn(),
patientUuid: mockPatient.id,
promptBeforeClosing: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { useVisits } from '../visits-widget/visit.resource';
import { useOfflineVisitType } from '../hooks/useOfflineVisitType';

interface StartVisitFormProps extends DefaultWorkspaceProps {
visitToEdit: Visit;
visitToEdit?: Visit;
showVisitEndDateTimeFields: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const mockPromptBeforeClosing = jest.fn();
const testProps = {
patientUuid: mockPatient.id,
closeWorkspace: mockCloseWorkspace,
closeWorkspaceWithSavedChanges: mockCloseWorkspace,
promptBeforeClosing: mockPromptBeforeClosing,
visitToEdit: undefined,
showVisitEndDateTimeFields: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function WorkspaceRenderer({ workspace, patientUuid, active }: WorkspaceR
() =>
workspace && {
closeWorkspace: workspace.closeWorkspace,
closeWorkspaceWithSavedChanges: workspace.closeWorkspaceWithSavedChanges,
promptBeforeClosing: workspace.promptBeforeClosing,
patientUuid,
...workspace.additionalProps,
Expand Down
7 changes: 5 additions & 2 deletions packages/esm-patient-common-lib/src/types/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { closeWorkspace } from '../workspaces';

/* The possible states a workspace window can be opened in. */
export type WorkspaceWindowState = 'maximized' | 'hidden' | 'normal';

Expand Down Expand Up @@ -35,6 +33,11 @@ export interface DefaultWorkspaceProps {
* this workspace is closed; e.g. if there is unsaved data.
*/
promptBeforeClosing(testFcn: () => boolean): void;
/**
* Call this function to close the workspace after the form is saved. This function
* will directly close the workspace without any prompt
*/
closeWorkspaceWithSavedChanges(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
patientUuid: string;
handlePostResponse?(): void;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/esm-patient-common-lib/src/workspaces/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface WorkspaceStoreState {
export interface OpenWorkspace extends WorkspaceRegistration {
additionalProps: object;
closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): boolean;
closeWorkspaceWithSavedChanges(closeWorkspaceOptions?: CloseWorkspaceOptions): boolean;
promptBeforeClosing(testFcn: () => boolean): void;
}

Expand Down Expand Up @@ -163,6 +164,8 @@ export function launchPatientWorkspace(name: string, additionalProps?: object) {
const newWorkspace = {
...workspace,
closeWorkspace: (options: CloseWorkspaceOptions = {}) => closeWorkspace(name, options),
closeWorkspaceWithSavedChanges: (options: CloseWorkspaceOptions) =>
closeWorkspace(name, { ignoreChanges: true, ...options }),
promptBeforeClosing: (testFcn) => promptBeforeClosing(name, testFcn),
additionalProps,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type ConditionFormData = z.infer<typeof conditionSchema>;

const ConditionsForm: React.FC<ConditionFormProps> = ({
closeWorkspace,
closeWorkspaceWithSavedChanges,
condition,
formContext,
patientUuid,
Expand Down Expand Up @@ -77,7 +78,7 @@ const ConditionsForm: React.FC<ConditionFormProps> = ({
<Form className={styles.form} onSubmit={methods.handleSubmit(onSubmit, onError)}>
<ConditionsWidget
patientUuid={patientUuid}
closeWorkspace={closeWorkspace}
closeWorkspaceWithSavedChanges={closeWorkspaceWithSavedChanges}
conditionToEdit={condition}
editing={formContext === 'editing'}
setErrorCreating={setErrorCreating}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dayjs.extend(utc);

const testProps = {
closeWorkspace: jest.fn(),
closeWorkspaceWithSavedChanges: jest.fn(),
patientUuid: mockPatient.id,
formContext: 'creating' as const,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import styles from './conditions-form.scss';
import { type DefaultWorkspaceProps } from '@openmrs/esm-patient-common-lib';

interface ConditionsWidgetProps {
closeWorkspace?: DefaultWorkspaceProps['closeWorkspace'];
closeWorkspaceWithSavedChanges?: DefaultWorkspaceProps['closeWorkspaceWithSavedChanges'];
conditionToEdit?: ConditionDataTableRow;
editing?: boolean;
patientUuid: string;
Expand All @@ -44,7 +44,7 @@ interface ConditionsWidgetProps {
}

const ConditionsWidget: React.FC<ConditionsWidgetProps> = ({
closeWorkspace,
closeWorkspaceWithSavedChanges,
conditionToEdit,
editing,
patientUuid,
Expand Down Expand Up @@ -115,14 +115,14 @@ const ConditionsWidget: React.FC<ConditionsWidgetProps> = ({
title: t('conditionSaved', 'Condition saved'),
});

closeWorkspace?.({ ignoreChanges: true });
closeWorkspaceWithSavedChanges();
}
} catch (error) {
setIsSubmittingForm(false);
setErrorCreating(error);
}
}, [
closeWorkspace,
closeWorkspaceWithSavedChanges,
getValues,
mutate,
patientUuid,
Expand Down Expand Up @@ -157,14 +157,14 @@ const ConditionsWidget: React.FC<ConditionsWidgetProps> = ({
title: t('conditionUpdated', 'Condition updated'),
});

closeWorkspace({ ignoreChanges: true });
closeWorkspaceWithSavedChanges();
}
} catch (error) {
setIsSubmittingForm(false);
setErrorUpdating(error);
}
}, [
closeWorkspace,
closeWorkspaceWithSavedChanges,
conditionToEdit?.id,
displayName,
editableClinicalStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import styles from './flags-list.scss';

type dropdownFilter = 'A - Z' | 'Active first' | 'Retired first';

const FlagsList: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWorkspace }) => {
const FlagsList: React.FC<DefaultWorkspaceProps> = ({
patientUuid,
closeWorkspace,
closeWorkspaceWithSavedChanges,
}) => {
const { t } = useTranslation();
const { flags, isLoading, error, mutate } = usePatientFlags(patientUuid);
const isTablet = useLayoutType() === 'tablet';
Expand Down Expand Up @@ -198,15 +202,15 @@ const FlagsList: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWorkspac
</Stack>
</div>
<ButtonSet className={isTablet ? styles.tabletButtonSet : styles.desktopButtonSet}>
<Button className={styles.button} kind="secondary" onClick={() => closeWorkspace()}>
<Button className={styles.button} kind="secondary" onClick={closeWorkspace}>
{t('discard', 'Discard')}
</Button>
<Button
className={styles.button}
disabled={isEnabling || isDisabling}
kind="primary"
type="submit"
onClick={() => closeWorkspace()}
onClick={closeWorkspaceWithSavedChanges}
>
{(() => {
if (isEnabling) return t('enablingFlag', 'Enabling flag...');
Expand Down
9 changes: 8 additions & 1 deletion packages/esm-patient-flags-app/src/flags/flags-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ it('renders an Edit form that enables users to toggle flags on or off', async ()
});

function renderFlagsList() {
return render(<FlagsList closeWorkspace={jest.fn()} patientUuid={mockPatient.id} promptBeforeClosing={jest.fn()} />);
return render(
<FlagsList
closeWorkspace={jest.fn()}
closeWorkspaceWithSavedChanges={jest.fn()}
patientUuid={mockPatient.id}
promptBeforeClosing={jest.fn()}
/>,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ interface FormEntryComponentProps extends DefaultWorkspaceProps {
formInfo: FormEntryProps;
}

const FormEntry: React.FC<FormEntryComponentProps> = ({ patientUuid, closeWorkspace, mutateForm, formInfo }) => {
const FormEntry: React.FC<FormEntryComponentProps> = ({
patientUuid,
closeWorkspaceWithSavedChanges,
mutateForm,
formInfo,
}) => {
const { encounterUuid, formUuid, visitStartDatetime, visitStopDatetime, visitTypeUuid, visitUuid, additionalProps } =
formInfo || {};
const { patient } = usePatient(patientUuid);
Expand All @@ -32,7 +37,7 @@ const FormEntry: React.FC<FormEntryComponentProps> = ({ patientUuid, closeWorksp
encounterUuid: encounterUuid ?? null,
closeWorkspace: () => {
typeof mutateForm === 'function' && mutateForm();
closeWorkspace({ ignoreChanges: true });
closeWorkspaceWithSavedChanges();
},
additionalProps,
}),
Expand All @@ -51,7 +56,7 @@ const FormEntry: React.FC<FormEntryComponentProps> = ({ patientUuid, closeWorksp
patient,
isOnline,
mutateForm,
closeWorkspace,
closeWorkspaceWithSavedChanges,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('FormEntry', () => {
function renderFormEntry() {
const testProps = {
closeWorkspace: jest.fn(),
closeWorkspaceWithSavedChanges: jest.fn(),
promptBeforeClosing: jest.fn(),
patientUuid: mockPatient.id,
formInfo: { formUuid: 'some-form-uuid' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import styles from './forms-dashboard.scss';
import { useForms } from '../hooks/use-forms';
import { useTranslation } from 'react-i18next';

const FormsDashboard: React.FC<DefaultWorkspaceProps> = ({ closeWorkspace }) => {
const FormsDashboard: React.FC<DefaultWorkspaceProps> = () => {
const { t } = useTranslation();
const config = useConfig<ConfigObject>();
const isOnline = useConnectivity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ describe('FormsDashboard', () => {
});

function renderFormDashboard() {
render(<FormsDashboard promptBeforeClosing={jest.fn()} closeWorkspace={jest.fn()} patientUuid="" />);
render(
<FormsDashboard
promptBeforeClosing={jest.fn()}
closeWorkspace={jest.fn()}
closeWorkspaceWithSavedChanges={jest.fn()}
patientUuid=""
/>,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ interface ResponsiveWrapperProps {

const datePickerFormat = 'd/m/Y';

const ImmunizationsForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, closeWorkspace, promptBeforeClosing }) => {
const ImmunizationsForm: React.FC<DefaultWorkspaceProps> = ({
patientUuid,
closeWorkspace,
closeWorkspaceWithSavedChanges,
promptBeforeClosing,
}) => {
const { t } = useTranslation();
const [isSubmitting, setIsSubmitting] = useState(false);
const { immunizationsConfig } = useConfig() as ConfigObject;
Expand Down Expand Up @@ -184,7 +189,7 @@ const ImmunizationsForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, close
).then(
() => {
setIsSubmitting(false);
closeWorkspace({ ignoreChanges: true });
closeWorkspaceWithSavedChanges();
mutate();
showSnackbar({
kind: 'success',
Expand All @@ -211,7 +216,7 @@ const ImmunizationsForm: React.FC<DefaultWorkspaceProps> = ({ patientUuid, close
currentVisit?.uuid,
immunizationToEditMeta,
immunizationsConceptSet,
closeWorkspace,
closeWorkspaceWithSavedChanges,
t,
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { immunizationFormSub } from './utils';
import { showSnackbar } from '@openmrs/esm-framework';

const mockCloseWorkspace = jest.fn();
const mockDiscardAndCloseWorkspace = jest.fn();
const mockCloseWorkspaceWithSavedChanges = jest.fn();
const mockPromptBeforeClosing = jest.fn();
const mockSavePatientImmunization = savePatientImmunization as jest.Mock;

Expand Down Expand Up @@ -84,6 +84,7 @@ jest.mock('./immunizations.resource', () => ({
const testProps = {
patientUuid: mockPatient.id,
closeWorkspace: mockCloseWorkspace,
closeWorkspaceWithSavedChanges: mockCloseWorkspaceWithSavedChanges,
promptBeforeClosing: mockPromptBeforeClosing,
};

Expand Down
Loading

0 comments on commit f311587

Please sign in to comment.