From e28ad6c6ec45eb88ed862993b89edb6d59c9c637 Mon Sep 17 00:00:00 2001 From: Pablo Varela Date: Tue, 22 May 2018 10:18:57 +0200 Subject: [PATCH] [SDFID-388] Retrieve annotation type name for qcode (#2310) * [SDFID-388] Retrieve annotation type name for qcode * [SDFID-388] Store annotation types in redux * [SDFID-388] Add metadata service to tests --- .../components/annotations/AnnotationPopup.jsx | 12 +++++++++--- scripts/core/editor3/store/index.js | 2 ++ scripts/core/editor3/store/tests/store.spec.jsx | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/core/editor3/components/annotations/AnnotationPopup.jsx b/scripts/core/editor3/components/annotations/AnnotationPopup.jsx index ff39ec674c..0310d66610 100644 --- a/scripts/core/editor3/components/annotations/AnnotationPopup.jsx +++ b/scripts/core/editor3/components/annotations/AnnotationPopup.jsx @@ -9,8 +9,9 @@ import ng from 'core/services/ng'; import {HighlightsPopupPresentation} from '../HighlightsPopupPresentation'; import {UserAvatar} from 'apps/users/components/UserAvatar'; -const Annotation = ({annotation, editorNode, showPopup, highlightId, highlightsManager}) => { - const {author, avatar, date, msg, annotationType: type} = annotation.data; +const Annotation = ({annotation, editorNode, showPopup, highlightId, highlightsManager, annotationTypes}) => { + const {author, avatar, 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 logger = ng.get('logger'); @@ -72,8 +73,13 @@ Annotation.propTypes = { highlightsManager: PropTypes.object.isRequired, highlightId: PropTypes.string, editorNode: PropTypes.object, + annotationTypes: PropTypes.array, }; -export const AnnotationPopup = connect(null, { +const mapStateToProps = (state) => ({ + annotationTypes: state.annotationTypes, +}); + +export const AnnotationPopup = connect(mapStateToProps, { showPopup, })(Annotation); diff --git a/scripts/core/editor3/store/index.js b/scripts/core/editor3/store/index.js index ee3f2c82b6..4f1620e57f 100644 --- a/scripts/core/editor3/store/index.js +++ b/scripts/core/editor3/store/index.js @@ -33,6 +33,7 @@ export default function createEditorStore(props, isReact = false) { const decorators = Editor3.getDecorator(props.disableSpellchecker || !spellcheck.isAutoSpellchecker); const showToolbar = !props.singleLine && (props.editorFormat || []).length > 0; const onChangeValue = isReact ? props.onChange : _.debounce(onChange.bind(props), props.debounce); + const annotationTypes = ng.get('metadata').values.annotation_types || []; const store = createStore(reducers, { editorState: EditorState.createWithContent(content, decorators), @@ -52,6 +53,7 @@ export default function createEditorStore(props, isReact = false) { suggestingMode: false, invisibles: false, svc: props.svc, + annotationTypes: annotationTypes, }, applyMiddleware(thunk)); diff --git a/scripts/core/editor3/store/tests/store.spec.jsx b/scripts/core/editor3/store/tests/store.spec.jsx index a14d106732..3732cdaeea 100644 --- a/scripts/core/editor3/store/tests/store.spec.jsx +++ b/scripts/core/editor3/store/tests/store.spec.jsx @@ -7,6 +7,11 @@ describe('editor3.store', () => { getDict: jasmine.createSpy().and.returnValue($q.when(null)), isCorrectWord: jasmine.createSpy(), })); + $provide.service('metadata', ($q) => ({ + values: { + annotation_types: [], + }, + })); })); it('should initialize with correct values', inject((spellcheck) => {