import React, { MouseEventHandler, ReactElement, useCallback, useEffect, useRef, useState, } from 'react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { Icons } from '@ohif/ui-next'; import { PatientInfo } from './PatientInfo'; /** * This is the modern Viewport Action Bar, showing patient info, series date, * series description, and optional next/prev arrows if there's enough screen width. */ type ViewportActionBarProps = { studyData: any; onArrowsClick: (arrow: string) => void; onDoubleClick: MouseEventHandler; getStatusComponent: () => ReactElement; }; function ViewportActionBar({ studyData, onArrowsClick, onDoubleClick, getStatusComponent, }: ViewportActionBarProps): JSX.Element { const { label, studyDate, seriesDescription, patientInformation } = studyData; const { patientName, patientSex, patientAge, MRN, thickness, thicknessUnits, spacing, scanner } = patientInformation; const [showPatientInfo, setShowPatientInfo] = useState(false); const showPatientInfoElemRef = useRef(null); const { t } = useTranslation(); // handle click outside to close patient info const handleClickOutside = useCallback( (evt: MouseEvent) => { if ( showPatientInfo && showPatientInfoElemRef.current && !showPatientInfoElemRef.current.contains(evt.target as Node) ) { setShowPatientInfo(false); } }, [showPatientInfoElemRef, showPatientInfo] ); useEffect(() => { document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [handleClickOutside]); return (
{getStatusComponent()} {!!label?.length && {label}}
{studyDate}
{seriesDescription} {/* Prev/Next icons */} onArrowsClick('left')} /> onArrowsClick('right')} /> {/* Patient Info */}
setShowPatientInfo(!showPatientInfo)}>
); } ViewportActionBar.propTypes = { onArrowsClick: PropTypes.func.isRequired, onDoubleClick: PropTypes.func, studyData: PropTypes.shape({ label: PropTypes.string.isRequired, studyDate: PropTypes.string.isRequired, seriesDescription: PropTypes.string.isRequired, patientInformation: PropTypes.shape({ patientName: PropTypes.string, patientSex: PropTypes.string, patientAge: PropTypes.string, MRN: PropTypes.string, thickness: PropTypes.string, thicknessUnits: PropTypes.string, spacing: PropTypes.string, scanner: PropTypes.string, }), }).isRequired, getStatusComponent: PropTypes.func.isRequired, }; export { ViewportActionBar };