2022-06-08 08:49:35 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
2021-11-03 09:21:14 -04:00
|
|
|
import PropTypes from 'prop-types'
|
2022-05-18 09:46:10 -04:00
|
|
|
import { Dropdown, MenuItem } from 'react-bootstrap'
|
2021-11-03 09:21:14 -04:00
|
|
|
import { Trans, useTranslation } from 'react-i18next'
|
2022-05-18 09:46:10 -04:00
|
|
|
import Tooltip from '../../../shared/components/tooltip'
|
2021-11-03 09:21:14 -04:00
|
|
|
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'
|
2021-11-30 09:54:14 -05:00
|
|
|
import { useLayoutContext } from '../../../shared/context/layout-context'
|
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
2022-05-20 04:15:14 -04:00
|
|
|
import useEventListener from '../../../shared/hooks/use-event-listener'
|
2021-11-03 09:21:14 -04:00
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
function IconPlaceholder() {
|
2022-01-19 06:56:57 -05:00
|
|
|
return <Icon type="" fw />
|
2021-11-30 09:54:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function IconRefresh() {
|
2022-01-19 06:56:57 -05:00
|
|
|
return <Icon type="refresh" fw spin />
|
2021-11-30 09:54:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function IconLayout() {
|
2022-01-19 06:56:57 -05:00
|
|
|
return <Icon type="columns" fw />
|
2021-11-30 09:54:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function IconDetach() {
|
2022-01-19 06:56:57 -05:00
|
|
|
return <Icon type="window-restore" fw />
|
2021-11-30 09:54:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function IconCheckmark({ iconFor, pdfLayout, view, detachRole }) {
|
2022-03-15 09:55:17 -04:00
|
|
|
if (detachRole === 'detacher' || view === 'history') {
|
2021-11-30 09:54:14 -05:00
|
|
|
return <IconPlaceholder />
|
|
|
|
}
|
2022-03-15 09:55:17 -04:00
|
|
|
if (
|
|
|
|
iconFor === 'editorOnly' &&
|
|
|
|
pdfLayout === 'flat' &&
|
|
|
|
(view === 'editor' || view === 'file')
|
|
|
|
) {
|
2021-11-03 09:21:14 -04:00
|
|
|
return <IconChecked />
|
|
|
|
} else if (iconFor === 'pdfOnly' && pdfLayout === 'flat' && view === 'pdf') {
|
|
|
|
return <IconChecked />
|
|
|
|
} else if (iconFor === 'sideBySide' && pdfLayout === 'sideBySide') {
|
|
|
|
return <IconChecked />
|
|
|
|
}
|
|
|
|
// return empty icon for placeholder
|
2021-11-30 09:54:14 -05:00
|
|
|
return <IconPlaceholder />
|
2021-11-03 09:21:14 -04:00
|
|
|
}
|
|
|
|
|
2022-06-08 08:49:35 -04:00
|
|
|
function LayoutMenuItem({ checkmark, icon, text, ...props }) {
|
2022-05-24 07:22:11 -04:00
|
|
|
return (
|
|
|
|
<MenuItem {...props}>
|
|
|
|
<div className="layout-menu-item">
|
|
|
|
<div className="layout-menu-item-start">
|
|
|
|
<div>{checkmark}</div>
|
|
|
|
<div>{icon}</div>
|
|
|
|
<div>{text}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
LayoutMenuItem.propTypes = {
|
|
|
|
checkmark: PropTypes.node.isRequired,
|
|
|
|
icon: PropTypes.node.isRequired,
|
|
|
|
text: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
|
|
|
onSelect: PropTypes.func,
|
2022-05-16 05:52:12 -04:00
|
|
|
}
|
2022-05-18 09:46:10 -04:00
|
|
|
|
2022-05-24 07:22:11 -04:00
|
|
|
function DetachDisabled() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
id="detach-disabled"
|
|
|
|
description={t('your_browser_does_not_support_this_feature')}
|
|
|
|
overlayProps={{ placement: 'left' }}
|
|
|
|
>
|
|
|
|
<LayoutMenuItem
|
|
|
|
disabled
|
|
|
|
checkmark={<IconPlaceholder />}
|
|
|
|
icon={<IconDetach />}
|
|
|
|
text={t('pdf_in_separate_tab')}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
)
|
2022-05-16 05:52:12 -04:00
|
|
|
}
|
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
function LayoutDropdownButton() {
|
2021-11-03 09:21:14 -04:00
|
|
|
const { t } = useTranslation()
|
2021-11-15 11:33:57 -05:00
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
const {
|
|
|
|
reattach,
|
|
|
|
detach,
|
|
|
|
detachIsLinked,
|
|
|
|
detachRole,
|
|
|
|
changeLayout,
|
|
|
|
view,
|
|
|
|
pdfLayout,
|
|
|
|
} = useLayoutContext(layoutContextPropTypes)
|
|
|
|
|
|
|
|
const handleDetach = useCallback(() => {
|
|
|
|
detach()
|
|
|
|
eventTracking.sendMB('project-layout-detach')
|
2022-03-31 07:22:36 -04:00
|
|
|
}, [detach])
|
2021-11-30 09:54:14 -05:00
|
|
|
|
|
|
|
const handleReattach = useCallback(() => {
|
|
|
|
if (detachRole !== 'detacher') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
reattach()
|
|
|
|
eventTracking.sendMB('project-layout-reattach')
|
|
|
|
}, [detachRole, reattach])
|
|
|
|
|
2022-05-20 04:15:14 -04:00
|
|
|
// reattach when the PDF pane opens
|
|
|
|
useEventListener('ui:pdf-open', handleReattach)
|
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
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'
|
|
|
|
|
2021-11-03 09:21:14 -04:00
|
|
|
// bsStyle is required for Dropdown.Toggle, but we will override style
|
|
|
|
return (
|
2021-11-15 11:33:57 -05:00
|
|
|
<>
|
2021-11-30 09:54:14 -05:00
|
|
|
{processing && (
|
2021-11-15 11:33:57 -05:00
|
|
|
<div aria-live="assertive" className="sr-only">
|
|
|
|
{t('layout_processing')}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<ControlledDropdown
|
|
|
|
id="layout-dropdown"
|
2021-12-02 10:18:20 -05:00
|
|
|
className="toolbar-item layout-dropdown"
|
2021-11-30 09:54:14 -05:00
|
|
|
pullRight
|
2021-11-15 11:33:57 -05:00
|
|
|
>
|
|
|
|
<Dropdown.Toggle className="btn-full-height" bsStyle="link">
|
2021-11-30 09:54:14 -05:00
|
|
|
{processing ? <IconRefresh /> : <IconLayout />}
|
2021-11-15 11:33:57 -05:00
|
|
|
<span className="toolbar-label">{t('layout')}</span>
|
2022-05-18 09:46:10 -04:00
|
|
|
<Tooltip
|
|
|
|
id="pdf-detach-badge"
|
2022-05-30 06:19:31 -04:00
|
|
|
description="New feature"
|
2022-05-18 09:46:10 -04:00
|
|
|
overlayProps={{ placement: 'bottom', delayHide: 100 }}
|
2021-12-02 10:18:20 -05:00
|
|
|
>
|
2022-05-30 06:19:31 -04:00
|
|
|
<span className="info-badge" />
|
2022-05-18 09:46:10 -04:00
|
|
|
</Tooltip>
|
2021-11-15 11:33:57 -05:00
|
|
|
</Dropdown.Toggle>
|
2022-05-24 07:22:11 -04:00
|
|
|
<Dropdown.Menu className="layout-dropdown-list">
|
|
|
|
<LayoutMenuItem
|
|
|
|
onSelect={() => handleChangeLayout('sideBySide')}
|
|
|
|
checkmark={
|
|
|
|
<IconCheckmark
|
|
|
|
iconFor="sideBySide"
|
|
|
|
pdfLayout={pdfLayout}
|
|
|
|
view={view}
|
|
|
|
detachRole={detachRole}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
icon={<Icon type="columns" fw />}
|
|
|
|
text={t('editor_and_pdf')}
|
|
|
|
/>
|
2021-11-15 11:33:57 -05:00
|
|
|
|
2022-05-24 07:22:11 -04:00
|
|
|
<LayoutMenuItem
|
2021-11-15 11:33:57 -05:00
|
|
|
onSelect={() => handleChangeLayout('flat', 'editor')}
|
2022-05-24 07:22:11 -04:00
|
|
|
checkmark={
|
|
|
|
<IconCheckmark
|
|
|
|
iconFor="editorOnly"
|
|
|
|
pdfLayout={pdfLayout}
|
|
|
|
view={view}
|
|
|
|
detachRole={detachRole}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
icon={
|
|
|
|
<i className="fa fa-fw">
|
|
|
|
<IconEditorOnly />
|
|
|
|
</i>
|
|
|
|
}
|
|
|
|
text={
|
2021-12-02 10:18:20 -05:00
|
|
|
<Trans
|
|
|
|
i18nKey="editor_only_hide_pdf"
|
|
|
|
components={[
|
|
|
|
<span key="editor_only_hide_pdf" className="subdued" />,
|
|
|
|
]}
|
|
|
|
/>
|
2022-05-24 07:22:11 -04:00
|
|
|
}
|
|
|
|
/>
|
2021-11-15 11:33:57 -05:00
|
|
|
|
2022-05-24 07:22:11 -04:00
|
|
|
<LayoutMenuItem
|
2021-11-15 11:33:57 -05:00
|
|
|
onSelect={() => handleChangeLayout('flat', 'pdf')}
|
2022-05-24 07:22:11 -04:00
|
|
|
checkmark={
|
|
|
|
<IconCheckmark
|
|
|
|
iconFor="pdfOnly"
|
|
|
|
pdfLayout={pdfLayout}
|
|
|
|
view={view}
|
|
|
|
detachRole={detachRole}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
icon={
|
|
|
|
<i className="fa fa-fw">
|
|
|
|
<IconPdfOnly />
|
|
|
|
</i>
|
|
|
|
}
|
|
|
|
text={
|
2021-12-02 10:18:20 -05:00
|
|
|
<Trans
|
|
|
|
i18nKey="pdf_only_hide_editor"
|
|
|
|
components={[
|
|
|
|
<span key="pdf_only_hide_editor" className="subdued" />,
|
|
|
|
]}
|
|
|
|
/>
|
2022-05-24 07:22:11 -04:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{'BroadcastChannel' in window ? (
|
|
|
|
<LayoutMenuItem
|
|
|
|
onSelect={() => handleDetach()}
|
|
|
|
checkmark={
|
|
|
|
detachRole === 'detacher' ? (
|
|
|
|
detachIsLinked ? (
|
|
|
|
<IconChecked />
|
|
|
|
) : (
|
|
|
|
<IconRefresh />
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<IconPlaceholder />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
icon={<IconDetach />}
|
|
|
|
text={t('pdf_in_separate_tab')}
|
|
|
|
/>
|
2021-11-15 11:33:57 -05:00
|
|
|
) : (
|
2022-05-24 07:22:11 -04:00
|
|
|
<DetachDisabled />
|
2021-11-15 11:33:57 -05:00
|
|
|
)}
|
2021-12-02 10:18:20 -05:00
|
|
|
|
|
|
|
<MenuItem divider />
|
|
|
|
<div className="pdf-detach-survey">
|
|
|
|
<span>
|
2022-05-30 06:19:31 -04:00
|
|
|
<span className="info-badge" />
|
2021-12-02 10:18:20 -05:00
|
|
|
</span>
|
|
|
|
<span className="pdf-detach-survey-text">
|
2022-05-30 06:19:31 -04:00
|
|
|
The Layout menu and opening the PDF in a new tab are new features.{' '}
|
2021-12-02 10:18:20 -05:00
|
|
|
<a
|
2022-06-14 04:13:23 -04:00
|
|
|
href="https://docs.google.com/forms/d/1fhc2LUMoun9jXvz9Nd6KkIKAQ8ZBfVZm_w8BpinpWu4"
|
2021-12-02 10:18:20 -05:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('give_feedback')}.
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-11-15 11:33:57 -05:00
|
|
|
</Dropdown.Menu>
|
|
|
|
</ControlledDropdown>
|
|
|
|
</>
|
2021-11-03 09:21:14 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-24 07:22:11 -04:00
|
|
|
export default memo(LayoutDropdownButton)
|
2021-11-03 09:21:14 -04:00
|
|
|
|
|
|
|
IconCheckmark.propTypes = {
|
|
|
|
iconFor: PropTypes.string.isRequired,
|
|
|
|
pdfLayout: PropTypes.string.isRequired,
|
|
|
|
view: PropTypes.string,
|
2021-11-30 09:54:14 -05:00
|
|
|
detachRole: PropTypes.string,
|
2021-11-03 09:21:14 -04:00
|
|
|
}
|
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
const layoutContextPropTypes = {
|
2021-11-15 11:33:57 -05:00
|
|
|
reattach: PropTypes.func.isRequired,
|
|
|
|
detach: PropTypes.func.isRequired,
|
2021-11-30 09:54:14 -05:00
|
|
|
changeLayout: PropTypes.func.isRequired,
|
|
|
|
detachIsLinked: PropTypes.bool,
|
2021-11-15 11:33:57 -05:00
|
|
|
detachRole: PropTypes.string,
|
2021-11-03 09:21:14 -04:00
|
|
|
pdfLayout: PropTypes.string.isRequired,
|
|
|
|
view: PropTypes.string,
|
|
|
|
}
|