import React, { useMemo, useRef } from 'react'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { ClickableTile, IconButton, Tile } from '@carbon/react'; import { ExtensionSlot, TrashCanIcon, useLayoutType, WarningIcon } from '@openmrs/esm-framework'; import type { TestOrderBasketItem } from '@openmrs/esm-patient-common-lib'; import styles from './lab-order-basket-item-tile.scss'; export interface OrderBasketItemTileProps { orderBasketItem: TestOrderBasketItem; onItemClick: () => void; onRemoveClick: () => void; } export function LabOrderBasketItemTile({ orderBasketItem, onItemClick, onRemoveClick }: OrderBasketItemTileProps) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; // This here is really dirty, but required. // If the ref's value is false, we won't react to the ClickableTile's handleClick function. // Why is this necessary? // The "Remove" button is nested inside the ClickableTile. If the button's clicked, the tile also raises the // handleClick event later. Not sure if this is a bug, but this shouldn't be possible in our flows. // Hence, we manually prevent the handleClick callback from being invoked as soon as the button is pressed once. const shouldOnClickBeCalled = useRef(true); const additionalInfoSlotState = useMemo( () => ({ orderItemUuid: orderBasketItem.testType.conceptUuid, }), [orderBasketItem], ); const labTile = (