import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import {connect} from 'react-redux'; import {showPopup, PopupTypes} from '../../actions'; import {convertFromRaw} from 'draft-js'; import ng from 'core/services/ng'; import {HighlightsPopupPositioner} from '../HighlightsPopupPositioner'; import {UserAvatarFromUserId} from 'apps/users/components/UserAvatarFromUserId'; import {connectPromiseResults} from 'core/helpers/ReactRenderAsync'; import {EditorHighlightsHeader} from '../../editorPopup/EditorHighlightsHeader'; import {FluidRows} from '../../fluid-flex-rows/fluid-rows'; import {FluidRow} from '../../fluid-flex-rows/fluid-row'; import {gettext} from 'core/utils'; import {editor3StateToHtml} from 'core/editor3/html/to-html/editor3StateToHtml'; class Annotation extends React.Component { static propTypes: any; static defaultProps: any; render() { const {annotation, editorNode, highlightId, highlightsManager, annotationTypes, close} = this.props; const _showPopup = this.props.showPopup; const {author, authorId, date, msg, annotationType} = annotation.data; const {name: type} = annotationTypes.find((t) => t.qcode === annotationType); const relativeDateString = moment(date).calendar(); const absoluteDateString = moment(date).format('MMMM Do YYYY, h:mm:ss a'); const html = editor3StateToHtml(convertFromRaw(JSON.parse(msg))); const modal = ng.get('modal'); const onEdit = () => { _showPopup(PopupTypes.Annotation, {annotation, highlightId}); close(); }; const onDelete = () => modal .confirm(gettext('The annotation will be deleted. Are you sure?')) .then(() => { highlightsManager.removeHighlight(highlightId); }); const availableActions = [ { text: gettext('Edit'), icon: 'icon-pencil', onClick: onEdit, }, { text: gettext('Delete'), icon: 'icon-trash', onClick: onDelete, }, ]; return (

{author}

{gettext('Annotation')}
{gettext('Annotation type')}: {type}
); } } Annotation.propTypes = { showPopup: PropTypes.func, annotation: PropTypes.object, highlightsManager: PropTypes.object.isRequired, highlightId: PropTypes.string, editorNode: PropTypes.object, annotationTypes: PropTypes.array.isRequired, }; const AnnotationWithDependenciesLoaded = connectPromiseResults(() => ({ annotationTypes: ng.get('metadata').initialize() .then(() => ng.get('metadata').values.annotation_types), }))(Annotation); export const AnnotationPopup: any = connect( () => ({}), {showPopup}, )(AnnotationWithDependenciesLoaded);