// PrinterSelect.js import PropTypes from 'prop-types' import { Flex, Typography, Popover } from 'antd' import { useNavigate } from 'react-router-dom' import { useMediaQuery } from 'react-responsive' import CopyButton from './CopyButton' import SpotlightTooltip from './SpotlightTooltip' import { getModelByName } from '../../../database/ObjectModels' const { Text, Link } = Typography const IdDisplay = ({ id, reference = null, plainCode = false, type, showCopy = true, longId = true, showHyperlink = false, showSpotlight = true }) => { const navigate = useNavigate() const isMobile = useMediaQuery({ maxWidth: 768 }) const model = getModelByName(type) const prefix = model.prefix var hyperlink = null const defaultModelActions = model.actions?.filter((action) => action.default == true) || [] if (defaultModelActions.length >= 1) { hyperlink = defaultModelActions[0].url(id) } if (!id) { return n/a } id = typeof id === 'string' ? id.toString().toUpperCase() : 'XXXXXX' var displayId = prefix + ':' + id var copyId = prefix + ':' + id if (longId == false || isMobile) { displayId = prefix + ':' + id.toString().slice(-6) } if (reference) { displayId = prefix + ':' + reference } return ( {(() => { var textElement = ( {displayId} ) if (plainCode == false) { textElement = ( {displayId} ) } // If hyperlink is enabled if (showHyperlink && hyperlink != null) { const linkElement = ( navigate(hyperlink)} ellipsis style={showCopy ? { marginRight: 6 } : undefined} > {textElement} ) if (showSpotlight) { return ( ) : null } trigger={['hover', 'click']} placement='topLeft' arrow={false} style={{ padding: 0 }} > {linkElement} ) } return linkElement } // If hyperlink is disabled if (showSpotlight) { return ( ) : null } trigger={['hover', 'click']} placement='topLeft' arrow={false} > {textElement} ) } return textElement })()} {showCopy && ( )} ) } IdDisplay.propTypes = { id: PropTypes.string, type: PropTypes.string, reference: PropTypes.string, showCopy: PropTypes.bool, longId: PropTypes.bool, showHyperlink: PropTypes.bool, plainCode: PropTypes.bool, showSpotlight: PropTypes.bool } export default IdDisplay