forked from ApryseSDK/webviewer-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
211 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import ShareTypes from 'constants/shareTypes'; | ||
import DataElementWrapper from 'components/DataElementWrapper'; | ||
import ShareTypeIcon from '../NoteShareType/ShareTypeIcon'; | ||
|
||
import './NoteShareType.scss'; | ||
|
||
const propTypes = { | ||
onClose: PropTypes.func, | ||
onSelect: PropTypes.func, | ||
positionStyle: PropTypes.object, | ||
selectedShareType: PropTypes.string, | ||
}; | ||
|
||
const NoteShareTypeDialog = forwardRef(({ onClose, onSelect, positionStyle, selectedShareType }, dialogRef) => { | ||
const [t] = useTranslation(); | ||
|
||
const preventAutoClose = (e) => e.stopPropagation(); | ||
|
||
return ( | ||
<dialog | ||
ref={dialogRef} | ||
style={positionStyle} | ||
className={classNames('note-share-type-dialog')} | ||
onKeyDown={(e) => { | ||
if (e.key === 'Escape') { | ||
onClose(); | ||
} | ||
}} | ||
> | ||
<div className="note-share-type-popup" onClick={preventAutoClose}> | ||
<DataElementWrapper | ||
tabbable | ||
dataElement="notePopupStateAssessor" | ||
type="button" | ||
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.ASSESSORS })} | ||
onClick={() => onSelect(ShareTypes.ASSESSORS)} | ||
> | ||
<ShareTypeIcon shareType={ShareTypes.ASSESSORS} /> | ||
{t('option.state.assessors')} | ||
</DataElementWrapper> | ||
|
||
<DataElementWrapper | ||
tabbable | ||
dataElement="notePopupStateParticipants" | ||
type="button" | ||
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.PARTICIPANTS })} | ||
onClick={() => onSelect(ShareTypes.PARTICIPANTS)} | ||
> | ||
<ShareTypeIcon shareType={ShareTypes.PARTICIPANTS} /> | ||
{t('option.state.participants')} | ||
</DataElementWrapper> | ||
|
||
<DataElementWrapper | ||
tabbable | ||
dataElement="notePopupStateAll" | ||
type="button" | ||
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.ALL })} | ||
onClick={() => onSelect(ShareTypes.ALL)} | ||
> | ||
<ShareTypeIcon shareType={ShareTypes.ALL} /> | ||
{t('option.state.all')} | ||
</DataElementWrapper> | ||
|
||
<DataElementWrapper | ||
tabbable | ||
dataElement="notePopupStateAssessors" | ||
type="button" | ||
className={classNames('note-sharetype-option', { selected: selectedShareType === ShareTypes.NONE })} | ||
onClick={() => onSelect(ShareTypes.NONE)} | ||
> | ||
<ShareTypeIcon shareType={ShareTypes.NONE} /> | ||
{t('option.state.none')} | ||
</DataElementWrapper> | ||
</div> | ||
</dialog> | ||
); | ||
}); | ||
|
||
NoteShareTypeDialog.displayName = 'NoteShareTypeDialog'; | ||
NoteShareTypeDialog.propTypes = propTypes; | ||
|
||
export default NoteShareTypeDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import classNames from 'classnames'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import useOverflowContainer from 'hooks/useOverflowContainer'; | ||
import useOnClickOutside from 'hooks/useOnClickOutside'; | ||
|
||
import DataElements from 'constants/dataElement'; | ||
import NoteShareTypeDialog from './NoteShareTypeDialog'; | ||
import ShareTypeIcon from '../NoteShareType/ShareTypeIcon'; | ||
|
||
import { getAnnotationShareType, setAnnotationShareType } from 'src/helpers/annotationShareType'; | ||
import getAnnotationManager from 'src/core/getAnnotationManager'; | ||
|
||
import './NoteShareType.scss'; | ||
|
||
/** | ||
* Multi control button and popup menu | ||
* @param {{ | ||
* multiSelectedAnnotations: Array<Annotation>, | ||
* }} props | ||
*/ | ||
const NoteShareTypeMultiControl = ({ multiSelectedAnnotations }) => { | ||
const [t] = useTranslation(); | ||
const [dialogIsOpen, setDialogIsOpen] = useState(false); | ||
const { popupMenuRef: dialogRef, style } = useOverflowContainer(dialogIsOpen, { defaultLocation: 'top' }); | ||
const [collectiveShareType, setCollectiveShareType] = useState(); | ||
|
||
useEffect(() => { | ||
const shareTypes = new Set(multiSelectedAnnotations.map((annotation) => getAnnotationShareType(annotation))); | ||
if (shareTypes.size === 1) { | ||
setCollectiveShareType(shareTypes.values().next().value); | ||
} else { | ||
setCollectiveShareType(undefined); | ||
} | ||
}, [multiSelectedAnnotations]); | ||
|
||
const onClose = () => { | ||
dialogRef.current?.close(); | ||
setDialogIsOpen(false); | ||
}; | ||
|
||
const onOpen = () => { | ||
dialogRef.current?.show(); | ||
setDialogIsOpen(true); | ||
}; | ||
|
||
const togglePopup = (e) => { | ||
e.stopPropagation(); | ||
if (dialogIsOpen) { | ||
onClose(); | ||
} else { | ||
onOpen(); | ||
} | ||
}; | ||
|
||
useOnClickOutside(dialogRef, () => { | ||
onClose(); | ||
}); | ||
|
||
const handleSelect = (shareType) => { | ||
|
||
multiSelectedAnnotations.forEach((annotation) => { | ||
setAnnotationShareType(annotation, shareType); | ||
}); | ||
|
||
getAnnotationManager().trigger('annotationChanged', [multiSelectedAnnotations, 'modify', {}]); | ||
setCollectiveShareType(shareType); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<div style={{ position: 'relative', display: 'flex' }}> | ||
<button | ||
style={{ padding: '0 3px' }} | ||
dataElement={DataElements.NOTE_MULTI_SHARE_TYPE_BUTTON} | ||
onClick={togglePopup} | ||
className={classNames('share-type-icon-button', { | ||
active: dialogIsOpen, | ||
})} | ||
disabled={!multiSelectedAnnotations.length} | ||
> | ||
<ShareTypeIcon shareType={collectiveShareType} label={t('action.shareType')} /> | ||
</button> | ||
|
||
<NoteShareTypeDialog onClose={onClose} selectedShareType={collectiveShareType} ref={dialogRef} positionStyle={style} onSelect={handleSelect} /> | ||
</div > | ||
); | ||
}; | ||
|
||
export default NoteShareTypeMultiControl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters