import { useCallback } from 'react' import PropTypes from 'prop-types' import { Dropdown, MenuItem, OverlayTrigger, Tooltip } from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import Icon from '../../../shared/components/icon' import IconChecked from '../../../shared/components/icon-checked' import ControlledDropdown from '../../../shared/components/controlled-dropdown' import IconEditorOnly from './icon-editor-only' import IconPdfOnly from './icon-pdf-only' import { useLayoutContext } from '../../../shared/context/layout-context' import * as eventTracking from '../../../infrastructure/event-tracking' function IconPlaceholder() { return } function IconRefresh() { return } function IconLayout() { return } function IconDetach() { return } function IconCheckmark({ iconFor, pdfLayout, view, detachRole }) { if (detachRole === 'detacher' || view === 'history') { return } if ( iconFor === 'editorOnly' && pdfLayout === 'flat' && (view === 'editor' || view === 'file') ) { return } else if (iconFor === 'pdfOnly' && pdfLayout === 'flat' && view === 'pdf') { return } else if (iconFor === 'sideBySide' && pdfLayout === 'sideBySide') { return } // return empty icon for placeholder return } function PdfDetachMenuItem({ handleDetach, children }) { const { t } = useTranslation() if (!('BroadcastChannel' in window)) { return ( {t('your_browser_does_not_support_this_feature')} } > {children} ) } return {children} } PdfDetachMenuItem.propTypes = { handleDetach: PropTypes.func.isRequired, children: PropTypes.arrayOf(PropTypes.node).isRequired, } function LayoutDropdownButton() { const { t } = useTranslation() const { reattach, detach, detachIsLinked, detachRole, changeLayout, view, pdfLayout, } = useLayoutContext(layoutContextPropTypes) const handleDetach = useCallback(() => { detach() eventTracking.sendMB('project-layout-detach') }, [detach]) const handleReattach = useCallback(() => { if (detachRole !== 'detacher') { return } reattach() eventTracking.sendMB('project-layout-reattach') }, [detachRole, reattach]) const handleChangeLayout = useCallback( (newLayout, newView) => { handleReattach() changeLayout(newLayout, newView) eventTracking.sendMB('project-layout-change', { layout: newLayout, view: newView, }) }, [changeLayout, handleReattach] ) const processing = !detachIsLinked && detachRole === 'detacher' // bsStyle is required for Dropdown.Toggle, but we will override style return ( <> {processing && (
{t('layout_processing')}
)} {processing ? : } {t('layout')} Beta feature} delayHide={100} > handleChangeLayout('sideBySide')}> {t('editor_and_pdf')} handleChangeLayout('flat', 'editor')} className="menu-item-with-svg" > , ]} /> handleChangeLayout('flat', 'pdf')} className="menu-item-with-svg" > , ]} /> {detachRole === 'detacher' ? ( {detachIsLinked ? : } {t('pdf_in_separate_tab')} ) : ( {t('pdf_in_separate_tab')} )}
The Layout menu and opening the PDF in a new tab are beta features.{' '} {t('give_feedback')}.
) } export default LayoutDropdownButton IconCheckmark.propTypes = { iconFor: PropTypes.string.isRequired, pdfLayout: PropTypes.string.isRequired, view: PropTypes.string, detachRole: PropTypes.string, } const layoutContextPropTypes = { reattach: PropTypes.func.isRequired, detach: PropTypes.func.isRequired, changeLayout: PropTypes.func.isRequired, detachIsLinked: PropTypes.bool, detachRole: PropTypes.string, pdfLayout: PropTypes.string.isRequired, view: PropTypes.string, }