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

(fix) O3-2813 disable test type edit when modifying lab orders #1782

Merged
merged 4 commits into from
Apr 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function AddLabOrderWorkspace({
}: AddLabOrderWorkspace) {
const { t } = useTranslation();

const { patient, isLoading: isLoadingPatient } = usePatient();
const { patient, isLoading: isLoadingPatient, patientUuid } = usePatient();
Copy link
Member

Choose a reason for hiding this comment

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

All workspaces should receive the patientUuid prop implicitly. You shouldn't need to drill the prop down to LabOrderForm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Found a weird behaviour testing this that's why i added this change. Maybe it was a unique case.

const [currentLabOrder, setCurrentLabOrder] = useState(initialOrder as LabOrderBasketItem);

const isTablet = useLayoutType() === 'tablet';
Expand Down Expand Up @@ -73,6 +73,7 @@ export default function AddLabOrderWorkspace({
) : (
<LabOrderForm
initialOrder={currentLabOrder}
patientUuid={patientUuid}
closeWorkspace={closeWorkspace}
closeWorkspaceWithSavedChanges={closeWorkspaceWithSavedChanges}
promptBeforeClosing={promptBeforeClosing}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import {
type LabOrderBasketItem,
type DefaultWorkspaceProps,
launchPatientWorkspace,
promptBeforeClosing,
useOrderBasket,
} from '@openmrs/esm-patient-common-lib';
import { translateFrom, useLayoutType, useSession, useConfig } from '@openmrs/esm-framework';
Expand All @@ -31,11 +30,8 @@ import { moduleName } from '@openmrs/esm-patient-chart-app/src/constants';
import { type ConfigObject } from '../../config-schema';
import styles from './lab-order-form.scss';

export interface LabOrderFormProps {
export interface LabOrderFormProps extends DefaultWorkspaceProps {
initialOrder: LabOrderBasketItem;
closeWorkspace: DefaultWorkspaceProps['closeWorkspace'];
closeWorkspaceWithSavedChanges: DefaultWorkspaceProps['closeWorkspaceWithSavedChanges'];
promptBeforeClosing: DefaultWorkspaceProps['promptBeforeClosing'];
}

// Designs:
Expand All @@ -50,6 +46,7 @@ export function LabOrderForm({
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const session = useSession();
const isEditing = useMemo(() => initialOrder && initialOrder.action === 'REVISE', [initialOrder]);
const { orders, setOrders } = useOrderBasket<LabOrderBasketItem>('labs', prepLabOrderPostData);
const { testTypes, isLoading: isLoadingTestTypes, error: errorLoadingTestTypes } = useTestTypes();
const [showErrorNotification, setShowErrorNotification] = useState(false);
Expand Down Expand Up @@ -171,7 +168,7 @@ export function LabOrderForm({
isLoadingTestTypes ? `${t('loading', 'Loading')}...` : t('testTypePlaceholder', 'Select one')
}
onBlur={onBlur}
disabled={isLoadingTestTypes}
disabled={isLoadingTestTypes || isEditing}
onChange={({ selectedItem }) => onChange(selectedItem)}
invalid={errors.testType?.message}
invalidText={errors.testType?.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ const OrderDetailsTable: React.FC<OrderDetailsProps> = ({ title, patientUuid, sh
? t('orders', 'Orders')
: (orderTypes?.find((x) => x.uuid === selectedOrderTypeUuid)).display + 's'
}
launchForm={launchOrderBasket}
/>
) : (
<div className={styles.widgetCard}>
Expand All @@ -316,7 +317,7 @@ const OrderDetailsTable: React.FC<OrderDetailsProps> = ({ title, patientUuid, sh
{t('print', 'Print')}
</Button>
)}
{showAddButton ?? true ? (
{showAddButton && (
<Button
kind="ghost"
renderIcon={(props) => <Add size={16} {...props} />}
Expand All @@ -325,7 +326,7 @@ const OrderDetailsTable: React.FC<OrderDetailsProps> = ({ title, patientUuid, sh
>
{t('add', 'Add')}
</Button>
) : null}
)}
</div>
</CardHeader>
<div ref={contentToPrintRef}>
Expand Down
Loading
Loading