Skip to content

Commit

Permalink
[SDFID-388] Retrieve annotation type name for qcode (#2310)
Browse files Browse the repository at this point in the history
* [SDFID-388] Retrieve annotation type name for qcode

* [SDFID-388] Store annotation types in redux

* [SDFID-388] Add metadata service to tests
  • Loading branch information
pablopunk authored and petrjasek committed May 22, 2018
1 parent 5189cb7 commit e28ad6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions scripts/core/editor3/components/annotations/AnnotationPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
2 changes: 2 additions & 0 deletions scripts/core/editor3/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -52,6 +53,7 @@ export default function createEditorStore(props, isReact = false) {
suggestingMode: false,
invisibles: false,
svc: props.svc,
annotationTypes: annotationTypes,
}, applyMiddleware(thunk));


Expand Down
5 changes: 5 additions & 0 deletions scripts/core/editor3/store/tests/store.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit e28ad6c

Please sign in to comment.